qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
114,306
<p>It's very painful to add multiple tickets to Trac or to have it as your own todo list. That causes people to use their own task management tools so tasks are then spread all around.</p> <p>Is there any plugin or macro that would quicken the process of adding a ticket?</p>
[ { "answer_id": 1344978, "author": "johntellsall", "author_id": 143880, "author_profile": "https://Stackoverflow.com/users/143880", "pm_score": 3, "selected": false, "text": "#!/usr/bin/env python\n\n'''\ntrac-bug: add bug/feature to current Trac project, from the command line.\nSpecify Trac project directory in TRAC_ENV environment variable.\n'''\n\n\nimport os, sys\n\nTRAC_ENV = os.environ.get('TRAC_ENV') or os.path.expanduser('~/trac/projectenv')\nif not os.path.isdir(TRAC_ENV):\n print >>sys.stderr, \"Set TRAC_ENV to the Trac project directory.\"\n sys.exit(2)\n\nfrom trac.env import open_environment\nfrom trac.ticket import Ticket\nt = Ticket(open_environment(TRAC_ENV))\n\ndesc = ' '.join(sys.argv[1:])\ninfo = dict(\n status='open', \n owner=os.environ['USER'], reporter=os.environ['USER'],\n description = desc, summary=desc\n)\n\nt.populate(info)\nnum = t.insert()\nif not num:\n print >>sys.stderr, \"Ticket not created\"\n print >>sys.stder, vals\n sys.exit(1)\n\nprint \"Ticket #%d: %s\" % (num,desc)\nsys.exit(0) # all is well\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/189/" ]
114,332
<p>I've had a <em>serious</em> issue with my Visual Studio 2008 setup. I receive the ever-so-useful error 'A problem has been encountered while loading the setup components. Canceling setup.' whenever I try to uninstall, reinstall or repair Visual Studio 2008 (team system version). If I can't resolve this issue I have no choice but to completely wipe my computer and start again which will take all day long! I've recently received very strange errors when trying to build projects regarding components running out of memory (despite having ~2gb physical memory free at the time) which has rendered my current VS install useless.</p> <p>Note I installed VS2005 shell version using the vs_setup.msi file in the SQL Server folder <em>after</em> I had installed VS2008, in order to gain access to the SQL Server 2005 Reporting Services designer in Business Intelligence Development Studio (this is inexplicably unavailable in VS2008).</p> <p>Does anyone have any solutions to this problem?</p> <p><strong>P.S.</strong>: I know this isn't directly related to programming, however I feel this <em>is</em> appropriate to SO as it is directly related to my <em>ability</em> to program at all!</p> <p><strong>Note</strong>: A colleague found a solution to this problem, hopefully this should help others with this problem.</p>
[ { "answer_id": 1827236, "author": "Andrew", "author_id": 5662, "author_profile": "https://Stackoverflow.com/users/5662", "pm_score": 3, "selected": false, "text": "KB972221 KB973674 KB971091 KB952241" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3394/" ]
114,339
<p>If I want to manipulate an HTML tag's properties on the server within an aspx page based on a master page i.e. </p> <pre><code>&lt;a href="#" runat="server" ID="myLink"&gt;My Link&lt;/a&gt; </code></pre> <p>For example to give the link a different class depending on the current page i.e.</p> <pre><code>if (Path.GetFileName(Request.PhysicalPath) == "MyPage") { myLink.Attributes.Add("class","active"); } </code></pre> <p>.NET changes the ID property of the link to something like</p> <pre><code>&lt;a href="#" ID="ct100-foo-myLink"&gt;My Link&lt;/a&gt; </code></pre> <p>Is there any way of stopping this from happening and keeping the original ID?</p> <p>Thanks in advance</p>
[ { "answer_id": 114357, "author": "Giovanni Galbo", "author_id": 4050, "author_profile": "https://Stackoverflow.com/users/4050", "pm_score": 0, "selected": false, "text": "public abstract string SetControlID(string name, System.Web.UI.Control control);\n" }, { "answer_id": 114363, "author": "Rahul", "author_id": 16308, "author_profile": "https://Stackoverflow.com/users/16308", "pm_score": 0, "selected": false, "text": "<asp:Literal ID=\"myLink\" />\n WebControl a = new WebControl(HtmlTextWriterTag.A);\na.CssClass = \"active\";\na.Attributes[\"href\"] = \"#\";\nLiteral text = new Literal();\ntext.Text = \"click here\";\na.Controls.Add(text);\nmyLink.Controls.Add(a);\n <a href=\"#\" class=\"active\">click here</a>\n" }, { "answer_id": 114375, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 0, "selected": false, "text": ".getElementById" }, { "answer_id": 114381, "author": "rslite", "author_id": 15682, "author_profile": "https://Stackoverflow.com/users/15682", "pm_score": 2, "selected": false, "text": "<a ID=\"myLink\" runat=\"server\">....\n\n\nvar ctrl = document.getElementById('<%# myLink.ClientID %>');\n" }, { "answer_id": 219730, "author": "CMPalmer", "author_id": 14894, "author_profile": "https://Stackoverflow.com/users/14894", "pm_score": 1, "selected": false, "text": "var mangled_name = $(\"[id$=original_name]\").attr(\"id\");\n <asp:TextBox ID=\"txtStartDate\" runat=\"server\" />\n var start_date_id = $(\"[id$=txtStartDate]\").attr(\"id\");\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12918/" ]
114,398
<p>After rebooting the Windows 2003 Server with the IIS I receive the follow error message:</p> <blockquote> <p>Cannot connect to the configuration database</p> </blockquote> <p>in the browser. The error occur on different pages and with different clients. that I think it is a server problem.</p> <p>What can I do to solve this error?</p>
[ { "answer_id": 249494, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<!-- Web.Config Configuration File -->\n<configuration>\n <system.web>\n <customErrors mode=\"RemoteOnly\"/>\n </system.web>\n</configuration>\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12631/" ]
114,419
<p>The following two C# code snippets produce different results (assuming the variable level is used both before and after the recursive call). Why?</p> <pre><code>public DoStuff(int level) { // ... DoStuff(level++); // ... } </code></pre> <p>,</p> <pre><code>public DoStuff(int level) { // ... DoStuff(level+1); // ... } </code></pre> <p>After reading some of the responses below I thought it would be worthwhile posting the stack traces for level++, ++level and level+1 to highlight how deceiving this problem is.</p> <p>I've simplified them for this post. The recursive call sequence starts with DoStuff(1). </p> <p>// level++</p> <pre><code>DoStuff(int level = 1) DoStuff(int level = 2) DoStuff(int level = 2) DoStuff(int level = 2) </code></pre> <p>// ++level</p> <pre><code>DoStuff(int level = 4) DoStuff(int level = 4) DoStuff(int level = 3) DoStuff(int level = 2) </code></pre> <p>// level+1</p> <pre><code>DoStuff(int level = 4) DoStuff(int level = 3) DoStuff(int level = 2) DoStuff(int level = 1) </code></pre>
[ { "answer_id": 114441, "author": "Markus Schnell", "author_id": 20668, "author_profile": "https://Stackoverflow.com/users/20668", "pm_score": 1, "selected": false, "text": "level++ level level level+1 level DoStuff (level + 1)" }, { "answer_id": 114446, "author": "Frederik Slijkerman", "author_id": 12416, "author_profile": "https://Stackoverflow.com/users/12416", "pm_score": 5, "selected": false, "text": "public DoStuff(int level)\n{ \n // ...\n int temp = level;\n level = level + 1;\n DoStuff(temp);\n // ...\n}\n public DoStuff(int level)\n{ \n // ...\n level = level + 1;\n DoStuff(level);\n // ...\n}\n" }, { "answer_id": 114468, "author": "Orion Adrian", "author_id": 7756, "author_profile": "https://Stackoverflow.com/users/7756", "pm_score": 4, "selected": false, "text": "level++ level therefore level DoStuff DoStuff ++level level + 1 level + 1 level + 1 DoStuff level int post_increment(ref int value)\n{\n int temp = value;\n value = value + 1\n return temp;\n}\n int pre_increment(ref int value)\n{\n value = value + 1;\n return value;\n}\n DoStuff(a + 1)\n\nint temp = a + 1;\nDoStuff(temp);\n DoStuff(++a)\n\na = a + 1;\nDoStuff(a);\n DoStuff(a++);\n\nint temp = a;\na = a + 1;\nDoStuff(temp);\n DoStuff(a);\na = a + 1;\n i + 1 DoStuff(i + 1) DoStuff(++i)" }, { "answer_id": 114471, "author": "Matt", "author_id": 17759, "author_profile": "https://Stackoverflow.com/users/17759", "pm_score": 5, "selected": false, "text": "DoStuff(a++);\n DoStuff(a);\na = a + 1;\n DoStuff(++a);\n a = a + 1;\nDoStuff(a);\n DoStuff(a + 1);\n b = a + 1;\nDoStuff(b);\n" }, { "answer_id": 114482, "author": "Wes P", "author_id": 13611, "author_profile": "https://Stackoverflow.com/users/13611", "pm_score": 1, "selected": false, "text": "public DoStuff(int level)\n{\n\n // DoStuff(level);\n DoStuff(level++);\n // level = level + 1;\n // here, level's value is 1 greater than when it came in\n}\n public DoStuff(int level)\n{\n // int iTmp = level + 1;\n // DoStuff(iTmp);\n DoStuff(level+1);\n // here, level's value hasn't changed\n}\n" }, { "answer_id": 114487, "author": "Chris Ballard", "author_id": 18782, "author_profile": "https://Stackoverflow.com/users/18782", "pm_score": 0, "selected": false, "text": "DoStuff(++level);\n level++;\nDoStuff(level);\n" }, { "answer_id": 12432401, "author": "MarioDS", "author_id": 1313143, "author_profile": "https://Stackoverflow.com/users/1313143", "pm_score": 0, "selected": false, "text": "++var var++ var+1 var 1" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1199234/" ]
114,431
<p>I am trying to display a live word count in the vim statusline. I do this by setting my status line in my .vimrc and inserting a function into it. The idea of this function is to return the number of words in the current buffer. This number is then displayed on the status line. This should work nicely as the statusline is updated at just about every possible opportunity so the count will always remain 'live'. </p> <p>The problem is that the function I have currently defined is slow and so vim is obviously sluggish when it is used for all but the smallest files; due to this function being executed so frequently.</p> <p>In summary, does anyone have a clever trick for producing a function that is blazingly fast at calculating the number of words in the current buffer and returning the result?</p>
[ { "answer_id": 116454, "author": "Mikael Jansson", "author_id": 18753, "author_profile": "https://Stackoverflow.com/users/18753", "pm_score": 2, "selected": false, "text": "updatetime let g:word_count=\"<unknown>\"\nfun! WordCount()\n return g:word_count\nendfun\nfun! UpdateWordCount()\n let s = system(\"wc -w \".expand(\"%p\"))\n let parts = split(s, ' ')\n if len(parts) > 1\n let g:word_count = parts[0]\n endif\nendfun\n\naugroup WordCounter\n au! CursorHold * call UpdateWordCount()\n au! CursorHoldI * call UpdateWordCount()\naugroup END\n\n\" how eager are you? (default is 4000 ms)\nset updatetime=500\n\n\" modify as you please...\nset statusline=%{WordCount()}\\ words\n" }, { "answer_id": 120386, "author": "Greg Sexton", "author_id": 20388, "author_profile": "https://Stackoverflow.com/users/20388", "pm_score": 0, "selected": false, "text": "\"returns the count of how many words are in the entire file excluding the current line \n\"updates the buffer variable Global_Word_Count to reflect this\nfu! OtherLineWordCount() \n let data = []\n \"get lines above and below current line unless current line is first or last\n if line(\".\") > 1\n let data = getline(1, line(\".\")-1)\n endif \n if line(\".\") < line(\"$\")\n let data = data + getline(line(\".\")+1, \"$\") \n endif \n let count_words = 0\n let pattern = \"\\\\<\\\\(\\\\w\\\\|-\\\\|'\\\\)\\\\+\\\\>\"\n for str in data\n let count_words = count_words + NumPatternsInString(str, pattern)\n endfor \n let b:Global_Word_Count = count_words\n return count_words\nendf \n\n\"returns the word count for the current line\n\"updates the buffer variable Current_Line_Number \n\"updates the buffer variable Current_Line_Word_Count \nfu! CurrentLineWordCount()\n if b:Current_Line_Number != line(\".\") \"if the line number has changed then add old count\n let b:Global_Word_Count = b:Global_Word_Count + b:Current_Line_Word_Count\n endif \n \"calculate number of words on current line\n let line = getline(\".\")\n let pattern = \"\\\\<\\\\(\\\\w\\\\|-\\\\|'\\\\)\\\\+\\\\>\"\n let count_words = NumPatternsInString(line, pattern)\n let b:Current_Line_Word_Count = count_words \"update buffer variable with current line count\n if b:Current_Line_Number != line(\".\") \"if the line number has changed then subtract current line count\n let b:Global_Word_Count = b:Global_Word_Count - b:Current_Line_Word_Count\n endif \n let b:Current_Line_Number = line(\".\") \"update buffer variable with current line number\n return count_words\nendf \n\n\"returns the word count for the entire file using variables defined in other procedures\n\"this is the function that is called repeatedly and controls the other word\n\"count functions.\nfu! WordCount()\n if exists(\"b:Global_Word_Count\") == 0 \n let b:Global_Word_Count = 0\n let b:Current_Line_Word_Count = 0\n let b:Current_Line_Number = line(\".\")\n call OtherLineWordCount()\n endif \n call CurrentLineWordCount()\n return b:Global_Word_Count + b:Current_Line_Word_Count\nendf\n\n\"returns the number of patterns found in a string \nfu! NumPatternsInString(str, pat)\n let i = 0\n let num = -1\n while i != -1\n let num = num + 1\n let i = matchend(a:str, a:pat, i)\n endwhile\n return num\nendf\n :set statusline=wc:%{WordCount()}\n" }, { "answer_id": 553257, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": true, "text": "function WordCount()\n let s:old_status = v:statusmsg\n exe \"silent normal g\\<c-g>\"\n let s:word_count = str2nr(split(v:statusmsg)[11])\n let v:statusmsg = s:old_status\n return s:word_count\nendfunction\n :set statusline=wc:%{WordCount()}\n" }, { "answer_id": 2796006, "author": "dahu", "author_id": 336429, "author_profile": "https://Stackoverflow.com/users/336429", "pm_score": 1, "selected": false, "text": "function! WordCount()\n let lnum = 1\n let n = 0\n while lnum <= line('$')\n let n = n + len(split(getline(lnum)))\n let lnum = lnum + 1\n endwhile\n return n\nendfunction\n :set statusline=wc:%{WordCount()}\n wc UpdateWordCount UpdateWordCount" }, { "answer_id": 2808113, "author": "godlygeek", "author_id": 337899, "author_profile": "https://Stackoverflow.com/users/337899", "pm_score": 1, "selected": false, "text": "function! UpdateWordCount()\n let b:word_count = eval(join(map(getline(\"1\", \"$\"), \"len(split(v:val, '\\\\s\\\\+'))\"), \"+\"))\nendfunction\n\naugroup UpdateWordCount\n au!\n autocmd BufRead,BufNewFile,BufEnter,CursorHold,CursorHoldI,InsertEnter,InsertLeave * call UpdateWordCount()\naugroup END\n\nlet &statusline='wc:%{get(b:, \"word_count\", 0)}'\n" }, { "answer_id": 4588161, "author": "Abslom Daak", "author_id": 561702, "author_profile": "https://Stackoverflow.com/users/561702", "pm_score": 5, "selected": false, "text": "function! WordCount()\n let s:old_status = v:statusmsg\n let position = getpos(\".\")\n exe \":silent normal g\\<c-g>\"\n let stat = v:statusmsg\n let s:word_count = 0\n if stat != '--No lines in buffer--'\n let s:word_count = str2nr(split(v:statusmsg)[11])\n let v:statusmsg = s:old_status\n end\n call setpos('.', position)\n return s:word_count \nendfunction\n :set statusline=wc:%{WordCount()}" }, { "answer_id": 8773451, "author": "nth", "author_id": 1136450, "author_profile": "https://Stackoverflow.com/users/1136450", "pm_score": 1, "selected": false, "text": "function WordCount()\n redir => l:status\n exe \"silent normal g\\<c-g>\"\n redir END\n return str2nr(split(l:status)[11])\nendfunction\n" }, { "answer_id": 11993678, "author": "Felipe Morales", "author_id": 1604120, "author_profile": "https://Stackoverflow.com/users/1604120", "pm_score": 1, "selected": false, "text": "function! WC()\n if &modified || !exists(\"b:wordcount\") \n let l:old_status = v:statusmsg \n execute \"silent normal g\\<c-g>\"\n let b:wordcount = str2nr(split(v:statusmsg)[11])\n let v:statusmsg = l:old_status \n return b:wordcount\n else\n return b:wordcount\n endif\nendfunction \n" }, { "answer_id": 13539953, "author": "Leo", "author_id": 926705, "author_profile": "https://Stackoverflow.com/users/926705", "pm_score": 2, "selected": false, "text": ":au CursorHold * exe \"normal g\\<c-g>\"\n:au CursorHoldI * exe \"normal g\\<c-g>\"\n updatetime set updatetime=300\n CursorHold CursorHoldI updatetime" }, { "answer_id": 18895724, "author": "Guy Gur-Ari", "author_id": 563237, "author_profile": "https://Stackoverflow.com/users/563237", "pm_score": 2, "selected": false, "text": "function! WordCount()\n let s:old_status = v:statusmsg\n let position = getpos(\".\")\n exe \":silent normal g\\<c-g>\"\n let stat = v:statusmsg\n let s:word_count = 0\n if stat != '--No lines in buffer--'\n if stat =~ \"^Selected\"\n let s:word_count = str2nr(split(v:statusmsg)[5])\n else\n let s:word_count = str2nr(split(v:statusmsg)[11])\n end\n let v:statusmsg = s:old_status\n end\n call setpos('.', position)\n return s:word_count \nendfunction\n set statusline=%=%{WordCount()}\\ words\\ " }, { "answer_id": 24560728, "author": "Dan Sheffler", "author_id": 3769180, "author_profile": "https://Stackoverflow.com/users/3769180", "pm_score": 0, "selected": false, "text": "~/.vim/bundle/vim-airline/autoload/airline/extensions/pandoc.vim call airline#extensions#pandoc#init(s:ext) extensions.vim let s:spc = g:airline_symbols.space\n\nfunction! airline#extensions#pandoc#word_count()\nif mode() == \"s\"\n return 0\nelse\n let s:old_status = v:statusmsg\n let position = getpos(\".\")\n let s:word_count = 0\n exe \":silent normal g\\<c-g>\"\n let stat = v:statusmsg\n let s:word_count = 0\n if stat != '--No lines in buffer--'\n let s:word_count = str2nr(split(v:statusmsg)[11])\n let v:statusmsg = s:old_status\n end\n call setpos('.', position)\n return s:word_count \nend\nendfunction\n\nfunction! airline#extensions#pandoc#apply(...)\nif &ft == \"pandoc\"\n let w:airline_section_x = \"%{airline#extensions#pandoc#word_count()} Words\"\nendif\nendfunction\n\nfunction! airline#extensions#pandoc#init(ext)\ncall a:ext.add_statusline_func('airline#extensions#pandoc#apply')\nendfunction\n" }, { "answer_id": 56586860, "author": "Enno", "author_id": 3528522, "author_profile": "https://Stackoverflow.com/users/3528522", "pm_score": 0, "selected": false, "text": "function! StatuslineWordCount()\n if !&l:spell\n return ''\n endif\n\n if empty(getline(line('$')))\n return ''\n endif\n let mode = mode()\n if !(mode ==# 'v' || mode ==# 'V' || mode ==# \"\\<c-v>\" || mode =~# '[ni]')\n return ''\n endif\n\n let s:old_status = v:statusmsg\n let position = getpos('.')\n let stat = v:statusmsg\n let s:word_count = 0\n exe \":silent normal g\\<c-g>\"\n try\n if mode ==# 'v' || mode ==# 'V'\n let s:word_count = split(split(v:statusmsg, ';')[1])[0]\n elseif mode ==# \"\\<c-v>\"\n let s:word_count = split(split(v:statusmsg, ';')[2])[0]\n elseif mode =~# '[ni]'\n let s:word_count = split(split(v:statusmsg, ';')[2])[3]\n end\n \" index out of range\n catch /^Vim\\%((\\a\\+)\\)\\=:E\\%(684\\|116\\)/\n return ''\n endtry\n let v:statusmsg = s:old_status\n call setpos('.', position)\n\n return \"\\ \\|\\ \" . s:word_count . 'w'\nendfunction\n set statusline+=%.10{StatuslineWordCount()} \" wordcount\n" }, { "answer_id": 60310471, "author": "Serge Stroobandt", "author_id": 2192488, "author_profile": "https://Stackoverflow.com/users/2192488", "pm_score": 2, "selected": false, "text": "vim vim statusline set statusline+=%{wordcount().words}\\ words\nset laststatus=2 \" enables the statusline.\n vim-airline vim-airline asciidoc, help, mail, markdown, org, rst, tex ,text vim-airline markdown.pandoc vim-airline .vimrc let g:airline#extensions#wordcount#filetypes = '\\vasciidoc|help|mail|markdown|markdown.pandoc|org|rst|tex|text'\nset laststatus=2 \" enables vim-airline.\n \\v g:airline#extensions#wordcount#filetypes vim-airline &filetype :echo &filetype\n" }, { "answer_id": 60326395, "author": "D. Ben Knoble", "author_id": 4400820, "author_profile": "https://Stackoverflow.com/users/4400820", "pm_score": 1, "selected": false, "text": ":echo wordcount().words\n" }, { "answer_id": 67723154, "author": "Iuri Gavronski", "author_id": 11001018, "author_profile": "https://Stackoverflow.com/users/11001018", "pm_score": 0, "selected": false, "text": "\"new in vim 7.4.1042\nlet g:word_count=wordcount().words\nfunction WordCount()\n if has_key(wordcount(),'visual_words')\n let g:word_count=wordcount().visual_words.\"/\".wordcount().words\n else\n let g:word_count=wordcount().cursor_words.\"/\".wordcount().words\n endif\n return g:word_count\nendfunction\n set statusline+=\\ w:%{WordCount()},\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20388/" ]
114,457
<p>What are the consequences of running a Java class file compiled in JDK 1.4.2 on JRE 1.6 or 1.5?</p>
[ { "answer_id": 114557, "author": "Heath Borders", "author_id": 9636, "author_profile": "https://Stackoverflow.com/users/9636", "pm_score": 1, "selected": false, "text": "String s = \"string1\" + \"string2\";\n String s = new StringBuilder(\"string1\").append(\"string2\").toString();\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15177/" ]
114,493
<p>I know the range name of the start of a list - <code>1</code> column wide and <code>x</code> rows deep.</p> <p>How do I calculate <code>x</code>?</p> <p>There is more data in the column than just this list. However, this list is contiguous - there is nothing in any of the cells above or below or either side beside it.</p>
[ { "answer_id": 114513, "author": "GSerg", "author_id": 11683, "author_profile": "https://Stackoverflow.com/users/11683", "pm_score": 5, "selected": true, "text": "Function ListRowCount(ByVal FirstCellName as String) as Long\n With thisworkbook.Names(FirstCellName).RefersToRange\n If isempty(.Offset(1,0).value) Then \n ListRowCount = 1\n Else\n ListRowCount = .End(xlDown).row - .row + 1\n End If\n End With\nEnd Function\n thisworkbook.Names(FirstCellName).RefersToRange.CurrentRegion.rows.count" }, { "answer_id": 114598, "author": "wcm", "author_id": 2173, "author_profile": "https://Stackoverflow.com/users/2173", "pm_score": 2, "selected": false, "text": "rows Data =ROWS(Data)" }, { "answer_id": 114615, "author": "SpyJournal", "author_id": 10326, "author_profile": "https://Stackoverflow.com/users/10326", "pm_score": 1, "selected": false, "text": "strArea = Sheets(\"Oper St Report CC\").Range(\"cc_rev\").CurrentRegion.Address\ncc_rev_rows = \"=ROWS(\" & strArea & \")\"\nRange(\"cc_rev_count\").Formula = cc_rev_rows\n" }, { "answer_id": 115091, "author": "Jon Fournier", "author_id": 5106, "author_profile": "https://Stackoverflow.com/users/5106", "pm_score": 3, "selected": false, "text": "Range( RangeName ).end(xlDown).row\n" }, { "answer_id": 1233664, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 6, "selected": false, "text": "Sheet1.Range(\"myrange\").Rows.Count\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10326/" ]
114,501
<p>I want to set a background image for a div, in a way that it is in the upper <strong>RIGHT</strong> of the div, but with a fixed <code>10px</code> distance from top and right.</p> <p>Here is how I would do that if wanted it in the upper <strong>LEFT</strong> of the div:</p> <pre>background: url(images/img06.gif) no-repeat 10px 10px;</pre> <p>Is there anyway to achieve the same result, but showing the background on the upper <strong>RIGHT</strong>?</p>
[ { "answer_id": 114517, "author": "mathieu", "author_id": 971, "author_profile": "https://Stackoverflow.com/users/971", "pm_score": 3, "selected": false, "text": "background: url(images/img06.gif) no-repeat top right;\n" }, { "answer_id": 114522, "author": "Justin Poliey", "author_id": 6967, "author_profile": "https://Stackoverflow.com/users/6967", "pm_score": 3, "selected": false, "text": "top right" }, { "answer_id": 114523, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 0, "selected": false, "text": "div" }, { "answer_id": 114653, "author": "roryf", "author_id": 270, "author_profile": "https://Stackoverflow.com/users/270", "pm_score": 5, "selected": true, "text": "background: url(images/img06.gif) no-repeat top right;\nmargin-top: 10px;\nmargin-right: 10px;\n" }, { "answer_id": 114661, "author": "Rahul", "author_id": 16308, "author_profile": "https://Stackoverflow.com/users/16308", "pm_score": 1, "selected": false, "text": "background: url(...) top 98% no-repeat;\n" }, { "answer_id": 9133530, "author": "Teatra.co", "author_id": 1188186, "author_profile": "https://Stackoverflow.com/users/1188186", "pm_score": -1, "selected": false, "text": "background: url(YourUrl) 0px -50px no-repeat;\n 0px -50px background-position" }, { "answer_id": 9943032, "author": "Boldewyn", "author_id": 113195, "author_profile": "https://Stackoverflow.com/users/113195", "pm_score": 5, "selected": false, "text": "background-position: right 10px top 10px;\n" }, { "answer_id": 32929143, "author": "Hichem ben chaabene", "author_id": 2079148, "author_profile": "https://Stackoverflow.com/users/2079148", "pm_score": 0, "selected": false, "text": " background-image: url(../images/calender.svg) center right\n border-right: 5px white solid\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114501", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6476/" ]
114,504
<p>Eg. can I write something like this code:</p> <pre><code>public void InactiveCustomers(IEnumerable&lt;Guid&gt; customerIDs) { //... myAdoCommand.CommandText = "UPDATE Customer SET Active = 0 WHERE CustomerID in (@CustomerIDs)"; myAdoCommand.Parameters["@CustomerIDs"].Value = customerIDs; //... } </code></pre> <p>The only way I know is to Join my IEnumerable and then use string concatenation to build my SQL string.</p>
[ { "answer_id": 114562, "author": "hollystyles", "author_id": 2083160, "author_profile": "https://Stackoverflow.com/users/2083160", "pm_score": -1, "selected": false, "text": " Create procedure usp_DeactivateCustomers \n @inactive varchar(50) /*or whatever values are required to identify inactive customers*/\n AS \n UPDATE Customer SET c.Active = 0 \n FROM Customer c JOIN tableB b ON c.CustomerID = b.CustomerID \n WHERE b.someField = @inactive\n public void InactiveCustomers(string inactive)\n{\n //...\n myAdoCommand.CommandText =\n \"usp_DeactivateCustomers\";\n myAdoCommand.Parameters[\"@inactive\"].Value = inactive;\n //...\n}\n" }, { "answer_id": 114724, "author": "Aleris", "author_id": 20417, "author_profile": "https://Stackoverflow.com/users/20417", "pm_score": 1, "selected": false, "text": "CREATE PROCEDURE SelectByIdList(@productIds xml) AS\n\nDECLARE @Products TABLE (ID int) \n\nINSERT INTO @Products (ID) SELECT ParamValues.ID.value('.','VARCHAR(20)')\nFROM @productIds.nodes('/Products/id') as ParamValues(ID) \n\nSELECT * FROM \n Products\nINNER JOIN \n @Products p\nON Products.ProductID = p.ID\n" }, { "answer_id": 31110710, "author": "stakx - no longer contributing", "author_id": 240733, "author_profile": "https://Stackoverflow.com/users/240733", "pm_score": 2, "selected": false, "text": "XML" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8547/" ]
114,521
<p>I am creating a <code>gridView</code> that allows adding new rows by adding the controls necessary for the insert into the <code>FooterTemplate</code>, but when the <code>ObjectDataSource</code> has no records, I add a dummy row as the <code>FooterTemplate</code> is only displayed when there is data.</p> <p>How can I hide this dummy row? I have tried setting <code>e.row.visible = false</code> on <code>RowDataBound</code> but the row is still visible.</p>
[ { "answer_id": 114612, "author": "mattlant", "author_id": 14642, "author_profile": "https://Stackoverflow.com/users/14642", "pm_score": 0, "selected": false, "text": "e.Row.Height = Unit.Pixel(0);\n" }, { "answer_id": 114699, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 1, "selected": false, "text": "<asp:GridView ID=\"grid\" runat=\"server\" AutoGenerateColumns=\"false\" ShowFooter=\"true\" OnRowDataBound=\"OnRowDataBound\">\n <Columns>\n <asp:TemplateField HeaderText=\"headertext\">\n <ItemTemplate>\n itemtext\n </ItemTemplate>\n <FooterTemplate>\n insert controls\n </FooterTemplate>\n </asp:TemplateField>\n </Columns>\n</asp:GridView>\n protected void OnRowDataBound(object sender, GridViewRowEventArgs e)\n{\n if (e.Row.RowType == DataControlRowType.DataRow)\n {\n e.Row.Attributes[\"style\"] = \"display:none\";\n }\n}\n" }, { "answer_id": 114737, "author": "John Miller", "author_id": 17623, "author_profile": "https://Stackoverflow.com/users/17623", "pm_score": 2, "selected": false, "text": "protected void GridView1_DataBound(object sender, EventArgs e)\n {\n if (GridView1.Rows.Count == 1)\n GridView1.Rows[0].Visible = false;\n }\n" }, { "answer_id": 115097, "author": "Rob", "author_id": 12413, "author_profile": "https://Stackoverflow.com/users/12413", "pm_score": 0, "selected": false, "text": "dim row as Datarow = table.NewRow()\ntable.AddRow(row)\ngridView.DataSource = table\ngridView.Databind()\n 'this will get the footer no matter how many rows there are in the grid.\n\nDim footer as Control = gridView.Controls(0).Controls(gridView.Controls(0).Controls.Count -1)\n Dim cntl as Control = footer.FindControl(<Insert Control Name Here>)\n footer.Visible = false\n If mTable.Rows.Count = 1 AndAlso mTable.Rows(0)(<first column to check for null value>) Is DBNull.Value AndAlso mTable.Rows(0)(<second column>) Is DBNull.Value AndAlso mTable.Rows(0)(<thrid column>) Is DBNull.Value Then \nmTable.Rows.Remove(mTable.Rows(0)) \nEnd If\nmTable.Rows.Add(row)\ngridView.Datasource = mTable\ngridView.Databind()\n" }, { "answer_id": 594536, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Gridview.Rows.Item(i).Attributes.Add(\"style\", \"display:block\")\n Gridview.Rows.Item(i).Attributes.Add(\"style\", \"display:none\")\n" }, { "answer_id": 3353093, "author": "Davidson Sousa", "author_id": 296437, "author_profile": "https://Stackoverflow.com/users/296437", "pm_score": 0, "selected": false, "text": "<asp:GridView ID=\"GridView1\" runat=\"server\" DataKeyNames=\"FooID\"> GridView1.DataKeys[0].Value.ToString()" }, { "answer_id": 8025100, "author": "Harshal", "author_id": 1031824, "author_profile": "https://Stackoverflow.com/users/1031824", "pm_score": 2, "selected": false, "text": " protected void GridView1_DataBound(object sender, EventArgs e)\n {\n GridView1.Rows[0].Visible = false;\n }\n" }, { "answer_id": 9844658, "author": "Anto SJ", "author_id": 1288930, "author_profile": "https://Stackoverflow.com/users/1288930", "pm_score": -1, "selected": false, "text": "USE YourdatabaseName select * from TableName where Column_Name <> ''\n" }, { "answer_id": 32940462, "author": "user5408227", "author_id": 5408227, "author_profile": "https://Stackoverflow.com/users/5408227", "pm_score": 0, "selected": false, "text": "if (!String.IsNullOrEmpty(item.DataName))\n{\n e.Row.Visible = false;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2808/" ]
114,525
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname">JavaScript: var functionName = function() {} vs function functionName() {}</a> </p> </blockquote> <p>What's the difference between:</p> <pre><code>function sum(x, y) { return x+y; } // and var sum = function (x, y) { return x+y; } </code></pre> <p>Why is one used over the other?</p>
[ { "answer_id": 114573, "author": "Daniel James", "author_id": 2434, "author_profile": "https://Stackoverflow.com/users/2434", "pm_score": 3, "selected": false, "text": "var y = sum(1, 2);\n\nfunction sum(x, y) {\n return x + y;\n}\n // Error here because the function hasn't been assigned to sum yet.\nvar y = sum(1, 2);\n\nvar sum = function(x, y) {\n return x + y;\n}\n var sum = function sum(x, y) {\n return x + y;\n}\n" }, { "answer_id": 114579, "author": "niXar", "author_id": 19979, "author_profile": "https://Stackoverflow.com/users/19979", "pm_score": -1, "selected": false, "text": "$ js\njs> function sum(x,y) { return x+y; }\njs> sum(1,2);\n3\njs> sum=3\n3\njs> sum(1,2);\ntypein:4: TypeError: sum is not a function\njs> sum\n3\n" }, { "answer_id": 114593, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 7, "selected": true, "text": "var z = sum(2, 3);\nfunction sum(x, y) {\n return x+y;\n}\n z var z = sum(2, 3);\nvar sum = function(x, y) {\n return x+y;\n}\n" }, { "answer_id": 114596, "author": "Mike Samuel", "author_id": 20394, "author_profile": "https://Stackoverflow.com/users/20394", "pm_score": 4, "selected": false, "text": "var f = function (x) { return 4; }\n\n(f)\n f var sum = function sum(x, y) { ... };\n var sum = function mySym(x, y) { ... };\n if (0) {\n function foo() { return 1; }\n } else {\n function foo() { return 2; }\n }\n return foo();\n var foo;\n if (0) {\n foo = function () { return 1; }\n } ...\n" }, { "answer_id": 114654, "author": "user19745", "author_id": 19745, "author_profile": "https://Stackoverflow.com/users/19745", "pm_score": 1, "selected": false, "text": "var sum = function (x, y) {\n return x+y;\n}\n function sum(x, y) {\n return x+y;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3983/" ]
114,527
<p>I'm really new to .NET, and I still didn't get the hang about how configuration files work.</p> <p>Every time I search on Google about it I get results about web.config, but I'm writing a Windows Forms application.</p> <p>I figured out that I need to use the System.Configuration namespace, but the documentation isn't helping.</p> <p>How do I define that my configuration file is XYZ.xml? Or does it have a "default" name for the configuration file? I still didn't get that.</p> <p>Also, how do I define a new section? Do I really need to create a class which inherits from ConfigurationSection?</p> <p>I would like to just have a configuration file with some values like this:</p> <pre><code>&lt;MyCustomValue&gt;1&lt;/MyCustomValue&gt; &lt;MyCustomPath&gt;C:\Some\Path\Here&lt;/MyCustomPath&gt; </code></pre> <p>Is there a simple way to do it? Can you explain in a simple way how to read and write from/to a simple configuration file?</p>
[ { "answer_id": 114552, "author": "Chris James", "author_id": 3193, "author_profile": "https://Stackoverflow.com/users/3193", "pm_score": 8, "selected": true, "text": "<configuration>\n <appSettings>\n <add key=\"MyKey\" value=\"false\"/>\n System.Configuration.ConfigurationSettings.AppSettings[\"MyKey\"];\n" }, { "answer_id": 114578, "author": "configurator", "author_id": 9536, "author_profile": "https://Stackoverflow.com/users/9536", "pm_score": 2, "selected": false, "text": "app.config web.config DefaultNamespace.Properties.Settings using DefaultNamespace.Properties;\n\nnamespace DefaultNamespace {\n class Class {\n public int LoadMySettingValue() {\n return Settings.Default.MySettingValue;\n }\n public void SaveMySettingValue(int value) {\n Settings.Default.MySettingValue = value;\n }\n }\n}\n" }, { "answer_id": 114607, "author": "Nathan Koop", "author_id": 18821, "author_profile": "https://Stackoverflow.com/users/18821", "pm_score": 3, "selected": false, "text": "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<configuration>\n <appSettings>\n <add key=\"setting1\" value=\"key\"/>\n </appSettings>\n <connectionStrings>\n <add name=\"prod\" connectionString=\"YourConnectionString\"/>\n </connectionStrings>\n</configuration>\n private void Form1_Load(object sender, EventArgs e)\n {\n string setting = ConfigurationManager.AppSettings[\"setting1\"];\n string conn = ConfigurationManager.ConnectionStrings[\"prod\"].ConnectionString;\n }\n" }, { "answer_id": 114649, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 3, "selected": false, "text": "<appSettings> <appSettings> System.Configuration.ConfigurationSettings.AppSettings IConfigurationSectionHandler <configSections> ConfigurationSettings.GetConfig System.Configuration.ConfigurationManager App.config" }, { "answer_id": 114691, "author": "ZombieSheep", "author_id": 377, "author_profile": "https://Stackoverflow.com/users/377", "pm_score": 6, "selected": false, "text": "<configuration>\n <appSettings>\n <add key=\"setting1\" value=\"key\"/>\n </appSettings>\n <connectionStrings>\n <add name=\"prod\" connectionString=\"YourConnectionString\"/>\n </connectionStrings>\n</configuration>\n private void Form1_Load(object sender, EventArgs e)\n{\n string setting = ConfigurationManager.AppSettings[\"setting1\"];\n string conn = ConfigurationManager.ConnectionStrings[\"prod\"].ConnectionString;\n}\n" }, { "answer_id": 118510, "author": "maxfurni", "author_id": 20832, "author_profile": "https://Stackoverflow.com/users/20832", "pm_score": 5, "selected": false, "text": "string s = Properties.Settings.Default.MyConnectionString;\n" }, { "answer_id": 326066, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "System.Configuration.ConfigurationSettings.AppSettings[\"MyKey\"];\n" }, { "answer_id": 599116, "author": "Protagonist", "author_id": 460006, "author_profile": "https://Stackoverflow.com/users/460006", "pm_score": 2, "selected": false, "text": "Settings" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/727/" ]
114,541
<p>I want to write a <a href="http://getsongbird.com/" rel="noreferrer">Songbird</a> extension binds the multimedia keys available on all Apple Mac OS X platforms. Unfortunately this isn't an easy google search and I can't find any docs.</p> <p>Can anyone point me resources on accessing these keys or tell me how to do it?</p> <p>I have extensive programming experience, but this will be my first time coding in both MacOSX and <a href="http://wiki.songbirdnest.com/Developer/Developer_Intro/Extensions" rel="noreferrer">XUL</a> (Firefox, etc), so any tips on either are welcome.</p> <p>Please note that these are not regular key events. I assume it must be a different type of system event that I will need to hook or subscribe to.</p>
[ { "answer_id": 115333, "author": "rami", "author_id": 9629, "author_profile": "https://Stackoverflow.com/users/9629", "pm_score": 0, "selected": false, "text": "xev" }, { "answer_id": 423534, "author": "Rhythmic Fistman", "author_id": 22147, "author_profile": "https://Stackoverflow.com/users/22147", "pm_score": 3, "selected": true, "text": "NSApplication sendEvent @implementation NSApplication(WantMediaKeysCategoryKBye)\n- (void)sendEvent: (NSEvent*)event\n{\n // intercept media keys here\n}\n@end\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114541", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15948/" ]
114,543
<p>How can I horizontally center a <code>&lt;div&gt;</code> within another <code>&lt;div&gt;</code> using CSS?</p> <pre class="lang-html prettyprint-override"><code>&lt;div id=&quot;outer&quot;&gt; &lt;div id=&quot;inner&quot;&gt;Foo foo&lt;/div&gt; &lt;/div&gt; </code></pre>
[ { "answer_id": 114549, "author": "Justin Poliey", "author_id": 6967, "author_profile": "https://Stackoverflow.com/users/6967", "pm_score": 13, "selected": true, "text": "<div> #inner {\n width: 50%;\n margin: 0 auto;\n}\n width 50% <div> margin: 0 auto #inner {\n display: table;\n margin: 0 auto;\n}\n width #inner {\n display: table;\n margin: 0 auto;\n border: 1px solid black;\n}\n\n#outer {\n border: 1px solid red;\n width:100%\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> flexbox #inner { \n border: 0.05em solid black;\n}\n\n#outer {\n border: 0.05em solid red;\n width:100%;\n display: flex;\n justify-content: center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> align-items: center" }, { "answer_id": 1180400, "author": "Sneakyness", "author_id": 142632, "author_profile": "https://Stackoverflow.com/users/142632", "pm_score": 7, "selected": false, "text": "width margin-left margin-right auto" }, { "answer_id": 4753609, "author": "Alfred", "author_id": 291727, "author_profile": "https://Stackoverflow.com/users/291727", "pm_score": 10, "selected": false, "text": "div #outer {\n width: 100%;\n text-align: center;\n}\n\n#inner {\n display: inline-block;\n} <div id=\"outer\"> \n <div id=\"inner\">Foo foo</div>\n</div> div text-align" }, { "answer_id": 6460947, "author": "James Moberg", "author_id": 693068, "author_profile": "https://Stackoverflow.com/users/693068", "pm_score": 6, "selected": false, "text": "display:none; $(function(){\n $('#inner').show().width($('#innerTable').width()).css('margin','0 auto');\n}); <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n<div id=\"inner\" style=\"display:none;\">\n <form action=\"\">\n <table id=\"innerTable\">\n <tr><td>Name:</td><td><input type=\"text\"></td></tr>\n <tr><td>Email:</td><td><input type=\"text\"></td></tr>\n <tr><td>Email:</td><td><input type=\"submit\"></td></tr>\n </table>\n </form>\n</div>" }, { "answer_id": 8347427, "author": "Nuno", "author_id": 501066, "author_profile": "https://Stackoverflow.com/users/501066", "pm_score": 8, "selected": false, "text": "#centered {\n position: absolute;\n left: 50%;\n margin-left: -100px;\n} <div id=\"outer\" style=\"width:200px\">\n <div id=\"centered\">Foo foo</div>\n</div> transform:translateX(-50%); .centered {\n width: 200px;\n position: absolute;\n left: calc(50% - 100px);\n}\n" }, { "answer_id": 9655404, "author": "neoneye", "author_id": 78336, "author_profile": "https://Stackoverflow.com/users/78336", "pm_score": 7, "selected": false, "text": "#outer {\n width: 100%;\n height: 100%;\n display: box;\n box-orient: horizontal;\n box-pack: center;\n box-align: center;\n}\n" }, { "answer_id": 10568273, "author": "Salman von Abbas", "author_id": 362006, "author_profile": "https://Stackoverflow.com/users/362006", "pm_score": 7, "selected": false, "text": "display: inline-block #element {\n display: table;\n margin: 0 auto;\n}\n" }, { "answer_id": 10836683, "author": "ch2o", "author_id": 982488, "author_profile": "https://Stackoverflow.com/users/982488", "pm_score": 6, "selected": false, "text": "<div style=\"width:100%;\">\n <div style=\"width: 50%; margin: 0px auto;\">Text</div>\n</div> <div style=\"width:100%; text-align:center;\">\n <div style=\"width: 50%; margin: 0px auto; text-align:left;\">Text</div>\n</div> text-align:" }, { "answer_id": 12196466, "author": "kongaraju", "author_id": 1307915, "author_profile": "https://Stackoverflow.com/users/1307915", "pm_score": 9, "selected": false, "text": "display: box box-pack box-align box-orient box-direction #outer {\n width: 100%;\n /* Firefox */\n display: -moz-box;\n -moz-box-pack: center;\n -moz-box-align: center;\n /* Safari and Chrome */\n display: -webkit-box;\n -webkit-box-pack: center;\n -webkit-box-align: center;\n /* W3C */\n display: box;\n box-pack: center;\n box-align: center;\n}\n\n#inner {\n width: 50%;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> box-orient, box-flex, box-direction #outer {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n justify-content: center;\n align-items: center;\n}\n" }, { "answer_id": 15412749, "author": "Ray", "author_id": 1372225, "author_profile": "https://Stackoverflow.com/users/1372225", "pm_score": -1, "selected": false, "text": "body {\n margin: 50px 0px;\n padding: 0px;\n text-align: center;\n}\n\n#Content {\n width: 500px;\n margin: 0px auto;\n text-align: left;\n padding: 15px;\n border: 1px dashed #333;\n background-color: #EEE;\n}\n" }, { "answer_id": 15860345, "author": "william44isme", "author_id": 2075466, "author_profile": "https://Stackoverflow.com/users/2075466", "pm_score": 6, "selected": false, "text": "#inner{\n left: 0;\n right: 0;\n margin-left: auto;\n margin-right: auto;\n position: absolute;\n}\n" }, { "answer_id": 16144913, "author": "Danield", "author_id": 703717, "author_profile": "https://Stackoverflow.com/users/703717", "pm_score": 8, "selected": false, "text": "display:box <div class=\"box\">\n <div class=\"item1\">A</div>\n <div class=\"item2\">B</div>\n <div class=\"item3\">C</div>\n</div>\n .box {\n display: flex;\n flex-wrap: wrap; /* Optional. only if you want the items to wrap */\n justify-content: center; /* For horizontal alignment */\n align-items: center; /* For vertical alignment */\n}\n .box {\n display: flex;\n flex-wrap: wrap;\n /* Optional. only if you want the items to wrap */\n justify-content: center;\n /* For horizontal alignment */\n align-items: center;\n /* For vertical alignment */\n}\n* {\n margin: 0;\n padding: 0;\n}\nhtml,\nbody {\n height: 100%;\n}\n.box {\n height: 200px;\n display: flex;\n flex-wrap: wrap;\n justify-content: center;\n align-items: center;\n border: 2px solid tomato;\n}\n.box div {\n margin: 0 10px;\n width: 100px;\n}\n.item1 {\n height: 50px;\n background: pink;\n}\n.item2 {\n background: brown;\n height: 100px;\n}\n.item3 {\n height: 150px;\n background: orange;\n} <div class=\"box\">\n <div class=\"item1\">A</div>\n <div class=\"item2\">B</div>\n <div class=\"item3\">C</div>\n</div>" }, { "answer_id": 16776988, "author": "BenjaminRH", "author_id": 941158, "author_profile": "https://Stackoverflow.com/users/941158", "pm_score": 6, "selected": false, "text": "#outer {\n position: absolute;\n left: 50%;\n}\n\n#inner {\n position: relative;\n left: -50%;\n}\n" }, { "answer_id": 16954310, "author": "aamirha", "author_id": 949033, "author_profile": "https://Stackoverflow.com/users/949033", "pm_score": 4, "selected": false, "text": "<div id=\"outer\" style=\"width:100%\"> \n <div id=\"inner\" style=\"display:table;margin:0 auto;\">Foo foo</div>\n</div>\n" }, { "answer_id": 17743761, "author": "Ankit Jain", "author_id": 2594679, "author_profile": "https://Stackoverflow.com/users/2594679", "pm_score": 6, "selected": false, "text": "#outerDiv {\n width: 500px;\n}\n\n#innerDiv {\n width: 200px;\n margin: 0 auto;\n} <div id=\"outerDiv\">\n <div id=\"innerDiv\">Inner Content</div>\n</div>" }, { "answer_id": 18739996, "author": "Tom Maton", "author_id": 911553, "author_profile": "https://Stackoverflow.com/users/911553", "pm_score": 8, "selected": false, "text": "align #outer {\n position: relative;\n}\n #inner {\n margin: auto;\n position: absolute;\n left:0;\n right: 0;\n top: 0;\n bottom: 0;\n}\n center" }, { "answer_id": 19123062, "author": "Rajesh", "author_id": 1114506, "author_profile": "https://Stackoverflow.com/users/1114506", "pm_score": 3, "selected": false, "text": "#inner #inner {\n width: 50%;\n margin-left: 25%;\n}\n" }, { "answer_id": 19359956, "author": "Kenma", "author_id": 1460756, "author_profile": "https://Stackoverflow.com/users/1460756", "pm_score": 5, "selected": false, "text": "#container {\n display: table;\n width: <width of your container>;\n height: <height of your container>;\n}\n\n#inner {\n width: <width of your center div>;\n display: table-cell;\n margin: 0 auto;\n text-align: center;\n vertical-align: middle;\n}\n #inner display vertical-align" }, { "answer_id": 19589133, "author": "Willem de Wit", "author_id": 1474739, "author_profile": "https://Stackoverflow.com/users/1474739", "pm_score": 6, "selected": false, "text": "display: table; /* This parent can be any width and height */\n.outer {\n text-align: center;\n}\n\n/* The ghost, nudged to maintain perfect centering */\n.outer:before {\n content: '.';\n display: inline-block;\n height: 100%;\n vertical-align: middle;\n width: 0;\n overflow: hidden;\n}\n\n/* The element to be centered, can\n also be of any width and height */\n.inner {\n display: inline-block;\n vertical-align: middle;\n width: 300px;\n}\n" }, { "answer_id": 19715517, "author": "Josh Mc", "author_id": 685404, "author_profile": "https://Stackoverflow.com/users/685404", "pm_score": 3, "selected": false, "text": "line-height vertical-align 50% center inline-block <h1>Center dynamic box using only css test</h1>\n<div class=\"container\">\n <div class=\"center\">\n <div class=\"center-container\">\n <span class=\"dyn-box\">\n <div class=\"dyn-head\">This is a head</div>\n <div class=\"dyn-body\">\n This is a body<br />\n Content<br />\n Content<br />\n Content<br />\n Content<br />\n </div>\n </span>\n </div>\n </div>\n</div>\n .container {\n position: absolute;\n left: 0;\n right: 0;\n top: 0;\n bottom: 0;\n overflow: hidden;\n}\n\n.center {\n position: absolute;\n left: 50%;\n top: 50%;\n}\n\n.center-container {\n position: absolute;\n left: -2500px;\n top: -2500px;\n width: 5000px;\n height: 5000px;\n line-height: 5000px;\n text-align: center;\n overflow: hidden;\n}\n\n.dyn-box {\n display: inline-block;\n vertical-align: middle;\n line-height: 100%;\n /* Purely asthetic below this point */\n background: #808080;\n padding: 13px;\n border-radius: 11px;\n font-family: arial;\n}\n\n.dyn-head {\n background: red;\n color: white;\n min-width: 300px;\n padding: 20px;\n font-size: 23px;\n}\n\n.dyn-body {\n padding: 10px;\n background: white;\n color: red;\n}\n" }, { "answer_id": 19792397, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "margin: 0 auto;\n text-align: center;\n" }, { "answer_id": 20023094, "author": "Pnsadeghy", "author_id": 2148893, "author_profile": "https://Stackoverflow.com/users/2148893", "pm_score": 5, "selected": false, "text": "margin: auto 0;\n text-align: center;\n #outer{\n text-align: center;\n display: block; /* Or inline-block - base on your need */\n}\n\n#inner\n{\n position: relative;\n margin: 0 auto; /* It is good to be */\n}\n" }, { "answer_id": 20339458, "author": "user2952495", "author_id": 2952495, "author_profile": "https://Stackoverflow.com/users/2952495", "pm_score": -1, "selected": false, "text": "<center>\n </center>\n" }, { "answer_id": 20369553, "author": "Lalit Kumar Maurya", "author_id": 1637683, "author_profile": "https://Stackoverflow.com/users/1637683", "pm_score": 6, "selected": false, "text": "div#outer {\n height: 120px;\n background-color: red;\n}\n\ndiv#inner {\n width: 50%;\n height: 100%;\n background-color: green;\n margin: 0 auto;\n text-align: center; /* For text alignment to center horizontally. */\n line-height: 120px; /* For text alignment to center vertically. */\n} <div id=\"outer\" style=\"width:100%;\">\n <div id=\"inner\">Foo foo</div>\n</div> <div id=\"outer\" style=\"width:100%;\">\n <div class=\"inner\"> Foo Text </div>\n <div class=\"inner\"> Foo Text </div>\n <div class=\"inner\"> Foo Text </div>\n <div class=\"inner\"> </div>\n <div class=\"inner\"> </div>\n <div class=\"inner\"> </div>\n <div class=\"inner\"> </div>\n <div class=\"inner\"> </div>\n <div class=\"inner\"> Foo Text </div>\n</div>\n" }, { "answer_id": 21193027, "author": "Salman A", "author_id": 87015, "author_profile": "https://Stackoverflow.com/users/87015", "pm_score": 5, "selected": false, "text": ".outer .inner .inner .center-helper .center-helper .inner .center-helper .inner .outer body {\n font: medium sans-serif;\n}\n\n.outer {\n overflow: hidden;\n background-color: papayawhip;\n}\n\n.center-helper {\n display: inline-block;\n position: relative;\n left: 50%;\n background-color: burlywood;\n}\n\n.inner {\n display: inline-block;\n position: relative;\n left: -50%;\n background-color: wheat;\n} <div class=\"outer\">\n <div class=\"center-helper\">\n <div class=\"inner\">\n <h1>A div with no defined width</h1>\n <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br>\n Duis condimentum sem non turpis consectetur blandit.<br>\n Donec dictum risus id orci ornare tempor.<br>\n Proin pharetra augue a lorem elementum molestie.<br>\n Nunc nec justo sit amet nisi tempor viverra sit amet a ipsum.</p>\n </div>\n </div>\n</div>" }, { "answer_id": 21402241, "author": "caniz", "author_id": 3178923, "author_profile": "https://Stackoverflow.com/users/3178923", "pm_score": 5, "selected": false, "text": "#outer {\n margin - top: 100 px;\n height: 500 px; /* you can set whatever you want */\n border: 1 px solid# ccc;\n}\n\n#inner {\n border: 1 px solid# f00;\n position: relative;\n top: 50 % ;\n transform: translateY(-50 % );\n}\n" }, { "answer_id": 21706557, "author": "Miguel Leite", "author_id": 1732465, "author_profile": "https://Stackoverflow.com/users/1732465", "pm_score": 5, "selected": false, "text": "<div class=\"container\">\n <div class=\"content\">Your content goes here!</div>\n <div class=\"content\">Your content goes here!</div>\n <div class=\"content\">Your content goes here!</div>\n</div>\n $(document).ready(function() {\n $('.container .content').each( function() {\n container = $(this).closest('.container');\n content = $(this);\n\n containerHeight = container.height();\n contentHeight = content.height();\n\n margin = (containerHeight - contentHeight) / 2;\n content.css('margin-top', margin);\n })\n});\n $(window).resize(function() {\n $('.container .content').each( function() {\n container = $(this).closest('.container');\n content = $(this);\n\n containerHeight = container.height();\n contentHeight = content.height();\n\n margin = (containerHeight - contentHeight) / 2;\n content.css('margin-top', margin);\n })\n});\n" }, { "answer_id": 22273883, "author": "uSeRnAmEhAhAhAhAhA", "author_id": 2645707, "author_profile": "https://Stackoverflow.com/users/2645707", "pm_score": 1, "selected": false, "text": "inner { width: 50%; background-color: Khaki; margin: 0 auto; }\n" }, { "answer_id": 23714832, "author": "iamnotsam", "author_id": 362477, "author_profile": "https://Stackoverflow.com/users/362477", "pm_score": 7, "selected": false, "text": ".content {\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n} <div class=\"content\">This works with any content</div>" }, { "answer_id": 25287376, "author": "hossein ketabi", "author_id": 2757573, "author_profile": "https://Stackoverflow.com/users/2757573", "pm_score": 1, "selected": false, "text": "<div id=\"a\">\n <div id=\"b\"></div>\n</div>\n #a{\n border: 1px solid red;\n height: 120px;\n width: 400px\n}\n\n#b{\n border: 1px solid blue;\n height: 90px;\n width: 300px;\n position: relative;\n margin-left: auto;\n margin-right: auto;\n}\n" }, { "answer_id": 25446740, "author": "joan16v", "author_id": 1398876, "author_profile": "https://Stackoverflow.com/users/1398876", "pm_score": 5, "selected": false, "text": "#outer {\n width: 100%;\n text-align: center;\n}\n#inner {\n margin: auto;\n width: 200px;\n} <div id=\"outer\">\n <div id=\"inner\">Blabla</div>\n</div>" }, { "answer_id": 25942594, "author": "Gerald Goshorn", "author_id": 4056805, "author_profile": "https://Stackoverflow.com/users/4056805", "pm_score": 2, "selected": false, "text": "<!doctype html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <title>center a div within a div?</title>\n <style type=\"text/css\">\n *{\n margin: 0;\n padding: 0;\n }\n\n #outer{\n width: 80%;\n height: 500px;\n background-color: #003;\n margin: 0 auto;\n }\n\n #outer p{\n color: #FFF;\n text-align: center;\n }\n\n #inner{\n background-color: #901;\n width: 50%;\n height: 100px;\n margin: 0 auto;\n\n }\n\n #inner p{\n color: #FFF;\n text-align: center;\n }\n </style>\n </head>\n\n <body>\n <div id=\"outer\"><p>this is the outer div</p>\n <div id=\"inner\">\n <p>this is the inner div</p>\n </div>\n </div>\n </body>\n</html>\n" }, { "answer_id": 25946329, "author": "sarath", "author_id": 2614847, "author_profile": "https://Stackoverflow.com/users/2614847", "pm_score": 4, "selected": false, "text": "$(window).bind(\"load\", function() {\n var wwidth = $(\"#outer\").width();\n var width = $('#inner').width();\n $('#inner').attr(\"style\", \"padding-left: \" + wwidth / 2 + \"px; margin-left: -\" + width / 2 + \"px;\");\n});\n" }, { "answer_id": 26072829, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<div id=\"outter\">\n <div id=\"inner\"Centered content\">\n </div\n</div>\n #inner{\n width: 50%;\n margin: auto;\n}\n" }, { "answer_id": 27965715, "author": "Cees Timmerman", "author_id": 819417, "author_profile": "https://Stackoverflow.com/users/819417", "pm_score": 1, "selected": false, "text": "<div style=\"top: 50%; left: 50%;\n height: 100px; width: 100px;\n margin-top: -50px; margin-left: -50px;\n background: url('lib/loading.gif') no-repeat center #fff;\n text-align: center;\n position: fixed; z-index: 9002;\">Loading...</div>\n body" }, { "answer_id": 29011864, "author": "Kilian Stinson", "author_id": 2345972, "author_profile": "https://Stackoverflow.com/users/2345972", "pm_score": 6, "selected": false, "text": "transform #outer {\n position: relative;\n}\n\n#inner {\n position: absolute;\n left: 50%;\n\n transform: translateX(-50%);\n}\n translateX(-50%) #inner" }, { "answer_id": 30257156, "author": "anand jothi", "author_id": 4247052, "author_profile": "https://Stackoverflow.com/users/4247052", "pm_score": 3, "selected": false, "text": "#inner {\n width: 50%;\n margin: 0 auto;\n}\n" }, { "answer_id": 32328992, "author": "Ajay Gupta", "author_id": 2663073, "author_profile": "https://Stackoverflow.com/users/2663073", "pm_score": 2, "selected": false, "text": "<style>\n #outer {\n display: inline-block;\n width: 100%;\n height: 100%;\n text-align: center;\n vertical-align: middle;\n }\n\n #outer > #inner {\n display: inline-block;\n font-size: 19px;\n margin: 20px;\n max-width: 320px;\n min-height: 20px;\n min-width: 30px;\n padding: 14px;\n vertical-align: middle;\n }\n</style>\n <div id=\"outer\">\n <div id=\"inner\">\n ...These <div>ITEMS</div> <img src=\"URL\"/> are in center...\n </div>\n</div>\n BEFORE applying code:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃V..Middle & H..Center ┣━1\n┃ ┣━2\n┃ ┣━3\n┗┳━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┳┛\n 1 2 3 4 5\n\nAFTER:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┣━1\n┃ V..Middle & H..Center ┣━2\n┃ ┣━3\n┗┳━━━━━━┳━━━━━━┳━━━━━━┳━━━━━━┳┛\n 1 2 3 4 5\n <style>\n #outer {\n width: 100%;\n text-align: center;\n }\n\n #outer > .inner2 {\n display: inline-block;\n }\n</style>\n <div id=\"outer\">\n <img class=\"inner2\" src=\"URL-1\"> <img class=\"inner2\" src=\"URL-2\">\n</div>\n BEFORE applying code:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃┍━━━━━━━━━━┑ ┃\n┃│ img URL1 │ ┃\n┃┕━━━━━━━━━━┙ ┃\n┃┍━━━━━━━━━━┑ ┃\n┃│ img URL2 │ ┃\n┃┕━━━━━━━━━━┙ ┃\n┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n\nAFTER:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┍━━━━━━━━━━┑ ┍━━━━━━━━━━┑ ┣━1\n┃ │ img URL1 │ │ img URL2 │ ┣━2\n┃ ┕━━━━━━━━━━┙ ┕━━━━━━━━━━┙ ┣━3\n┗┳━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━┳┛\n 1 2 3 4 5\n <style>\n #outer {\n width: 100%;\n text-align: center;\n }\n\n #outer > img, #outer > div {\n display: inline-block;\n }\n</style>\n <div id=\"outer\">\n <img src=\"URL-1\"> Text1 <img src=\"URL-2\"> Text2\n</div>\n BEFORE applying code:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃┍━━━━━━━━┑ ┃\n┃│img URL1│ ┃\n┃┕━━━━━━━━┙ ┃\n┃Text1 ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL2│ ┃\n┃┕━━━━━━━━┙ ┃\n┃Text2 ┃\n┗━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n\nAFTER:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┍━━━━━━━━━┑ ┍━━━━━━━━┑ ┣━1\n┃ │img URL1 │ │img URL2│ ┣━2\n┃ ┕━━━━━━━━━┙Text1┕━━━━━━━━┙Text2 ┣━3\n┗┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳┛\n 1 2 3 4 5\n <style>\n .outer2 {\n width: 100%;\n text-align: center;\n }\n\n .outer2 > div, .outer2 > div > img {\n display: inline-block;\n }\n</style>\n <div class=\"outer2\">\n <div>\n Line1: <img src=\"URL-1\"> Text1 <img src=\"URL-2\">\n </div>\n</div>\n...\n<div class=\"outer2\">\n <div>\n Line2: <img src=\"URL-3\"> Text2 <img src=\"URL-4\">\n </div>\n</div>\n BEFORE applying code:\n┏━━━━━━━━━━━━━━━━━━━━━━┓\n┃Line1: ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL1│ ┃\n┃┕━━━━━━━━┙ ┃\n┃Text1 ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL2│ ┃\n┃┕━━━━━━━━┙ ┃\n┗━━━━━━━━━━━━━━━━━━━━━━┛\n........................\n┏━━━━━━━━━━━━━━━━━━━━━━┓\n┃Line2: ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL3│ ┃\n┃┕━━━━━━━━┙ ┃\n┃Text2 ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL4│ ┃\n┃┕━━━━━━━━┙ ┃\n┗━━━━━━━━━━━━━━━━━━━━━━┛\n\nAFTER:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┍━━━━━━━━┑ ┍━━━━━━━━┑ ┣━1\n┃ │img URL1│ │img URL2│ ┣━2\n┃ Line1:┕━━━━━━━━┙Text1┕━━━━━━━━┙ ┣━3\n┗┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳┛\n 1 2 3 4 5\n.......................................\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┍━━━━━━━━┑ ┍━━━━━━━━┑ ┣━1\n┃ │img URL3│ │img URL4│ ┣━2\n┃ Line2:┕━━━━━━━━┙Text2┕━━━━━━━━┙ ┣━3\n┗┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳┛\n 1 2 3 4 5\n <style>\n .outer2 {\n width: 100%;\n text-align: center;\n vertical-align: middle;\n }\n\n .outer2 > div, .outer2 > div > img {\n display: inline-block;\n vertical-align: middle;\n }\n</style>\n <div class=\"outer2\">\n <div>\n Line1: <img src=\"URL-1\"> Text1 <img src=\"URL-2\">\n </div>\n</div>\n...\n<div class=\"outer2\">\n <div>\n Line2: <img src=\"URL-3\"> Text2 <img src=\"URL-4\">\n </div>\n</div>\n BEFORE applying code:\n┏━━━━━━━━━━━━━━━━━━━━━━┓\n┃Line1: ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL1│ ┃\n┃┕━━━━━━━━┙ ┃\n┃Text1 ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL2│ ┃\n┃┕━━━━━━━━┙ ┃\n┗━━━━━━━━━━━━━━━━━━━━━━┛\n........................\n┏━━━━━━━━━━━━━━━━━━━━━━┓\n┃Line2: ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL3│ ┃\n┃┕━━━━━━━━┙ ┃\n┃Text2 ┃\n┃┍━━━━━━━━┑ ┃\n┃│img URL4│ ┃\n┃┕━━━━━━━━┙ ┃\n┗━━━━━━━━━━━━━━━━━━━━━━┛\n\nAFTER:\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┍━━━━━━━━┑ ┍━━━━━━━━┑ ┣━1\n┃ Line1:│img URL1│Text1│img URL2│ ┣━2\n┃ ┕━━━━━━━━┙ ┕━━━━━━━━┙ ┣━3\n┗┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳┛\n 1 2 3 4 5\n.......................................\n┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n┃ ┍━━━━━━━━┑ ┍━━━━━━━━┑ ┣━1\n┃ Line2:│img URL3│Text2│img URL4│ ┣━2\n┃ ┕━━━━━━━━┙ ┕━━━━━━━━┙ ┣━3\n┗┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳━━━━━━━━┳┛\n 1 2 3 4 5\n" }, { "answer_id": 33708242, "author": "Majid Sadr", "author_id": 3789730, "author_profile": "https://Stackoverflow.com/users/3789730", "pm_score": 2, "selected": false, "text": "#outer {postion: relative}\n#inner {\n width: 100px; \n height: 40px; \n position: absolute;\n top: 50%;\n margin-top: -20px; /* Half of your height */\n}\n" }, { "answer_id": 34386220, "author": "Justin Munce", "author_id": 4780578, "author_profile": "https://Stackoverflow.com/users/4780578", "pm_score": 2, "selected": false, "text": "margin: 0 auto; float: none;\n" }, { "answer_id": 34432583, "author": "Banti Mathur", "author_id": 4300993, "author_profile": "https://Stackoverflow.com/users/4300993", "pm_score": 2, "selected": false, "text": ".classname {\n display: box;\n margin: 0 auto;\n width: 500px /* Width set as per your requirement. */;\n}\n" }, { "answer_id": 35357708, "author": "nyn05", "author_id": 5758188, "author_profile": "https://Stackoverflow.com/users/5758188", "pm_score": 1, "selected": false, "text": "#outer{\n display: table;\n height: 100vh;\n width: 100%;\n}\n\n\n#inner{\n display: table-cell;\n vertical-align: middle;\n text-align: center;\n} <div id=\"outer\">\n <div id=\"inner\">\n <h1>\n set content center\n </h1>\n <div>\n hi this is the best way to align your items center\n </div>\n </div>\n</div>" }, { "answer_id": 35510639, "author": "John Slegers", "author_id": 1946501, "author_profile": "https://Stackoverflow.com/users/1946501", "pm_score": 5, "selected": false, "text": "text-align: center; display: inline-block; .container {\n width: 100%;\n height: 120px;\n background: #CCC;\n text-align: center;\n}\n\n.centered-content {\n display: inline-block;\n background: #FFF;\n padding: 20px;\n border: 1px solid #000;\n} <div class=\"container\">\n <div class=\"centered-content\">\n Center this!\n </div>\n</div> display: table; display: table-cell; vertical-align: middle; text-align: center; display: inline-block; .outer-container {\n display: table;\n width: 100%;\n height: 120px;\n background: #CCC;\n}\n\n.inner-container {\n display: table-cell;\n vertical-align: middle;\n text-align: center;\n}\n\n.centered-content {\n display: inline-block;\n background: #FFF;\n padding: 20px;\n border: 1px solid #000;\n} <div class=\"outer-container\">\n <div class=\"inner-container\">\n <div class=\"centered-content\">\n Center this!\n </div>\n </div>\n</div>" }, { "answer_id": 36259732, "author": "Gaurav Aggarwal", "author_id": 4119808, "author_profile": "https://Stackoverflow.com/users/4119808", "pm_score": 2, "selected": false, "text": ".inner{\n width: 500px; /* Assumed width */\n margin: 0 auto;\n}\n" }, { "answer_id": 37096327, "author": "Qmr", "author_id": 2681049, "author_profile": "https://Stackoverflow.com/users/2681049", "pm_score": 2, "selected": false, "text": "<div id=\"outer\" style=\"width:100%;margin: 0 auto; text-align: center;\"> \n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 37735442, "author": "Mardok", "author_id": 3170976, "author_profile": "https://Stackoverflow.com/users/3170976", "pm_score": 2, "selected": false, "text": "<p>Horz Center</p>\n<div class=\"outterDiv\">\n <div class=\"innerDiv horzCenter\"></div>\n</div>\n<p>Vert Center</p>\n<div class=\"outterDiv\">\n <div class=\"innerDiv vertCenter\"></div>\n</div>\n<p>True Center</p>\n<div class=\"outterDiv\">\n <div class=\"innerDiv trueCenter\"></div>\n</div>\n.vertCenter\n{\n position: absolute;\n top:50%;\n -ms-transform: translateY(-50%);\n -moz-transform: translateY(-50%);\n -webkit-transform: translateY(-50%);\n transform: translateY(-50%);\n}\n\n.horzCenter\n{\n position: absolute;\n left: 50%;\n -ms-transform: translateX(-50%);\n -moz-transform: translateX(-50%);\n -webkit-transform: translateX(-50%);\n transform: translateX(-50%);\n}\n\n.trueCenter\n{\n position: absolute;\n left: 50%;\n top: 50%;\n -ms-transform: translate(-50%, -50%);\n -moz-transform: translate(-50%, -50%);\n -webkit-transform: translate(-50%, -50%);\n transform: translate(-50%, -50%);\n}\n\n.outterDiv\n{\n position: relative;\n background-color: blue;\n width: 10rem;\n height: 10rem;\n margin: 2rem;\n}\n.innerDiv\n{\n background-color: red;\n width: 5rem;\n height: 5rem;\n}\n" }, { "answer_id": 38170372, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">\n </div>\n</div>\n #outer{\n width: 500px;\n background-color: #000;\n height: 500px\n}\n#inner{\n background-color: #333;\n margin: 0 auto;\n width: 50%;\n height: 250px;\n}\n" }, { "answer_id": 38673523, "author": "Friend", "author_id": 6284236, "author_profile": "https://Stackoverflow.com/users/6284236", "pm_score": 1, "selected": false, "text": "text-align:center; #outer {\n text-align: center;\n}\n #outer > div {\n margin: auto;\n width: 100px;\n}\n" }, { "answer_id": 39654350, "author": "Billal Begueradj", "author_id": 3329664, "author_profile": "https://Stackoverflow.com/users/3329664", "pm_score": 5, "selected": false, "text": "div.container {\n display: flex;\n justify-content: center; /* For horizontal alignment */\n align-items: center; /* For vertical alignment */\n}\n <div> height width" }, { "answer_id": 40361272, "author": "Saurav Rastogi", "author_id": 1687746, "author_profile": "https://Stackoverflow.com/users/1687746", "pm_score": 3, "selected": false, "text": "#outer {\n display: flex;\n align-content: center;\n justify-content: center;\n}\n #outer {\n display: flex;\n align-items: center;\n justify-content: center;\n border: 1px solid #ddd;\n width: 100%;\n height: 200px;\n } <div id=\"outer\"> \n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 40480047, "author": "Mr.Pandya", "author_id": 6554624, "author_profile": "https://Stackoverflow.com/users/6554624", "pm_score": 2, "selected": false, "text": "width div margin:0 auto;" }, { "answer_id": 41059156, "author": "amit bende", "author_id": 6374688, "author_profile": "https://Stackoverflow.com/users/6374688", "pm_score": -1, "selected": false, "text": ".outer {\n text-align: center;\n width: 100%\n}\n" }, { "answer_id": 41237712, "author": "Cyan Baltazar", "author_id": 6665604, "author_profile": "https://Stackoverflow.com/users/6665604", "pm_score": 2, "selected": false, "text": "#inner {\n display: flex;\n justify-content: center;\n}\n" }, { "answer_id": 41634428, "author": "ADH - THE TECHIE GUY", "author_id": 6677244, "author_profile": "https://Stackoverflow.com/users/6677244", "pm_score": 3, "selected": false, "text": "display:flex; {justify-content:center; ,align-items:center;} #outer {\n display: flex;\n justify-content: center;\n align-items: center;\n} <div id=\"outer\" style=\"width:100%\">\n <div id=\"inner\">Foo foo</div>\n</div> display:flex margin:auto; #outer {\n display: flex;\n}\n\n#inner {\n margin: auto;\n} <div id=\"outer\" style=\"width:100%\">\n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 41644871, "author": "bonyem", "author_id": 6921594, "author_profile": "https://Stackoverflow.com/users/6921594", "pm_score": 0, "selected": false, "text": "margin: 0 auto <div id=\"outer\" style=\"width:100%\"> \n <div id=\"inner\" style=\"margin:0 auto;width:50%\">Foo foo</div> \n</div>\n" }, { "answer_id": 41713418, "author": "Abdul Ghaffar", "author_id": 5324262, "author_profile": "https://Stackoverflow.com/users/5324262", "pm_score": 2, "selected": false, "text": "#inner {\n display: table;\n margin: 0 auto; \n}\n <div id=\"outer\" style=\"width:100%\"> \n <div id=\"inner\">Foo foo</div>\n</div>\n" }, { "answer_id": 41952200, "author": "sneha", "author_id": 7445431, "author_profile": "https://Stackoverflow.com/users/7445431", "pm_score": -1, "selected": false, "text": "<div id=\"outer\" style=\"width:100%\"> \n <div id=\"inner\" style=\"text-align:center\">Foo foo</div>\n</div>\n" }, { "answer_id": 42173742, "author": "Faizal Munna", "author_id": 7434879, "author_profile": "https://Stackoverflow.com/users/7434879", "pm_score": 2, "selected": false, "text": "<div class=\"outer\">\n <div class=\"inner\">\n Foo foo\n </div>\n</div>\n .outer{\n width: 100%;\n height: 300px;\n background: yellow;\n}\n\n.inner{\n width: 30%;\n height: 200px;\n margin: auto;\n background: red;\n text-align: center\n}\n" }, { "answer_id": 42345578, "author": "Sankar", "author_id": 2131576, "author_profile": "https://Stackoverflow.com/users/2131576", "pm_score": 1, "selected": false, "text": "Margin:0px auto #inner{\n display: block;\n margin: 0px auto;\n width: 100px;\n} <div id=\"outer\" style=\"width:100%\"> \n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 42736256, "author": "Legends", "author_id": 2581562, "author_profile": "https://Stackoverflow.com/users/2581562", "pm_score": 3, "selected": false, "text": "display: flex;\njustify-content: space-between; // <-- space-between or space-around\n justify-content #containerdiv {\n display: flex;\n justify-content: space-between;\n}\n\n#containerdiv > div {\n background-color: blue;\n width: 50px;\n color: white;\n text-align: center;\n} <!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width\">\n <title>JS Bin</title>\n</head>\n<body>\n <div id=\"containerdiv\">\n <div>88</div>\n <div>77</div>\n <div>55</div>\n <div>33</div>\n <div>40</div>\n <div>45</div>\n </div>\n</body>\n</html>" }, { "answer_id": 43193443, "author": "Sandesh Damkondwar", "author_id": 3589104, "author_profile": "https://Stackoverflow.com/users/3589104", "pm_score": 5, "selected": false, "text": "#outer {\n display: flex;\n justify-content: center;\n}\n" }, { "answer_id": 43882882, "author": "Agu Dondo", "author_id": 936703, "author_profile": "https://Stackoverflow.com/users/936703", "pm_score": 2, "selected": false, "text": "#outer{\n position: relative;\n}\n\n#inner{\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%)\n}\n" }, { "answer_id": 44020300, "author": "Faizal", "author_id": 8012850, "author_profile": "https://Stackoverflow.com/users/8012850", "pm_score": 2, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n #outer {\n text-align: center;\n}\n#inner{\n display: inline-block;\n}\n" }, { "answer_id": 44084783, "author": "Alireza", "author_id": 5423108, "author_profile": "https://Stackoverflow.com/users/5423108", "pm_score": 2, "selected": false, "text": "margin #parent {\n width: 100%;\n background-color: #CCCCCC;\n}\n\n#child {\n width: 30%; /* We need the width */\n margin: 0 auto; /* This does the magic */\n color: #FFFFFF;\n background-color: #000000;\n padding: 10px;\n text-align: center;\n} <div id=\"parent\">\n <div id=\"child\">I'm the child and I'm horizontally centered! My daddy is a greyish div dude!</div>\n</div> margin: 0 auto; width" }, { "answer_id": 44338349, "author": "Yahya Essam", "author_id": 6471803, "author_profile": "https://Stackoverflow.com/users/6471803", "pm_score": 2, "selected": false, "text": "text-align:center #inner {\n text-align: center;\n } <div id=\"outer\" style=\"width:100%\">\n <div id=\"inner\"><button>hello</button></div>\n</div>" }, { "answer_id": 44453030, "author": "Paolo Forgia", "author_id": 1685157, "author_profile": "https://Stackoverflow.com/users/1685157", "pm_score": 5, "selected": false, "text": "display: flex justify-content: center #inner {\n display: inline-block;\n}\n\n#outer {\n display: flex;\n justify-content: center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> text-align: center width: 100% display: block display: inline display: inline-block #inner {\n display: inline-block;\n}\n\n#outer {\n text-align: center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> margin: 0 auto display: table #inner {\n display: table;\n margin: 0 auto;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> transform: translate position: absolute left: 50% #inner {\n position: absolute;\n left: 50%;\n transform: translate(-50%, 0%);\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> <center> <center> text-align: center #inner {\n display: inline-block;\n} <div id=\"outer\">\n <center>\n <div id=\"inner\">Foo foo</div>\n </center>\n</div>" }, { "answer_id": 45251566, "author": "Heitor", "author_id": 3063226, "author_profile": "https://Stackoverflow.com/users/3063226", "pm_score": 2, "selected": false, "text": "<div id=\"outer\"> \n <center>Foo foo</center>\n</div>\n" }, { "answer_id": 45322869, "author": "sibaspage", "author_id": 5241734, "author_profile": "https://Stackoverflow.com/users/5241734", "pm_score": -1, "selected": false, "text": ".outer{\n display: table;\n width: 100%;\n height: 100%;\n}\n.inner {\n vertical-align: middle;\n}\n" }, { "answer_id": 45510181, "author": "Rafiqul Islam", "author_id": 4788956, "author_profile": "https://Stackoverflow.com/users/4788956", "pm_score": 2, "selected": false, "text": "#inner {\n width: 90%;\n margin: 0 auto;\n text-align:center;\n} <div id=\"outer\"> \n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 46382081, "author": "antelove", "author_id": 7656367, "author_profile": "https://Stackoverflow.com/users/7656367", "pm_score": 2, "selected": false, "text": ".outer {\n display: -webkit-flex;\n display: flex;\n\n //-webkit-justify-content: center; \n //justify-content: center;\n \n //align-items: center;\n\n width: 100%;\n height: 100px;\n background-color: lightgrey;\n}\n\n.inner {\n background-color: cornflowerblue;\n padding: 2rem;\n margin: auto; \n \n //align-self: center; \n} <div class=\"outer\"> \n <div class=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 46382588, "author": "Elias MP", "author_id": 5770216, "author_profile": "https://Stackoverflow.com/users/5770216", "pm_score": 2, "selected": false, "text": ".centerElement{\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n" }, { "answer_id": 46449757, "author": "Руслан", "author_id": 7546060, "author_profile": "https://Stackoverflow.com/users/7546060", "pm_score": 2, "selected": false, "text": "<div id=\"parent\">\n <div class=\"child\"></div>\n</div>\n #parent {\n display: flex;\n justify-content: center;\n}\n #parent {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n" }, { "answer_id": 46604060, "author": "sed", "author_id": 1483143, "author_profile": "https://Stackoverflow.com/users/1483143", "pm_score": 2, "selected": false, "text": ".container {\n width:1200px;\n margin-left: calc(50% - 600px);\n}\n" }, { "answer_id": 46741879, "author": "Husain Ahmed", "author_id": 5218509, "author_profile": "https://Stackoverflow.com/users/5218509", "pm_score": 2, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n\n#inner {\n width: 50%;\n margin: 0 auto;\n text-align: center;\n}\n" }, { "answer_id": 46807365, "author": "SUNIL KUMAR E.U", "author_id": 4688232, "author_profile": "https://Stackoverflow.com/users/4688232", "pm_score": 2, "selected": false, "text": "<style>\n #outer{\n text-align: center;\n width: 100%;\n }\n #inner{\n text-align: center;\n }\n</style>\n" }, { "answer_id": 47604928, "author": "Gaurang Sondagar", "author_id": 6152004, "author_profile": "https://Stackoverflow.com/users/6152004", "pm_score": 1, "selected": false, "text": "1. First Method\n#outer {\n text-align: center;\n width: 100%;\n}\n#inner {\n display: inline-block;\n}\n\n\n2. Second method\n#outer {\n position: relative;\n overflow: hidden;\n}\n.centered {\n position: absolute;\n left: 50%;\n}\n" }, { "answer_id": 47885563, "author": "Temani Afif", "author_id": 8620333, "author_profile": "https://Stackoverflow.com/users/8620333", "pm_score": 2, "selected": false, "text": "flex:1 .container {\n display: flex;\n border: 1px solid;\n}\n\n.container:before,\n.container:after {\n content: \"\";\n flex: 1;\n}\n\n.inner {\n border: 1px solid red;\n padding: 5px;\n} <div class=\"container\">\n <div class=\"inner\">\n Foo content\n </div>\n</div> .container {\n display: flex;\n flex-direction: column;\n border: 1px solid;\n min-height: 200px;\n}\n\n.container:before,\n.container:after {\n content: \"\";\n flex: 1;\n}\n\n.inner {\n border: 1px solid red;\n padding: 5px;\n} <div class=\"container\">\n <div class=\"inner\">\n Foo content\n </div>\n</div>" }, { "answer_id": 48437064, "author": "Anu", "author_id": 7635131, "author_profile": "https://Stackoverflow.com/users/7635131", "pm_score": 1, "selected": false, "text": "#inner {\n display: table;\n margin: 0 auto;\n} <div id=\"outer\" style=\"width:100%\">\n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 48437400, "author": "Anu", "author_id": 7635131, "author_profile": "https://Stackoverflow.com/users/7635131", "pm_score": 1, "selected": false, "text": "margin: auto width: .DivCenter{\n width: 50%;\n margin: auto;\n border: 3px solid #000;\n padding: 10px;\n}\n" }, { "answer_id": 49306625, "author": "Shivam Chhetri", "author_id": 9138195, "author_profile": "https://Stackoverflow.com/users/9138195", "pm_score": 2, "selected": false, "text": "#outer{\n display: flex;\n}\n#inner{\n margin: auto;\n}\n margin: 0 auto;\n margin: auto 0;\n" }, { "answer_id": 50785476, "author": "Milan Panigrahi", "author_id": 9121968, "author_profile": "https://Stackoverflow.com/users/9121968", "pm_score": 5, "selected": false, "text": "display: flex justify-content: center #outer{\n display: flex;\n justify-content: center;\n}\n" }, { "answer_id": 51349575, "author": "MANGESH SUPE", "author_id": 9857446, "author_profile": "https://Stackoverflow.com/users/9857446", "pm_score": -1, "selected": false, "text": "<!DOCTYPE html>\n<html>\n <head>\n <title>Center</title>\n <style>\n .outer{\n text-align: center;\n }\n .inner{\n width: 500px;\n margin: 0 auto;\n background: brown;\n color: red;\n }\n\n</style>\n\n </head>\n\n <body>\n\n <div class=\"outer\">\n <div class=\"inner\">This DIV is centered</div>\n </div>\n\n </body>\n</html>" }, { "answer_id": 51724022, "author": "Jaison James", "author_id": 1374554, "author_profile": "https://Stackoverflow.com/users/1374554", "pm_score": 2, "selected": false, "text": "<div class=\"outer\">\n <div class=\"inner\"></div>\n</div>\n.outer{\n width: 500px;\n height: 500px;\n position: relative;\n background: yellow;\n}\n.inner{\n width: 100px;\n height: 100px;\n background:red;\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%);\n}\n" }, { "answer_id": 51844248, "author": "Galarist", "author_id": 10123520, "author_profile": "https://Stackoverflow.com/users/10123520", "pm_score": 1, "selected": false, "text": "#outer {\n width: 160px;\n padding: 5px;\n border-style: solid;\n border-width: thin;\n display: block;\n}\n\n#inner {\n margin: auto;\n background-color: lightblue;\n border-style: solid;\n border-width: thin;\n width: 80px;\n padding: 10px;\n text-align: center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 52230054, "author": "Mark Salvania", "author_id": 10326622, "author_profile": "https://Stackoverflow.com/users/10326622", "pm_score": 2, "selected": false, "text": "#inner #outer {\n background: black;\n position: relative;\n width:150px;\n height:150px;\n}\n\n#inner { \n background:white;\n position: absolute;\n left:50%;\n top: 50%;\n transform: translate(-50%,-50%);\n -webkit-transform: translate(-50%,-50%);\n -moz-transform: translate(-50%,-50%); \n -o-transform: translate(-50%,-50%);\n} <div id=\"outer\"> \n <div id=\"inner\">Foo foo</div>\n</div> #outer {\n background: black;\n position: relative;\n width:150px;\n height:150px;\n}\n\n#inner { \n background:white;\n position: absolute;\n left:50%;\n transform: translate(-50%,0);\n -webkit-transform: translate(-50%,0);\n -moz-transform: translate(-50%,0); \n -o-transform: translate(-50%,0);\n} <div id=\"outer\"> \n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 52230061, "author": "drewkiimon", "author_id": 8249594, "author_profile": "https://Stackoverflow.com/users/8249594", "pm_score": 2, "selected": false, "text": "display: flex margin: 0 auto .wrapper {\n display: flex;\n /* Adding whatever height & width we want */\n height: 300px;\n width: 300px;\n /* Just so you can see it is centered */\n background: peachpuff;\n}\n\n.inner {\n /* center horizontally */\n margin: 0 auto;\n /* center vertically */\n /* margin: auto 0; */\n /* center */\n /* margin: 0 auto; */\n} <div class=\"wrapper\">\n <div class=\"inner\">\n I am horizontally!\n </div>\n</div>" }, { "answer_id": 52266619, "author": "Morteza Sadri", "author_id": 7707724, "author_profile": "https://Stackoverflow.com/users/7707724", "pm_score": 2, "selected": false, "text": "display: flex; align-items: center; #outer #outer {\n display: flex;\n align-items: center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> #inner #outer #outer {\n height: 500px;\n display: flex;\n align-items: center;\n background-color: blue;\n}\n\n#inner {\n height: 100px;\n background: yellow;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> #inner" }, { "answer_id": 53296801, "author": "Mohammed Rabiulla RABI", "author_id": 9321142, "author_profile": "https://Stackoverflow.com/users/9321142", "pm_score": 2, "selected": false, "text": "div{\n width: 100px;\n height: 100px;\n margin: 0 auto;\n}\n .parentdiv{\n position: relative;\n height: 500px;\n}\n\n.child_div{\n position: absolute;\n height: 200px;\n width: 500px;\n left: 0;\n right: 0;\n margin: 0 auto;\n}\n" }, { "answer_id": 53465902, "author": "Fatemeh Khosravi Farsani", "author_id": 2370039, "author_profile": "https://Stackoverflow.com/users/2370039", "pm_score": 2, "selected": false, "text": "#inner {\n position: absolute;\n margin: 0 auto;\n left: 0;\n width: 7%;\n right: 0;\n}\n" }, { "answer_id": 53973313, "author": "orghu", "author_id": 2817442, "author_profile": "https://Stackoverflow.com/users/2817442", "pm_score": 1, "selected": false, "text": "margin-left left #inner {\n width: 100%;\n max-width: 65px; /* To adapt to screen width. It can be whatever you want. */\n left: 65px; /* This has to be approximately the same as the max-width. */\n}\n" }, { "answer_id": 54642130, "author": "Ady Ngom", "author_id": 2074138, "author_profile": "https://Stackoverflow.com/users/2074138", "pm_score": 4, "selected": false, "text": ".parentBox {\n display: flex;\n justify-content: center\n}\n" }, { "answer_id": 55045803, "author": "pavelbere", "author_id": 11129768, "author_profile": "https://Stackoverflow.com/users/11129768", "pm_score": 2, "selected": false, "text": ".outer\n{\n background-color: rgb(230,230,255);\n width: 100%;\n height: 50px;\n}\n.inner\n{\n background-color: rgb(200,200,255);\n width: 50%;\n height: 50px;\n margin: 0 auto;\n} <div class=\"outer\">\n <div class=\"inner\">\n margin 0 auto\n </div>\n</div>" }, { "answer_id": 55360820, "author": "Hassan Siddiqui", "author_id": 3169136, "author_profile": "https://Stackoverflow.com/users/3169136", "pm_score": 3, "selected": false, "text": "#outer {\n display: flex;\n justify-content: center;\n} <div id=\"outer\"> \n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 55515508, "author": "Shashin Bhayani", "author_id": 10429035, "author_profile": "https://Stackoverflow.com/users/10429035", "pm_score": 5, "selected": false, "text": "#outer {\n display: flex;\n justify-content: center\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> #outer {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n width: 100%;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center\n}\n #inner {\n position: absolute;\n left: 50%;\n transform: translate(-50%)\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> #inner {\n position: absolute;\n left: 50%;\n -webkit-transform: translate(-50%);\n -ms-transform: translate(-50%);\n transform: translate(-50%)\n}\n" }, { "answer_id": 56275647, "author": "Riddhi Busa", "author_id": 5440324, "author_profile": "https://Stackoverflow.com/users/5440324", "pm_score": -1, "selected": false, "text": "#outer {\n width: 100%;\n text-align: center;\n}\n#inner {\n display: inline-block;\n}\n <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n" }, { "answer_id": 56361573, "author": "Javed Khan", "author_id": 9704900, "author_profile": "https://Stackoverflow.com/users/9704900", "pm_score": 1, "selected": false, "text": "#inner {\n width: 50%;\n margin: 0 auto;\n}\n" }, { "answer_id": 57012108, "author": "Appy Sharma", "author_id": 7802577, "author_profile": "https://Stackoverflow.com/users/7802577", "pm_score": 4, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n #outer {\n display: flex;\n justify-content: center;\n}\n #outer {\n display: flex;\n align-items: center;\n}\n #outer{\n display: flex;\n justify-content: center;\n align-items: center;\n}\n" }, { "answer_id": 57100359, "author": "SB3NDER", "author_id": 9350702, "author_profile": "https://Stackoverflow.com/users/9350702", "pm_score": 2, "selected": false, "text": "#inner {\n position: absolute;\n left: 50%;\n}\n\n#inner > div {\n position: relative;\n left: -50%;\n} <div id=\"outer\">\n <div id=\"inner\"><div>Foo foo</div></div>\n</div>" }, { "answer_id": 57272025, "author": "Asmit", "author_id": 10721198, "author_profile": "https://Stackoverflow.com/users/10721198", "pm_score": 3, "selected": false, "text": "<!DOCTYPE html>\n<html>\n <head>\n <style>\n #outer-div {\n width: 100%;\n text-align: center;\n background-color: #000\n }\n #inner-div {\n display: inline-block;\n margin: 0 auto;\n padding: 3px;\n background-color: #888\n }\n </style>\n </head>\n\n <body>\n <div id =\"outer-div\" width=\"100%\">\n <div id =\"inner-div\"> I am a easy horizontally centered div.</div>\n <div>\n </body>\n</html>\n" }, { "answer_id": 59006837, "author": "Sawan mishra", "author_id": 3454233, "author_profile": "https://Stackoverflow.com/users/3454233", "pm_score": 3, "selected": false, "text": "#outer {\n display: flex;\n align-items: center;\n justify-content: center;\n} <!DOCTYPE html>\n<html>\n <head>\n\n </head>\n\n <body>\n <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n </div>\n </body>\n</html>" }, { "answer_id": 59263638, "author": "Shoma", "author_id": 7901403, "author_profile": "https://Stackoverflow.com/users/7901403", "pm_score": 3, "selected": false, "text": "body{height: 200px} <div id=\"outer\">\n <div id=\"centered\">Foo foo</div>\n</div>\n #outer{\n display: flex;\n width: 100%;\n height: 200px;\n}\n#centered {\n margin: auto;\n}\n #centered {\n margin: 0px auto;\n}\n #outer{\n display: flex;\n width: 100%;\n height: 200px;\n}\n#centered {\n margin: auto;\n}\n\n<div id=\"outer\">\n <div id=\"centered\">Foo foo</div>\n</div>\n #outer{\n display: flex;\n width: 100%;\n height: 200px;\n border: 1px solid #000000;\n}\n#centered {\n margin: auto;\n border: 1px solid #000000;\n} <div id=\"outer\">\n <div id=\"centered\">Foo foo</div>\n</div>" }, { "answer_id": 59607763, "author": "ChandanK", "author_id": 9826412, "author_profile": "https://Stackoverflow.com/users/9826412", "pm_score": 4, "selected": false, "text": "#outer {\n display: flex;\n justify-content: center;\n}\n #outer {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n" }, { "answer_id": 60116165, "author": "Alessandro_Russo", "author_id": 2893733, "author_profile": "https://Stackoverflow.com/users/2893733", "pm_score": 3, "selected": false, "text": "// Center horizontal mixin\n@mixin center-horizontally {\n position: absolute;\n left: 50%;\n transform: translate(-50%, -50%);\n}\n\n// Center horizontal class\n.center-horizontally {\n @include center-horizontally;\n}\n <div class=\"center-horizontally\">\n I'm centered!\n</div>\n position: relative; @mixin center-horizontally {\n display: flex;\n justify-content: center;\n}\n\n// Center horizontal class\n.center-horizontally {\n @include center-horizontally;\n}\n <div class=\"center-horizontally\">\n <div>I'm centered!</div>\n</div>\n" }, { "answer_id": 60301181, "author": "jual ahmed", "author_id": 9797396, "author_profile": "https://Stackoverflow.com/users/9797396", "pm_score": 2, "selected": false, "text": "#outer{\n display: flex;\n justify-content: center;\n} #outer {\n display: inline-grid;\n grid-template-rows: 100px 100px 100px;\n grid-template-columns: 100px 100px 100px;\n grid-gap: 3px;\n}" }, { "answer_id": 61367209, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "margin: 0 auto display:table <center>" }, { "answer_id": 62515727, "author": "Utkarsh Tyagi", "author_id": 13779469, "author_profile": "https://Stackoverflow.com/users/13779469", "pm_score": 3, "selected": false, "text": ".outer{\n width: 300px; /* For example */\n height: 300px; /* For example */\n background: red;\n}\n.inner{\n position: relative;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n width: 200px;\n height: 200px;\n background: yellow;\n} <body>\n <div class='outer'>\n <div class='inner'></div>\n </div>\n</body>" }, { "answer_id": 63123622, "author": "air5", "author_id": 7764088, "author_profile": "https://Stackoverflow.com/users/7764088", "pm_score": 4, "selected": false, "text": "display: grid div {\n border: 1px dotted grey;\n}\n\n#outer {\n display: grid;\n place-items: center;\n height: 50px; /* not necessary */\n} <!DOCTYPE html>\n<html>\n <head>\n </head>\n\n <body>\n <div id=\"outer\">\n <div>Foo foo</div>\n </div>\n </body>\n</html>" }, { "answer_id": 63469234, "author": "Priya jain", "author_id": 6076863, "author_profile": "https://Stackoverflow.com/users/6076863", "pm_score": 2, "selected": false, "text": "#outer {\n display: flex;\n justify-content: center;\n}\n" }, { "answer_id": 63746323, "author": "sabban", "author_id": 13435350, "author_profile": "https://Stackoverflow.com/users/13435350", "pm_score": 2, "selected": false, "text": "#outer\n{\n display: grid;\n justify-content: center;\n\n} <div id=\"outer\">\n <div id=\"inner\">hello</div>\n</div> enter code here" }, { "answer_id": 64015413, "author": "mdmundo", "author_id": 11720321, "author_profile": "https://Stackoverflow.com/users/11720321", "pm_score": 2, "selected": false, "text": "<div style=\"position: absolute;left: 50%;top: 50%;-webkit-transform: translate(-50%, -50%);transform: translate(-50%, -50%);\"><div>Example</div></div>\n" }, { "answer_id": 64672383, "author": "John T", "author_id": 9403953, "author_profile": "https://Stackoverflow.com/users/9403953", "pm_score": 2, "selected": false, "text": "#outer {\n margin: auto;\n left: 0;\n right: 0;\n position: fixed;\n}\n#inner {\n text-align: center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 65804173, "author": "Jone", "author_id": 14769063, "author_profile": "https://Stackoverflow.com/users/14769063", "pm_score": 0, "selected": false, "text": ".wrapper {border: 1px solid #678596; max-width: 350px; margin: 30px auto;} \n \n.parentClass { display: flex; justify-content: center; align-items: center; height: 300px;}\n \n.parentClass div {margin: 5px; background: #678596; width: 50px; line-height: 50px; text-align: center; font-size: 30px; color: #fff;} <h1>Flexbox Center Horizontally and Vertically Center Align an Element</h1>\n<h2>justify-content: center; align-items: center;</h2>\n\n<div class=\"wrapper\">\n\n<div class=\"parentClass\">\n <div>c</div>\n</div>\n\n</div>" }, { "answer_id": 66435423, "author": "proseosoc", "author_id": 5225541, "author_profile": "https://Stackoverflow.com/users/5225541", "pm_score": 3, "selected": false, "text": "position: fixed;\ntop: 0; left: 0;\ntransform: translate(calc(50vw - 50%));\n position: fixed;\ntop: 0; left: 0;\ntransform: translate(calc(50vw - 50%), calc(50vh - 50%));\n" }, { "answer_id": 66739798, "author": "Satish Chandra Gupta", "author_id": 9445290, "author_profile": "https://Stackoverflow.com/users/9445290", "pm_score": 3, "selected": false, "text": "margin-left margin-right margin: 0 auto display: block #outer {\n background-color: silver;\n}\n#inner {\n width: max-content;\n margin: 0 auto;\n background-color: #f07878;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> justify-content center #outer {\n display: flex;\n justify-content: center;\n background-color: silver;\n}\n#inner {\n background-color: #f07878;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div> postion:relative left: 50% transform: translateX(-50%) #outer {\n position: relative;\n background-color: silver;\n}\n#inner {\n position: absolute;\n left: 50%;\n transform: translateX(-50%);\n background-color: #f07878;\n} <div id=\"outer\">\n <center>\n <div id=\"inner\">Foo foo</div>\n </center>\n</div>" }, { "answer_id": 66866694, "author": "Vasyl Gutnyk", "author_id": 3277216, "author_profile": "https://Stackoverflow.com/users/3277216", "pm_score": 0, "selected": false, "text": "button {\n margin: 0 auto;\n width: fit-content;\n display: block;\n}\n// container should have set width (for example 100%)\n" }, { "answer_id": 67053491, "author": "Abdullah Ch", "author_id": 13708712, "author_profile": "https://Stackoverflow.com/users/13708712", "pm_score": 3, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n #outer{\n display: grid;\n place-items: center;\n}\n\n" }, { "answer_id": 67132637, "author": "Egon Stetmann.", "author_id": 7238789, "author_profile": "https://Stackoverflow.com/users/7238789", "pm_score": 2, "selected": false, "text": "transform() position ...\n<div class=\"parent\">\n <form> ... </form>\n <div> ... </div>\n</div>\n .parent {\n display: grid;\n place-items: center;\n}\n" }, { "answer_id": 67390020, "author": "Tharindu Lakshan", "author_id": 11384233, "author_profile": "https://Stackoverflow.com/users/11384233", "pm_score": 3, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n #outer{\n width: 100%;\n}\n\n#inner{\n margin: auto;\n}\n" }, { "answer_id": 67547259, "author": "Krutik Raut", "author_id": 13613400, "author_profile": "https://Stackoverflow.com/users/13613400", "pm_score": 0, "selected": false, "text": "#outer {\ndisplay:grid;\nplace-items:center;\n} <div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>" }, { "answer_id": 69733298, "author": "Ismoil Shokirov", "author_id": 12924484, "author_profile": "https://Stackoverflow.com/users/12924484", "pm_score": 2, "selected": false, "text": "#outer #inner #outer {\n display: flex;\n justify-content: center;\n align-items: center; /* if you also need vertical center */\n}\n #outer {\n position: relative;\n}\n#inner {\n position: absolute;\n left: 50%;\n translate: transformX(-50%)\n}\n #outer {\n position: relative;\n}\n#inner {\n position: absolute;\n left: 50%;\n top: 50%;\n translate: transform(-50%, -50%)\n}\n #inner {\n width: fit-content;\n margin: 0 auto;\n}\n" }, { "answer_id": 69778212, "author": "Anil Parshi", "author_id": 15405352, "author_profile": "https://Stackoverflow.com/users/15405352", "pm_score": 0, "selected": false, "text": "justify-content: center; text-align: center; #content_block {\n border: 1px solid black;\n padding: 10px;\n width: 50%;\n text-align: center;\n}\n\n#container {\n border: 1px solid red;\n width:100%;\n padding: 20px;\n display: flex;\n justify-content: center;\n} <div id=\"container\">\n <div id=\"content_block\">Foo foo check</div>\n</div>" }, { "answer_id": 70569854, "author": "Rounin - Standing with Ukraine", "author_id": 3897775, "author_profile": "https://Stackoverflow.com/users/3897775", "pm_score": 3, "selected": false, "text": "<div> <div> margin auto margin calc() padding box-sizing calc() position: absolute margin-left position: absolute transform: translateX() display: inline-block text-align: center display: table display: table-cell display: flex justify-content: center display: grid justify-items: center auto .outer {\n width: 300px;\n height: 180px;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n width: 150px;\n height: 180px;\n margin: 0 auto;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> calc .outer {\n width: 300px;\n height: 180px;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n width: 150px;\n height: 180px;\n margin: 0 calc((300px - 150px) / 2);\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> calc box-sizing .outer {\n width: 300px;\n height: 180px;\n padding: 0 calc((300px - 150px) / 2);\n background-color: rgb(255, 0, 0);\n box-sizing: border-box;\n}\n\n.inner {\n width: 150px;\n height: 180px;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> position: absolute left: 50% margin-left .outer {\n position: relative;\n width: 300px;\n height: 180px;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n position: absolute;\n left: 50%;\n width: 150px;\n height: 180px;\n margin-left: -75px;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> position: absolute left: 50% transform: translateX() .outer {\n position: relative;\n width: 300px;\n height: 180px;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n position: absolute;\n left: 50%;\n width: 150px;\n height: 180px;\n background-color: rgb(255, 255, 0);\n transform: translateX(-75px);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> display: inline-block text-align: center .outer {\n position: relative;\n width: 300px;\n height: 180px;\n text-align: center;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n display: inline-block;\n width: 150px;\n height: 180px;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> display: table padding box-sizing .outer {\n display: table;\n width: 300px;\n height: 180px;\n padding: 0 75px;\n background-color: rgb(255, 0, 0);\n box-sizing: border-box;\n}\n\n.inner {\n display: table-cell;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> display: flex justify-content: center .outer {\n display: flex;\n justify-content: center;\n width: 300px;\n height: 180px;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n flex: 0 0 150px;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div> display: grid justify-items: center .outer {\n display: grid;\n justify-items: center;\n width: 300px;\n height: 180px;\n background-color: rgb(255, 0, 0);\n}\n\n.inner {\n width: 150px;\n background-color: rgb(255, 255, 0);\n} <div class=\"outer\">\n <div class=\"inner\"></div>\n</div>" }, { "answer_id": 70785617, "author": "Ali Hamza Yaseen", "author_id": 10144242, "author_profile": "https://Stackoverflow.com/users/10144242", "pm_score": 0, "selected": false, "text": "#outer{\n display: flex;\n width: 100%;\n height: 200px;\n justify-content:center;\n align-items:center;\n}\n" }, { "answer_id": 71138412, "author": "Vishal Kardam", "author_id": 16431434, "author_profile": "https://Stackoverflow.com/users/16431434", "pm_score": 0, "selected": false, "text": "<html> *{\n margin: 0;\n padding: 0;\n }\n #outer{\n background: red;\n width: 100%;\n height: 100vh;\n display: flex;\n /*center For vertically*/\n justify-content: center;\n flex-direction: column;\n /*center for horizontally*/\n align-items: center;\n }\n #inner{\n width: 80%;\n height: 40px;\n background: grey;\n margin-top:5px;\n } <!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>horizontally center an element</title>\n</head>\n\n<body>\n<div id=\"outer\">\n <div id=\"inner\">1</div>\n <div id=\"inner\" style=\"background: green;\">2</div>\n <div id=\"inner\" style=\"background: yellow;\">3</div>\n</div>\n</body>\n</html>" }, { "answer_id": 72238157, "author": "mirazimi", "author_id": 6742006, "author_profile": "https://Stackoverflow.com/users/6742006", "pm_score": 0, "selected": false, "text": "<div class=\"container\">\n<div class=\"res-banner\">\n<img class=\"imgmelk\" src=\"~/File/opt_img.jpg\" >\n</div>\n</div>\n .res-banner{\n width:309px;\n margin: auto;\n height:309px;\n }\n" }, { "answer_id": 72403665, "author": "Mubeen Ahmad", "author_id": 17344570, "author_profile": "https://Stackoverflow.com/users/17344570", "pm_score": 1, "selected": false, "text": "<div> <div> text-align text-align: center text-align: right text-align: left text-align: justify div.a {\n text-align: center;\n}\n\ndiv.b {\n text-align: left;\n}\n\ndiv.c {\n text-align: right;\n} \n\ndiv.d {\n text-align: justify;\n} <h1>The text-align Property</h1>\n\n<div class=\"a\">\n<h2>text-align: center:</h2>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</p>\n</div>\n\n<div class=\"b\">\n<h2>text-align: left:</h2>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</p>\n</div>\n\n<div class=\"c\">\n<h2>text-align: right:</h2>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</p>\n</div>\n\n<div class=\"d\">\n<h2>text-align: justify:</h2>\n<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</p>\n</div>" }, { "answer_id": 73393666, "author": "Chathuranga CPM", "author_id": 2913984, "author_profile": "https://Stackoverflow.com/users/2913984", "pm_score": 0, "selected": false, "text": "<div id=\"outer\">\n <div id=\"inner\">Foo foo</div>\n</div>\n\n\n\n#outer{\n display:flex;\n align-items:center;\n}\n" }, { "answer_id": 73449205, "author": "legend", "author_id": 19670872, "author_profile": "https://Stackoverflow.com/users/19670872", "pm_score": -1, "selected": false, "text": "<div align=center>\n (code goes here)\n</div>\n <!-- css here -->\n .center-me {\n margin: 0 auto;\n }\n\n<!-- html here -->\n <div class=\"center-me\">\n (code goes here)\n </div>\n" }, { "answer_id": 74247962, "author": "A. Ravindu Silva", "author_id": 18738231, "author_profile": "https://Stackoverflow.com/users/18738231", "pm_score": -1, "selected": false, "text": "#outer {\n position: absolute;\n left: 50%;\n}\n\n#inner {\n position: relative;\n left: -50%;\n}\n" }, { "answer_id": 74567666, "author": "Harvir", "author_id": 16195196, "author_profile": "https://Stackoverflow.com/users/16195196", "pm_score": -1, "selected": false, "text": " <div id=\"outer\">\n <center> \n<div id=\"inner\">Foo foo</div> \n</center> \n</div>\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114543", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20403/" ]
114,555
<p>I'm fairly new to the world of versioning but would like to introduce Subversion into our small development team as we're finding that more and more we are working on the same projects/files. We primarily code in <code>PHP</code> on a <code>LAMP</code> environment (Red Hat Enterprise).</p> <p>What I'm looking for are some starting points to get me up and running such as installation/configuration guides for Red Hat. I use Dreamweaver <code>CS3</code> (I see that Subversion functions will be introduced in <code>CS4</code>) so would be willing to look at other PHP IDEs with Subversion integration, do you have any preferences? I'm open to suggestions.</p>
[ { "answer_id": 114662, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 2, "selected": true, "text": "svnadmin create --fs-type=fsfs" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13658/" ]
114,575
<p>I'm passing around some objects through web service and some of them contain java.sql.Date. Because Date doesn't have empty constructor it doesn't want to get serialized. </p> <p>First part of a question is easy: what is the best way to pass a date between client and service? </p> <p>Second part is bit trickier: Once I decide how to pass dates around, I can obviously declare date transient and make some wrapper class to pass dates as String or whatever, but how to apply same solution as transparently as possible to several classes that include Date? </p> <p>(I have a hunch that DynamicProxy thingy might be a solution, but reading documentation on Sun's site wasn't very helpful, so if it really is something in that direction, some clarification would be appreciated)</p> <p>Edit: I asked wrong question, sorry (some misunderstanding between me and coworker what is actually a problem). Problem occurs because of deserializing. So once I have date in xml format it tries to deserialize itself as GregorianCalendar. Other part of a question still remains: What is the best way to receive something (long timestamp or GregorianCalendar) and convert it to sql date, without making 10 different wrappers for 10 different classes. I'm using a NetBeans for code and wsdl generation. </p>
[ { "answer_id": 114641, "author": "paul", "author_id": 11249, "author_profile": "https://Stackoverflow.com/users/11249", "pm_score": 0, "selected": false, "text": "XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));\nencoder.setPersistenceDelegate(\n Rectangle.class, \n new DefaultPersistenceDelegate(new String[]{\"x\", \"y\", \"width\", \"height\"}));\nencoder.writeObject(groups);\nencoder.close();\n" }, { "answer_id": 115107, "author": "Argelbargel", "author_id": 2992, "author_profile": "https://Stackoverflow.com/users/2992", "pm_score": 0, "selected": false, "text": "java.sql.Date date = new java.sql.Date(calendar.getTimeInMillis);" }, { "answer_id": 28037492, "author": "Basil Bourque", "author_id": 642706, "author_profile": "https://Stackoverflow.com/users/642706", "pm_score": 1, "selected": false, "text": "2015-01-16T20:15:43+02:00\n2015-01-16T18:15:43Z\n Z +00:00 2007-12-03T10:15:30+01:00[Europe/Paris] LocalDate java.sql.Date java.time.LocalDate myJavaSqlDate.toLocalDate() LocalDate LocalDate Serializable java.util.Date Calendar SimpleDateFormat java.sql.* Interval YearWeek YearQuarter" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4433/" ]
114,586
<p>What is the smartest way to design a math parser? What I mean is a function that takes a math string (like: "2 + 3 / 2 + (2 * 5)") and returns the calculated value? I did write one in VB6 ages ago but it ended up being way to bloated and not very portable (or smart for that matter...). General ideas, psuedo code or real code is appreciated. </p>
[ { "answer_id": 55853186, "author": "gbenroscience", "author_id": 1845404, "author_profile": "https://Stackoverflow.com/users/1845404", "pm_score": 1, "selected": false, "text": " MathExpression expr = new MathExpression(\"(34+32)-44/(8+9(3+2))-22\"); \n System.out.println(\"result: \" + expr.solve());\n\n result: 43.16981132075472\n MathExpression expr = new MathExpression(\"r=3;P=2*pi*r;\"); \nSystem.out.println(\"result: \" + expr.getValue(\"P\"));\n MathExpression expr = new MathExpression(\"f(x)=39*sin(x^2)+x^3*cos(x);f(3)\"); \nSystem.out.println(\"result: \" + expr.solve());\n\nresult: -10.65717648378352\n MathExpression expr = new MathExpression(\"f(x)=x^3*ln(x); diff(f,3,1)\"); \nSystem.out.println(\"result: \" + expr.solve());\n\n result: 38.66253179403897\n x^3 * ln(x) MathExpression expr = new MathExpression(\"f(x)=2*x; intg(f,1,3)\"); \nSystem.out.println(\"result: \" + expr.solve());\n\nresult: 7.999999999998261... approx: 8\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
114,658
<p>I keep hearing that </p> <pre><code>catch (Exception ex) </code></pre> <p>Is bad practise, however, I often use it in event handlers where an operation may for example go to network, allowing the possibility of many different types of failure. In this case, I catch all exceptions and display the error message to the user in a message box.</p> <p>Is this considered bad practise? There's nothing more I can do with the exception: I don't want it to halt the application, the user needs to know what happened, and I'm at the top level of my code. What else should I be doing?</p> <p>EDIT:</p> <p>People are saying that I should look through the stack of calls and handle errors specifically, because for example a StackOverflow exception cannot be handled meaningfully. However, halting the process is the <b>worst</b> outcome, I want to prevent that at all costs. If I can't handle a StackOverflow, so be it - the outcome will be no worse than not catching exceptions at all, and in 99% of cases, informing the user is the least bad option as far as I'm concerned.</p> <p>Also, despite my best efforts to work out all of the possible exceptions that can be thrown, in a large code-base it's likely that I would miss some. And for most of them the best defense is still to inform the user.</p>
[ { "answer_id": 114693, "author": "Rasmus Faber", "author_id": 5542, "author_profile": "https://Stackoverflow.com/users/5542", "pm_score": 6, "selected": true, "text": "catch (Exception ex){}\n catch (Exception ex){ return false; }\n" }, { "answer_id": 114726, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 4, "selected": false, "text": "catch (Exception ex)\n" }, { "answer_id": 114751, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "try {\n myThing.DoStuff();\n}\ncatch (StuffGoneWrongException ex) {\n //figure out what you need to do or bail\n}\n" }, { "answer_id": 114869, "author": "MusiGenesis", "author_id": 14606, "author_profile": "https://Stackoverflow.com/users/14606", "pm_score": 2, "selected": false, "text": "try {something} catch (SqlException) {do stuff} catch (Exception) {do other stuff}\n" }, { "answer_id": 1194825, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "Dim myGuid As Guid = Nothing\n\nTry\n myGuid = New Guid(strGuid)\n 'Some processing here...\n\nCatch ex As FormatException\n lblError.Text = \"Invalid ID\"\n\nCatch ex As Exception \n Throw\n\nFinally\n If myGuid IsNot Nothing Then\n myGuid = Nothing\n End If\n\nEnd Try\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6448/" ]
114,698
<p>We have a lot of spreadsheets (xls) in our source code repository. These are usually edited with gnumeric or openoffice.org, and are mostly used to populate databases for unit testing with <a href="http://www.dbunit.org/" rel="noreferrer">dbUnit</a>. There are no easy ways of doing diffs on xls files that I know of, and this makes merging extremely tedious and error prone.</p> <p>I've tried to converting the spreadsheets to xml and doing a regular diff, but it really feels like it should be a last resort. </p> <p>I'd like to perform the diffing (and merging) with <code>git</code> as I do with text files. How would I do this, e.g. when issuing <code>git diff</code>?</p>
[ { "answer_id": 114759, "author": "Laurent", "author_id": 10786, "author_profile": "https://Stackoverflow.com/users/10786", "pm_score": 7, "selected": false, "text": "=if(Sheet1!A1 <> Sheet2!A1, \"X\", \"\")" }, { "answer_id": 12359446, "author": "Toby", "author_id": 233266, "author_profile": "https://Stackoverflow.com/users/233266", "pm_score": 1, "selected": false, "text": "java.lang.AssertionError:\nExpected: entire workbook to be equal\n but: cell at \"C14\" contained <\"bananas\"> expected <nothing>,\n cell at \"C15\" contained <\"1,850,000 EUR\"> expected <\"1,850,000.00 EUR\">,\n cell at \"D16\" contained <nothing> expected <\"Tue Sep 04 06:30:00\">\n at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)\n" }, { "answer_id": 14756427, "author": "kbulgrien", "author_id": 856172, "author_profile": "https://Stackoverflow.com/users/856172", "pm_score": 2, "selected": false, "text": "row c s c:s" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13365/" ]
114,725
<p>I’ve got a problem with Visual Basic (6) in combination with LDAP. When I try to connect to an LDAP store, I always get errors like ‘Bad Pathname’ or ‘Table does not exist’ (depending on what the code looks like).</p> <p>This is the part of the code I wrote to connect:</p> <pre><code>path = "LDAP://xx.xxx.xxx.xxx:xxx/" Logging.WriteToLogFile "Test1", logINFO Set conn = CreateObject("ADODB.Connection") conn.Provider = "ADsDSOObject" conn.Properties("User ID") = "USER_ID" conn.Properties("Password") = "PASSWORD" conn.Properties("Encrypt Password") = True conn.Properties("ADSI Flag") = 34 Logging.WriteToLogFile "Test2", logINFO conn.Open "Active Directory Provider" Logging.WriteToLogFile "Test3", logINFO Set rs = conn.Execute("&lt;" &amp; path &amp; "ou=Some,ou=Kindof,o=Searchbase&gt;;(objectclass=*);name;subtree") Logging.WriteToLogFile "Test4", logINFO </code></pre> <p>The logfile shows “Test1” , “Test2”, “Test3” and then “Table does not exist”, so it’s the line “Set rs = conn.Execute(…)” where things go wrong (pretty obvious…).</p> <p>In my code, I try to connect in a secure way. I found out it has nothing to do with SSL/certificates though, because it’s also not possible to establish an anonymous unsecured connection. Funny thing is: I wrote a small test app in .NET in five minutes. With that app I was able to connect (anonymously) and read results from the LDAP store, no problems at all.</p> <p>Does anyone have any experience with the combination LDAP and VB6 and maybe know what could be the problem? I googled and saw some example code snippets, but unfortunately none of them worked (same error messages as result). Thanks in advance!</p>
[ { "answer_id": 114790, "author": "Darrel Miller", "author_id": 6819, "author_profile": "https://Stackoverflow.com/users/6819", "pm_score": 2, "selected": false, "text": " Set oinfo = New ADSystemInfo\n sDomain = Split(oinfo.DomainDNSName, \".\")\n '-- Get Datasets from the Active Directory\n\n '-- Connect to Active Directory in logged in domain\n con.Open \"Provider=ADsDSOObject;Encrypt Password=False;Integrated Security=SSPI;Data Source=ADSDSOObject;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648\"\n\n '-- Query all serviceConnectionPoints in the Active Directory \n '-- that contain the keyword \"urn://tavis.net/TM/Database\" \n '-- and return the full path to the object\n\n Set rst = con.Execute(\"<LDAP://DC=\" & sDomain(0) & \",DC=\" & sDomain(1) & \">;(&(objectCategory=serviceConnectionPoint)(keywords=urn://tavis.net/TM/Database));Name, AdsPath;subTree\")\n" }, { "answer_id": 642661, "author": "AviD", "author_id": 10080, "author_profile": "https://Stackoverflow.com/users/10080", "pm_score": 1, "selected": false, "text": "Open() Execute() \"<\" & path & \"ou=Some/ou=Kindof/o=Searchbase>;(objectclass=*);name;subtree\"\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
114,728
<p>One of my DBs have grown closer to permitted size.</p> <p>Inorder to find out the table containing the max data, i used the following query:</p> <pre><code>exec sp_MSforeachtable @command1="print '?' exec sp_spaceused '?'" </code></pre> <p>It returned the culprit table comprising the max data.</p> <p>As a next step, i want to cleanup the rows based on the size. For this, i would like to order the rows based on size.</p> <p>How to achieve this using a query? Are there any tools to do this?</p>
[ { "answer_id": 114827, "author": "Casper", "author_id": 18729, "author_profile": "https://Stackoverflow.com/users/18729", "pm_score": 1, "selected": false, "text": "SELECT * \nFROM #TempTable\nOrder by dataSize desc\n SELECT LEN(CONVERT(nvarchar(MAX), LogProperties)) AS length\nFROM EventLog\nORDER BY length DESC\n" }, { "answer_id": 114856, "author": "Sam Saffron", "author_id": 17174, "author_profile": "https://Stackoverflow.com/users/17174", "pm_score": 0, "selected": false, "text": "delete table where id in \n(\n select top 100 id\n from table\n order by datalength(event_text) + length(varchar_column) desc\n) \n" }, { "answer_id": 114886, "author": "Christopher Klein", "author_id": 17632, "author_profile": "https://Stackoverflow.com/users/17632", "pm_score": 1, "selected": false, "text": "\nWITH table_space_usage\n( schema_name, table_name, index_name, used, reserved, ind_rows, tbl_rows )\nAS (\nSELECT s.Name\n , o.Name\n , coalesce(i.Name, 'HEAP')\n , p.used_page_count * 8\n , p.reserved_page_count * 8\n , p.row_count\n , case when i.index_id in ( 0, 1 ) then p.row_count else 0 end\nFROM sys.dm_db_partition_stats p\n INNER JOIN sys.objects as o\n ON o.object_id = p.object_id\n INNER JOIN sys.schemas as s\n ON s.schema_id = o.schema_id\n LEFT OUTER JOIN sys.indexes as i\n on i.object_id = p.object_id and i.index_id = p.index_id\n WHERE o.type_desc = 'USER_TABLE'\n and o.is_ms_shipped = 0\n)\n SELECT t.schema_name\n , t.table_name\n , t.index_name\n , sum(t.used) as used_in_kb\n , sum(t.reserved) as reserved_in_kb\n , case grouping(t.index_name) \n when 0 then sum(t.ind_rows) \n else sum(t.tbl_rows) end as rows\n FROM table_space_usage as t\n GROUP BY\n t.schema_name\n , t.table_name\n , t.index_name\n WITH ROLLUP\n ORDER BY\n grouping(t.schema_name)\n , t.schema_name\n , grouping(t.table_name)\n , t.table_name\n , grouping(t.index_name)\n , t.index_name\n" }, { "answer_id": 114978, "author": "Tokabi", "author_id": 315, "author_profile": "https://Stackoverflow.com/users/315", "pm_score": 4, "selected": false, "text": "declare @table varchar(20)\ndeclare @idcol varchar(10)\ndeclare @sql varchar(1000)\n\nset @table = 'Employees'\nset @idcol = 'EmployeeId'\nset @sql = 'select ' + @idcol +' , (0'\n\nselect @sql = @sql + ' + isnull(datalength(' + name + '), 1)' \n from syscolumns where id = object_id(@table)\nset @sql = @sql + ') as rowsize from ' + @table + ' order by rowsize desc'\n\nexec (@sql)\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15425/" ]
114,733
<p>Do anyone have good ideas of how to modify the toolbar for the WinForms version of the ReportViewer Toolbar? That is, I want to remove some buttons and varius, but it looks like the solution is to create a brand new toolbar instead of modifying the one that is there.</p> <p>Like, I had to remove export to excel, and did it this way:</p> <pre><code> // Disable excel export foreach (RenderingExtension extension in lr.ListRenderingExtensions()) { if (extension.Name == "Excel") { //extension.Visible = false; // Property is readonly... FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic); fi.SetValue(extension, false); } } </code></pre> <p>A bit trickysh if you ask me.. For removing toolbarbuttons, an possible way was to iterate through the Control array inside the ReportViewer and change the Visible property for the buttons to hide, but it gets reset all the time, so it is not an good way..</p> <p>WHEN do MS come with an new version btw?</p>
[ { "answer_id": 355705, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": " private readonly string[] ZOOM_VALUES = { \"25%\", \"50%\", \"75%\", \"100%\", \"110%\", \"120%\", \"125%\", \"130%\", \"140%\", \"150%\", \"175%\", \"200%\", \"300%\", \"400%\", \"500%\" };\n private readonly int DEFAULT_ZOOM = 3;\n //--\n\n public ucReportViewer()\n {\n InitializeComponent(); \n this.reportViewer1.ProcessingMode = ProcessingMode.Local;\n\n setScaleFactor(ZOOM_VALUES[DEFAULT_ZOOM]);\n\n Control[] tb = reportViewer1.Controls.Find(\"ReportToolBar\", true);\n\n ToolStrip ts;\n if (tb != null && tb.Length > 0 && tb[0].Controls.Count > 0 && (ts = tb[0].Controls[0] as ToolStrip) != null)\n {\n //here we go if our trick works (tested at .NET Framework 2.0.50727 SP1)\n ToolStripComboBox tscb = new ToolStripComboBox();\n tscb.DropDownStyle = ComboBoxStyle.DropDownList;\n\n tscb.Items.AddRange(ZOOM_VALUES); \n tscb.SelectedIndex = 3; //100%\n\n tscb.SelectedIndexChanged += new EventHandler(toolStripZoomPercent_Click);\n\n ts.Items.Add(tscb);\n }\n else\n { \n //if there is some problems - just use context menu\n ContextMenuStrip cmZoomMenu = new ContextMenuStrip();\n\n for (int i = 0; i < ZOOM_VALUES.Length; i++)\n {\n ToolStripMenuItem tsmi = new ToolStripMenuItem(ZOOM_VALUES[i]);\n\n tsmi.Checked = (i == DEFAULT_ZOOM);\n //tsmi.Tag = (IntPtr)cmZoomMenu;\n tsmi.Click += new EventHandler(toolStripZoomPercent_Click);\n\n cmZoomMenu.Items.Add(tsmi);\n }\n\n reportViewer1.ContextMenuStrip = cmZoomMenu;\n } \n }\n\n private bool setScaleFactor(string value)\n {\n try\n {\n int percent = Convert.ToInt32(value.TrimEnd('%'));\n\n reportViewer1.ZoomMode = ZoomMode.Percent;\n reportViewer1.ZoomPercent = percent;\n\n return true;\n }\n catch\n {\n return false;\n }\n }\n\n\n private void toolStripZoomPercent_Click(object sender, EventArgs e)\n {\n ToolStripMenuItem tsmi = sender as ToolStripMenuItem;\n ToolStripComboBox tscb = sender as ToolStripComboBox;\n\n if (tscb != null && tscb.SelectedIndex > -1)\n {\n setScaleFactor(tscb.Items[tscb.SelectedIndex].ToString());\n }\n else if (tsmi != null)\n {\n if (setScaleFactor(tsmi.Text))\n {\n foreach (ToolStripItem tsi in tsmi.Owner.Items)\n {\n ToolStripMenuItem item = tsi as ToolStripMenuItem;\n\n if (item != null && item.Checked)\n {\n item.Checked = false;\n }\n }\n\n tsmi.Checked = true;\n }\n else\n {\n tsmi.Checked = false;\n }\n }\n }\n" }, { "answer_id": 1683049, "author": "Chris", "author_id": 204038, "author_profile": "https://Stackoverflow.com/users/204038", "pm_score": 3, "selected": false, "text": "ToolStrip toolStrip = (ToolStrip)reportViewer.Controls.Find(\"toolStrip1\", true)[0]\n toolStrip.Items.Add(...)\n" }, { "answer_id": 27667387, "author": "alex_vkcr", "author_id": 3578480, "author_profile": "https://Stackoverflow.com/users/3578480", "pm_score": 1, "selected": false, "text": "using Microsoft.Reporting.WinForms;\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Forms;\n\nnamespace X\n{\n class ReportViewerPlus : ReportViewer\n {\n private Button boton { get; set; }\n\n public ReportViewerPlus(Button but) {\n this.boton = but;\n testc(this.Controls[0]);\n }\n public ReportViewerPlus()\n {\n }\n private void testc(Control item){\n if(item is ToolStrip) \n { \n ToolStripItemCollection tsic = ((ToolStrip)item).Items;\n tsic.Insert(0, new ToolStripControlHost(boton)); \n return; \n } \n for (int i = 0; i < item.Controls.Count; i++) \n { \n testc(item.Controls[i]); \n } \n }\n }\n}\n" }, { "answer_id": 29372802, "author": "Joseph", "author_id": 4734672, "author_profile": "https://Stackoverflow.com/users/4734672", "pm_score": 2, "selected": false, "text": "private void AddPrintBtn()\n { \n foreach (Control c in rv.Controls)\n {\n foreach (Control c1 in c.Controls)\n {\n foreach (Control c2 in c1.Controls)\n {\n foreach (Control c3 in c2.Controls)\n {\n if (c3.ToString() == \"Microsoft.Reporting.WebForms.ToolbarControl\")\n {\n foreach (Control c4 in c3.Controls)\n {\n if (c4.ToString() == \"Microsoft.Reporting.WebForms.PageNavigationGroup\")\n {\n var btn = new Button();\n btn.Text = \"Criteria\";\n btn.ID = \"btnFlip\";\n btn.OnClientClick = \"$('#pnl').toggle();\";\n c4.Controls.Add(btn);\n return;\n }\n }\n }\n }\n }\n }\n }\n }\n" }, { "answer_id": 30645044, "author": "lison", "author_id": 1182712, "author_profile": "https://Stackoverflow.com/users/1182712", "pm_score": 0, "selected": false, "text": "public CustOrderReportForm() {\n InitializeComponent();\n CustomizeReport(this.reportViewer1);\n}\n\n\nprivate void CustomizeReport(Control reportControl, int recurCount = 0) {\n Console.WriteLine(\"\".PadLeft(recurCount + 1, '.') + reportControl.GetType() + \":\" + reportControl.Name);\n if (reportControl is Button) {\n CustomizeReportButton((Button)reportControl, recurCount);\n }\n else if (reportControl is ToolStrip) {\n CustomizeReportToolStrip((ToolStrip)reportControl, recurCount);\n }\n foreach (Control childControl in reportControl.Controls) {\n CustomizeReport(childControl, recurCount + 1);\n }\n}\n\n//-------------------------------------------------------------\n\n\nvoid CustomizeReportToolStrip(ToolStrip c, int recurCount) {\n List<ToolStripItem> customized = new List<ToolStripItem>();\n foreach (ToolStripItem i in c.Items) {\n if (CustomizeReportToolStripItem(i, recurCount + 1)) {\n customized.Add(i);\n }\n }\n foreach (var i in customized) c.Items.Remove(i);\n}\n\n//-------------------------------------------------------------\n\nvoid CustomizeReportButton(Button button, int recurCount) {\n}\n\n//-------------------------------------------------------------\n\nbool CustomizeReportToolStripItem(ToolStripItem i, int recurCount) {\n Console.WriteLine(\"\".PadLeft(recurCount + 1, '.') + i.GetType() + \":\" + i.Name);\n if (i.Name == \"pageSetup\") {\n return true;\n }\n else if (i.Name == \"printPreview\") {\n return true;\n }\n return false; ;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3308/" ]
114,772
<p>I need to create and add custom headers to an ASP.NET 2.0 application. The case is simulation of an SSO-login in our dev/test environment.</p> <p>When I try to add headers I run into the "Not supported on this platform." error. BigJim has a nice post on the subject here: <a href="http://bigjimindc.blogspot.com/2007/07/ms-kb928365-aspnet-requestheadersadd.html" rel="nofollow noreferrer">http://bigjimindc.blogspot.com/2007/07/ms-kb928365-aspnet-requestheadersadd.html</a></p> <p>The root of my problem lies in the fact that I need to simulate various persons logging into my application. Not just adding static data in a HttpModule. I need to take values from a couple of TextBoxes and transfer information from these into custom headers and then re-direct the user. The HttpModule stuff happens to early in the pipeline...</p> <p>Does anyone now if there exsist a simple redirect/proxy solution that one could use in a dev environment? Or have simple/beautiful way of doing it in code?</p>
[ { "answer_id": 114943, "author": "Jon Adams", "author_id": 2291, "author_profile": "https://Stackoverflow.com/users/2291", "pm_score": 0, "selected": false, "text": "Response.AddHeader()" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
114,804
<p>I want to write a real-time analysis tool for wireless traffic.</p> <p>Does anyone know how to read from a promiscuous (or sniffing) device in C? </p> <p>I know that you need to have root access to do it. I was wondering if anyone knows what functions are necessary to do this. Normal sockets don't seem to make sense here.</p>
[ { "answer_id": 115169, "author": "DGentry", "author_id": 4761, "author_profile": "https://Stackoverflow.com/users/4761", "pm_score": 5, "selected": true, "text": "s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))\n ldh = load halfword (from packet) \njeq = jump if equal \nret = return with exit code \n" }, { "answer_id": 229296, "author": "user30684", "author_id": 30684, "author_profile": "https://Stackoverflow.com/users/30684", "pm_score": 3, "selected": false, "text": "eth0 int raw_init (const char *device)\n{\n struct ifreq ifr;\n int raw_socket;\n\n memset (&ifr, 0, sizeof (struct ifreq));\n\n /* Open A Raw Socket */\n if ((raw_socket = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 1)\n {\n printf (\"ERROR: Could not open socket, Got #?\\n\");\n exit (1);\n }\n\n /* Set the device to use */\n strcpy (ifr.ifr_name, device);\n\n /* Get the current flags that the device might have */\n if (ioctl (raw_socket, SIOCGIFFLAGS, &ifr) == -1)\n {\n perror (\"Error: Could not retrive the flags from the device.\\n\");\n exit (1);\n }\n\n /* Set the old flags plus the IFF_PROMISC flag */\n ifr.ifr_flags |= IFF_PROMISC;\n if (ioctl (raw_socket, SIOCSIFFLAGS, &ifr) == -1)\n {\n perror (\"Error: Could not set flag IFF_PROMISC\");\n exit (1);\n }\n printf (\"Entering promiscuous mode\\n\");\n\n /* Configure the device */\n\n if (ioctl (raw_socket, SIOCGIFINDEX, &ifr) < 0)\n {\n perror (\"Error: Error getting the device index.\\n\");\n exit (1);\n }\n\n return raw_socket;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114804", "https://Stackoverflow.com", "https://Stackoverflow.com/users/542226/" ]
114,814
<p>In Bash, how do I count the number of non-blank lines of code in a project?</p>
[ { "answer_id": 114835, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 2, "selected": false, "text": "awk '/^[[:space:]]*$/ {++x} END {print x}' \"$testfile\"\n" }, { "answer_id": 114836, "author": "Michael Cramer", "author_id": 1496728, "author_profile": "https://Stackoverflow.com/users/1496728", "pm_score": 9, "selected": true, "text": "cat foo.c | sed '/^\\s*$/d' | wc -l\n cat foo.pl | sed '/^\\s*#/d;/^\\s*$/d' | wc -l\n" }, { "answer_id": 114844, "author": "Jonathan Hartley", "author_id": 10176, "author_profile": "https://Stackoverflow.com/users/10176", "pm_score": 4, "selected": false, "text": "wc *.py\n grep -v '^\\s*$' *.py | wc\n" }, { "answer_id": 114861, "author": "SpoonMeiser", "author_id": 1577190, "author_profile": "https://Stackoverflow.com/users/1577190", "pm_score": 5, "selected": false, "text": "grep -cve '^\\s*$' <file>\n wc $ grep -cve '^\\s*$' *.hh\n\nconfig.hh:36\nexceptions.hh:48\nlayer.hh:52\nmain.hh:39\n" }, { "answer_id": 114865, "author": "curtisk", "author_id": 17651, "author_profile": "https://Stackoverflow.com/users/17651", "pm_score": 3, "selected": false, "text": "cat 'filename' | grep '[^ ]' | wc -l\n" }, { "answer_id": 114867, "author": "Linor", "author_id": 3197, "author_profile": "https://Stackoverflow.com/users/3197", "pm_score": 1, "selected": false, "text": "grep -c '.' <list of files>\n grep -c '.' `find -type f`\n" }, { "answer_id": 114870, "author": "Gilles", "author_id": 10024, "author_profile": "https://Stackoverflow.com/users/10024", "pm_score": 6, "selected": false, "text": "#!/bin/bash\nfind . -path './pma' -prune -o -path './blog' -prune -o -path './punbb' -prune -o -path './js/3rdparty' -prune -o -print | egrep '\\.php|\\.as|\\.sql|\\.css|\\.js' | grep -v '\\.svn' | xargs cat | sed '/^\\s*$/d' | wc -l\n" }, { "answer_id": 4586338, "author": "Dutch", "author_id": 561486, "author_profile": "https://Stackoverflow.com/users/561486", "pm_score": 0, "selected": false, "text": "grep -v '^\\W*$' `find -type f` | grep -c '.' > /path/to/lineCountFile.txt\n" }, { "answer_id": 5090546, "author": "mahesh", "author_id": 630123, "author_profile": "https://Stackoverflow.com/users/630123", "pm_score": 0, "selected": false, "text": "grep -v ^$ filename wc -l | sed -e 's/ //g' \n" }, { "answer_id": 7054319, "author": "Keith Pinson", "author_id": 834176, "author_profile": "https://Stackoverflow.com/users/834176", "pm_score": 1, "selected": false, "text": "#!/usr/bin/env bash\n(\necho 0;\nfor ext in \"$@\"; do\n for i in $(find . -name \"*$ext\"); do\n sed '/^\\s*$/d' $i | wc -l ## skip blank lines\n #cat $i | wc -l; ## count all lines\n echo +;\n done\ndone\necho p q;\n) | dc;\n ./countlines.sh .py .java .html\n" }, { "answer_id": 8352769, "author": "Andy", "author_id": 504992, "author_profile": "https://Stackoverflow.com/users/504992", "pm_score": 1, "selected": false, "text": "while read line\ndo grep -cve '^\\s*$' \"$line\"\ndone < <(find $1 -name \"*.$2\" -print) | awk '{s+=$1} END {print s}'\n ./scriptname ~/Dropbox/project/src java\n" }, { "answer_id": 10458195, "author": "G1i1ch", "author_id": 1072619, "author_profile": "https://Stackoverflow.com/users/1072619", "pm_score": -1, "selected": false, "text": "wc -l *.c \n" }, { "answer_id": 21773910, "author": "sami", "author_id": 3309383, "author_profile": "https://Stackoverflow.com/users/3309383", "pm_score": 3, "selected": false, "text": "grep -cvE '(^\\s*[/*])|(^\\s*$)' foo\n\n-c = count\n-v = exclude\n-E = extended regex\n'(comment lines) OR (empty lines)'\nwhere\n^ = beginning of the line\n\\s = whitespace\n* = any number of previous characters or none\n[/*] = either / or *\n| = OR\n$ = end of the line\n" }, { "answer_id": 22774449, "author": "curran", "author_id": 2188100, "author_profile": "https://Stackoverflow.com/users/2188100", "pm_score": 2, "selected": false, "text": "# $excluded is a regex for paths to exclude from line counting\nexcluded=\"spec\\|node_modules\\|README\\|lib\\|docs\\|csv\\|XLS\\|json\\|png\"\n\ncountLines(){\n # $total is the total lines of code counted\n total=0\n # -mindepth exclues the current directory (\".\")\n for file in `find . -mindepth 1 -name \"*.*\" |grep -v \"$excluded\"`; do\n # First sed: only count lines of code that are not commented with //\n # Second sed: don't count blank lines\n # $numLines is the lines of code\n numLines=`cat $file | sed '/\\/\\//d' | sed '/^\\s*$/d' | wc -l`\n\n # To exclude only blank lines and count comment lines, uncomment this:\n #numLines=`cat $file | sed '/^\\s*$/d' | wc -l`\n\n total=$(($total + $numLines))\n echo \" \" $numLines $file\n done\n echo \" \" $total in total\n}\n\necho Source code files:\ncountLines\necho Unit tests:\ncd spec\ncountLines\n Source code files:\n 2 ./buildDocs.sh\n 24 ./countLines.sh\n 15 ./css/dashboard.css\n 53 ./data/un_population/provenance/preprocess.js\n 19 ./index.html\n 5 ./server/server.js\n 2 ./server/startServer.sh\n 24 ./SpecRunner.html\n 34 ./src/computeLayout.js\n 60 ./src/configDiff.js\n 18 ./src/dashboardMirror.js\n 37 ./src/dashboardScaffold.js\n 14 ./src/data.js\n 68 ./src/dummyVis.js\n 27 ./src/layout.js\n 28 ./src/links.js\n 5 ./src/main.js\n 52 ./src/processActions.js\n 86 ./src/timeline.js\n 73 ./src/udc.js\n 18 ./src/wire.js\n 664 in total\nUnit tests:\n 230 ./ComputeLayoutSpec.js\n 134 ./ConfigDiffSpec.js\n 134 ./ProcessActionsSpec.js\n 84 ./UDCSpec.js\n 149 ./WireSpec.js\n 731 in total\n" }, { "answer_id": 24034216, "author": "coastline", "author_id": 679724, "author_profile": "https://Stackoverflow.com/users/679724", "pm_score": 4, "selected": false, "text": "cat fileName | grep -v ^$ | wc -l" }, { "answer_id": 41039836, "author": "jean-emmanuel", "author_id": 7267664, "author_profile": "https://Stackoverflow.com/users/7267664", "pm_score": 0, "selected": false, "text": "rgrep . | wc -l\n" }, { "answer_id": 58593331, "author": "Jaydillan", "author_id": 12286498, "author_profile": "https://Stackoverflow.com/users/12286498", "pm_score": 4, "selected": false, "text": "cat file.txt | awk 'NF' | wc -l\n" }, { "answer_id": 64147711, "author": "Son Nguyen", "author_id": 1548073, "author_profile": "https://Stackoverflow.com/users/1548073", "pm_score": 2, "selected": false, "text": "grep -vc ^$ fileName\n -c wc -l" }, { "answer_id": 70705385, "author": "Hamza Awashra", "author_id": 17929460, "author_profile": "https://Stackoverflow.com/users/17929460", "pm_score": 0, "selected": false, "text": "> grep -cve ^$ -cve '^//' *.java\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114814", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10176/" ]
114,819
<p>Consider these classes.</p> <pre><code>class Base { ... }; class Derived : public Base { ... }; </code></pre> <p>this function</p> <pre><code>void BaseFoo( std::vector&lt;Base*&gt;vec ) { ... } </code></pre> <p>And finally my vector</p> <pre><code>std::vector&lt;Derived*&gt;derived; </code></pre> <p>I want to pass <code>derived</code> to function <code>BaseFoo</code>, but the compiler doesn't let me. How do I solve this, without copying the whole vector to a <code>std::vector&lt;Base*&gt;</code>?</p>
[ { "answer_id": 114833, "author": "Matt Price", "author_id": 852, "author_profile": "https://Stackoverflow.com/users/852", "pm_score": 3, "selected": false, "text": "template<typename T>\nvoid BaseFoo( const std::vector<T*>& vec)\n{\n ...\n}\n" }, { "answer_id": 114883, "author": "ChrisN", "author_id": 3853, "author_profile": "https://Stackoverflow.com/users/3853", "pm_score": 6, "selected": true, "text": "vector<Base*> vector<Derived*> vector<Derived*> vector<Base*> Derived vector void BaseFoo( const std::vector<Base*>& vec )\n{\n ...\n}\n #include <boost/ptr_container/ptr_vector.hpp>\nboost::ptr_vector<Base> vec;\n #include <memory>\nstd::vector< std::shared_ptr<Base*> > vec;\n #include <boost/shared_ptr.hpp>\nstd::vector< boost::shared_ptr<Base*> > vec;\n BaseFoo" }, { "answer_id": 114911, "author": "eduffy", "author_id": 7536, "author_profile": "https://Stackoverflow.com/users/7536", "pm_score": 2, "selected": false, "text": "BaseFoo (*reinterpret_cast<std::vector<Base *> *>(&derived));\n" }, { "answer_id": 115052, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 5, "selected": false, "text": "vector<> begin end" }, { "answer_id": 115323, "author": "bk1e", "author_id": 8090, "author_profile": "https://Stackoverflow.com/users/8090", "pm_score": 1, "selected": false, "text": "std::vector class Base {};\nclass Derived1 : public Base {};\nclass Derived2 : public Base {};\n\nvoid pushStuff(std::vector<Base*>& vec) {\n vec.push_back(new Derived2);\n vec.push_back(new Base);\n}\n\n...\nstd::vector<Derived1*> vec;\npushStuff(vec); // Not legal\n// Now vec contains a Derived2 and a Base!\n BaseFoo() reinterpret_cast<std::vector<Base*>&>() std::vector<Derived*>" }, { "answer_id": 115364, "author": "Richard Corden", "author_id": 11698, "author_profile": "https://Stackoverflow.com/users/11698", "pm_score": 2, "selected": false, "text": "// BaseFoo.h\ntemplate<typename T>\nvoid BaseFoo( const std::vector<T*>& vec);\n\n// BaseFoo.cpp\ntemplate<typename T>\nvoid BaseFoo( const std::vector<T*>& vec);\n{\n ...\n}\n\n// Explicit instantiation means no need for definition in the header file.\ntemplate void BaseFoo<Base> ( const std::vector<Base*>& vec );\ntemplate void BaseFoo<Derived> ( const std::vector<Derived*>& vec );\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19863/" ]
114,830
<p>One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?</p>
[ { "answer_id": 114831, "author": "nosklo", "author_id": 17160, "author_profile": "https://Stackoverflow.com/users/17160", "pm_score": 9, "selected": true, "text": ">>> a = {}\n>>> b = ['some', 'list']\n>>> hash(b)\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nTypeError: list objects are unhashable\n>>> a[b] = 'some'\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nTypeError: list objects are unhashable\n" }, { "answer_id": 115379, "author": "Jeremy Cantrell", "author_id": 18866, "author_profile": "https://Stackoverflow.com/users/18866", "pm_score": 3, "selected": false, "text": "a = {}\nb = ['some', 'list']\na[b] = 'some' # this won't work\na[tuple(b)] = 'some' # this will, same as a['some', 'list']\n" }, { "answer_id": 33459086, "author": "Bob Stein", "author_id": 673991, "author_profile": "https://Stackoverflow.com/users/673991", "pm_score": 6, "selected": false, "text": ">>> hash(1.1)\n2040142438\n>>> hash(4504.1)\n2040142438\n >>> d = { 1.1: 'a', 4504.1: 'b' }\n>>> d[1.1]\n'a'\n>>> d[4504.1]\n'b'\n >>> for k,v in d.items(): print(hash(k))\n2040142438\n2040142438\n hash(1.1) == hash(214748749.8) hash(1.1) == 230584300921369601" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11575/" ]
114,847
<p>I'm trying to use the Stream.BeginWrite Async I/O API in .NET for a high-throughput situation with many short messages. As such, a scatter/gather API will reduce the number of context switches (and CPU usage) tremendously. Does this API use the LPBUFFERS Win32 API at all? Is there an alternative API for Scatter/Gather I/O?</p>
[ { "answer_id": 30565480, "author": "Evgeniy Berezovsky", "author_id": 709537, "author_profile": "https://Stackoverflow.com/users/709537", "pm_score": 2, "selected": false, "text": "SocketAsyncEventArgs BufferList Buffer Socket.SendAsync(SocketAsyncEventArgs) WSASend Socket.SendAsync(SocketAsyncEventArgs) WSARecv BufferList NetworkStream.BeginWrite" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13897/" ]
114,851
<p>I have the following code:</p> <pre><code>ListBox.DataSource = DataSet.Tables("table_name").Select("some_criteria = match") ListBox.DisplayMember = "name" </code></pre> <p>The <a href="http://msdn.microsoft.com/en-us/library/system.data.datatable.select(VS.80).aspx" rel="noreferrer"><code>DataTable.Select()</code> method</a> returns an array of <a href="http://msdn.microsoft.com/en-us/library/system.data.datarow(VS.80).aspx" rel="noreferrer"><code>System.Data.DataRow</code></a> objects.</p> <p>No matter what I specify in the <code>ListBox.DisplayMember</code> property, all I see is the ListBox with the correct number of items all showing as <code>System.Data.DataRow</code> instead of the value I want which is in the <code>"name"</code> column!</p> <p>Is it possible to bind to the resulting array from <code>DataTable.Select()</code>, instead of looping through it and adding each one to the <code>ListBox</code>?</p> <p>(I've no problem with looping, but doesn't seem an elegant ending!)</p>
[ { "answer_id": 114887, "author": "Josh", "author_id": 11702, "author_profile": "https://Stackoverflow.com/users/11702", "pm_score": 6, "selected": true, "text": "ListBox.DataSource = new DataView(DataSet.Tables(\"table_name\"), \"some_criteria = match\", \"name\", DataViewRowState.CurrentRows);\nListBox.DisplayMember = \"name\"\n" }, { "answer_id": 115029, "author": "t3rse", "author_id": 64, "author_profile": "https://Stackoverflow.com/users/64", "pm_score": 1, "selected": false, "text": "\n DataSet copy = new DataSet();\n copy.Merge(myDataTable.Select(\"Foo='Bar'\"));\n // copy.Tables[0] has a clone\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5662/" ]
114,859
<p>I use a custom Matrix class in my application, and I frequently add multiple matrices:</p> <pre><code>Matrix result = a + b + c + d; // a, b, c and d are also Matrices </code></pre> <p>However, this creates an intermediate matrix for each addition operation. Since this is simple addition, it is possible to avoid the intermediate objects and create the result by adding the elements of all 4 matrices at once. How can I accomplish this?</p> <p>NOTE: I know I can define multiple functions like <code>Add3Matrices(a, b, c)</code>, <code>Add4Matrices(a, b, c, d)</code>, etc. but I want to keep the elegancy of <code>result = a + b + c + d</code>.</p>
[ { "answer_id": 114905, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 2, "selected": false, "text": "Matrix Add3Matrices(a,b,c) //and so on \n Matrix AddMatrices(Matrix[] matrices)\n" }, { "answer_id": 114952, "author": "Ian G", "author_id": 5764, "author_profile": "https://Stackoverflow.com/users/5764", "pm_score": 4, "selected": true, "text": "public class LazyMatrix\n{\n public static implicit operator Matrix(LazyMatrix l)\n {\n Matrix m = new Matrix();\n foreach (Matrix x in l.Pending)\n {\n for (int i = 0; i < 2; ++i)\n for (int j = 0; j < 2; ++j)\n m.Contents[i, j] += x.Contents[i, j];\n }\n\n return m;\n }\n\n public List<Matrix> Pending = new List<Matrix>();\n}\n\npublic class Matrix\n{\n public int[,] Contents = { { 0, 0 }, { 0, 0 } };\n\n public static LazyMatrix operator+(Matrix a, Matrix b)\n {\n LazyMatrix l = new LazyMatrix();\n l.Pending.Add(a);\n l.Pending.Add(b);\n return l;\n }\n\n public static LazyMatrix operator+(Matrix a, LazyMatrix b)\n {\n b.Pending.Add(a);\n return b;\n }\n}\n\nclass Program\n{\n static void Main(string[] args)\n {\n Matrix a = new Matrix();\n Matrix b = new Matrix();\n Matrix c = new Matrix();\n Matrix d = new Matrix();\n\n a.Contents[0, 0] = 1;\n b.Contents[1, 0] = 4;\n c.Contents[0, 1] = 9;\n d.Contents[1, 1] = 16;\n\n Matrix m = a + b + c + d;\n\n for (int i = 0; i < 2; ++i)\n {\n for (int j = 0; j < 2; ++j)\n {\n System.Console.Write(m.Contents[i, j]);\n System.Console.Write(\" \");\n }\n System.Console.WriteLine();\n }\n\n System.Console.ReadLine();\n }\n}\n" }, { "answer_id": 114964, "author": "Tetha", "author_id": 17663, "author_profile": "https://Stackoverflow.com/users/17663", "pm_score": 2, "selected": false, "text": "result = MatrixAdditionCollector() << a + b + c + d\n" }, { "answer_id": 115005, "author": "Kokuma", "author_id": 12088, "author_profile": "https://Stackoverflow.com/users/12088", "pm_score": 0, "selected": false, "text": "static Matrix AddMatrices(Matrix[] lMatrices) // or List<Matrix> lMatrices\n{\n // Check consistency of matrices\n\n Matrix m = new Matrix(n, p);\n\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n foreach (Maxtrix mat in lMatrices)\n m[i, j] += mat[i, j];\n\n return m;\n}\n result = a + b + c + d result = Matrix.AddMatrices(new Matrix[] { a, b, c, d });" }, { "answer_id": 115007, "author": "Frank Szczerba", "author_id": 8964, "author_profile": "https://Stackoverflow.com/users/8964", "pm_score": 2, "selected": false, "text": "Matrix result = a;\nresult += b;\nresult += c;\nresult += d;\n Matrix result = a;\nresult = result + b;\nresult = result + c;\nresult = result + d;\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/976/" ]
114,872
<p>Given some JS code like that one here:</p> <pre><code> for (var i = 0; i &lt; document.getElementsByName('scale_select').length; i++) { document.getElementsByName('scale_select')[i].onclick = vSetScale; } </code></pre> <p>Would the code be faster if we put the result of getElementsByName into a variable before the loop and then use the variable after that?</p> <p>I am not sure how large the effect is in real life, with the result from <code>getElementsByName</code> typically having &lt; 10 items. I'd like to understand the underlying mechanics anyway.</p> <p>Also, if there's anything else noteworthy about the two options, please tell me.</p>
[ { "answer_id": 114904, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 5, "selected": true, "text": "var scale_select = document.getElementsByName('scale_select');\nfor (var i = 0; i < scale_select.length; i++)\n scale_select[i].onclick = vSetScale;\n" }, { "answer_id": 117253, "author": "ScottKoon", "author_id": 1538, "author_profile": "https://Stackoverflow.com/users/1538", "pm_score": 2, "selected": false, "text": "var scale_select = document.getElementsByName('scale_select');\nfor (var i = 0, al=scale_select.length; i < al; i++)\n scale_select[i].onclick = vSetScale;\n" }, { "answer_id": 120576, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 0, "selected": false, "text": "var scaleSelect = document.getElementsByName('scale_select');\nvar scaleSelectLength = scaleSelect.length;\n\nfor (var i = 0; i < scaleSelectLength; i += 1)\n{\n // scaleSelect[i]\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2077/" ]
114,914
<p>We use <a href="http://hudson-ci.org/" rel="noreferrer">Hudson</a> as a continuous integration system to execute automated builds (nightly and based on CVS polling) of a lot of our projects.</p> <p>Some projects poll CVS every 15 minutes, some others poll every 5 minutes and some poll every hour.</p> <p>Every few weeks we'll get a build that fails with the following output:</p> <pre><code>FATAL: java.io.IOException: Too many open files java.io.IOException: java.io.IOException: Too many open files at java.lang.UNIXProcess.&lt;init&gt;(UNIXProcess.java:148) </code></pre> <p>The next build always worked (with 0 changes) so we always chalked it up to 2 build jobs being run at the same time and happening to have too many files open during the process.</p> <p>This weekend we had a build fail Friday night (automatic nightly build) with the message and every other nightly build also failed. Somehow this triggered Hudson to continuously build every project which failed until the issue was resolved. This resulted in a build every 30 minutes or so of every project until sometime Saturday night when the issue magically disappeared. </p>
[ { "answer_id": 114932, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 0, "selected": false, "text": "ulimit -n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9518/" ]
114,928
<p>I'm firing off a Java application from inside of a C# <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="noreferrer">.NET</a> console application. It works fine for the case where the Java application doesn't care what the "default" directory is, but fails for a Java application that only searches the current directory for support files.</p> <p>Is there a process parameter that can be set to specify the default directory that a process is started in?</p>
[ { "answer_id": 114937, "author": "Dror Helper", "author_id": 11361, "author_profile": "https://Stackoverflow.com/users/11361", "pm_score": 9, "selected": true, "text": "...\nusing System.Diagnostics;\n...\n\nvar startInfo = new ProcessStartInfo();\n\n startInfo.WorkingDirectory = // working directory\n // set additional properties \n\nProcess proc = Process.Start(startInfo);\n" }, { "answer_id": 114947, "author": "Joseph Daigle", "author_id": 507, "author_profile": "https://Stackoverflow.com/users/507", "pm_score": 2, "selected": false, "text": "ProcessStartInfo WorkingDirectory" }, { "answer_id": 115287, "author": "Larry Smithmier", "author_id": 4911, "author_profile": "https://Stackoverflow.com/users/4911", "pm_score": 6, "selected": false, "text": "string _systemRoot = Environment.GetEnvironmentVariable(\"SYSTEMROOT\"); \n ...\nusing System.Diagnostics;\n...\n\nProcessStartInfo _processStartInfo = new ProcessStartInfo();\n _processStartInfo.WorkingDirectory = @\"%ProgramFiles%\";\n _processStartInfo.FileName = @\"Notepad.exe\";\n _processStartInfo.Arguments = \"test.txt\";\n _processStartInfo.CreateNoWindow = true;\nProcess myProcess = Process.Start(_processStartInfo);\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15689/" ]
114,953
<p>I'm writing a photo gallery webapp for a friend's wedding and they want a photo gallery for guests to submit the digital photos they take on the day. </p> <p>After evaluating all the options, I've decided the easiest thing for users would be to let them use a familiar interface (their email) and just have them send in the pictures as attachments.</p> <p>I've created an mailbox but now I need to connect and retrieve these attachments for automated processing for adding to the gallery system. But how? Are there any tutorials or prefab classes you've seen for doing this?</p>
[ { "answer_id": 114973, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 3, "selected": true, "text": "xfilter" }, { "answer_id": 115017, "author": "DreamWerx", "author_id": 15487, "author_profile": "https://Stackoverflow.com/users/15487", "pm_score": 3, "selected": false, "text": "// Open pop mailbox\nif (!$mbox = imap_open (\"{localhost:110/pop3/notls}INBOX\", \"user\", \"tester\")) {\n die ('Cannot connect/check pop mail! Exiting');\n}\n\nif ($hdr = imap_check($mbox)) {\n $msgCount = $hdr->Nmsgs;\n} else {\n echo \"Failed to get mail\";\n exit;\n}\n\n$MN=$msgCount;\n$overview=imap_fetch_overview($mbox,\"1:$MN\",0);\n\nfor ($X = 1; $X <= $MN; $X++) {\n\n $file = imap_fetchbody($mbox, $X, 1);\n\n imap_delete($mbox, $X);\n}\n\nimap_expunge($mbox);\nimap_close($mbox);\n" }, { "answer_id": 115058, "author": "Daniel Papasian", "author_id": 7548, "author_profile": "https://Stackoverflow.com/users/7548", "pm_score": 3, "selected": false, "text": "\nmsgsubmit: \"| /usr/bin/php ~path/to/example.php\", msgsubmit-box\n \nmsgsubmit\n \"| /usr/bin/php ~path/to/example.php\"\n msgsubmit-box\n\n" }, { "answer_id": 367813, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "<?php\n//make sure that submit button name is 'Submit'\nif(isset($_POST['Submit'])){\n\n\n $name = $_POST['visitorname'];\n $email = $_POST['visitoremail'];\n $message = $_POST['visitormessage'];\n\n\n $to=\"youremail@yourdomain.com\";\n\n $subject=\"From \".$name;\n\n\n $from = $email;\n\n // generate a random string to be used as the boundary marker\n $mime_boundary=\"==Multipart_Boundary_x\".md5(mt_rand()).\"x\";\n\n // now we'll build the message headers\n $headers = \"From: $from\\r\\n\" .\n \"MIME-Version: 1.0\\r\\n\" .\n \"Content-Type: multipart/mixed;\\r\\n\" .\n \" boundary=\\\"{$mime_boundary}\\\"\";\n\n // next, we'll build the invisible portion of the message body\n // note that we insert two dashes in front of the MIME boundary\n // when we use it\n $message = \"This is a multi-part message in MIME format.\\n\\n\" .\n \"--{$mime_boundary}\\n\" .\n \"Content-Type: text/plain; charset=\\\"iso-8859-1\\\"\\n\" .\n \"Content-Transfer-Encoding: 7bit\\n\\n\" .\n $message . \"\\n\\n\";\n\n foreach($_FILES as $userfile)\n {\n // store the file information to variables for easier access\n $tmp_name = $userfile['tmp_name'];\n $type = $userfile['type'];\n $name = $userfile['name'];\n $size = $userfile['size'];\n\n\n\n // if the upload succeded, the file will exist\n if (file_exists($tmp_name))\n {\n\n // check to make sure that it is an uploaded file and not a system file\n if(is_uploaded_file($tmp_name))\n {\n\n // open the file for a binary read\n $file = fopen($tmp_name,'rb');\n\n // read the file content into a variable\n $data = fread($file,filesize($tmp_name));\n\n // close the file\n fclose($file);\n\n // now we encode it and split it into acceptable length lines\n $data = chunk_split(base64_encode($data));\n }\n\n // now we'll insert a boundary to indicate we're starting the attachment\n // we have to specify the content type, file name, and disposition as\n // an attachment, then add the file content.\n // NOTE: we don't set another boundary to indicate that the end of the\n // file has been reached here. we only want one boundary between each file\n // we'll add the final one after the loop finishes.\n $message .= \"--{$mime_boundary}\\n\" .\n \"Content-Type: {$type};\\n\" .\n \" name=\\\"{$name}\\\"\\n\" .\n \"Content-Disposition: attachment;\\n\" .\n \" filename=\\\"{$fileatt_name}\\\"\\n\" .\n \"Content-Transfer-Encoding: base64\\n\\n\" .\n $data . \"\\n\\n\";\n }\n }\n\n\n$ok = @mail($to, $subject, $message , $headers);\nif ($ok) {\nif (($_FILES[\"file\"][\"type\"] == \"image/gif\")\n|| ($_FILES[\"file\"][\"type\"] == \"image/jpeg\")\n|| ($_FILES[\"file\"][\"type\"] == \"image/pjpeg\")\n&& ($_FILES[\"file\"][\"size\"] < 20000))\n {\n if ($_FILES[\"file\"][\"error\"] > 0)\n {\n echo \"Return Code: \" . $_FILES[\"file\"][\"error\"] . \"<br />\";\n }\n else\n {\n\nif (file_exists(\"upload/\" . $_FILES[\"file\"][\"name\"]))\n {\n echo $_FILES[\"file\"][\"name\"] . \" already exists. \";\n }\n else\n {\n move_uploaded_file($_FILES[\"file\"][\"tmp_name\"],\n \"upload/\" . $_FILES[\"file\"][\"name\"]);\n\n }\n }\n }\nelse\n {\n\n }\necho \"<span class='red'>E-mail has been sent successfully from $mail_name to $to</span>\"; }\nelse{\necho \"<span class='red'>Failed to send the E-mail from $from to $to</span>\";\n}\n}\n?>\n" }, { "answer_id": 12764157, "author": "paulo lellis", "author_id": 1725820, "author_profile": "https://Stackoverflow.com/users/1725820", "pm_score": 0, "selected": false, "text": "Majordomo" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12870/" ]
114,983
<p>Given:</p> <pre><code>DateTime.UtcNow </code></pre> <p>How do I get a string which represents the same value in an <a href="http://en.wikipedia.org/wiki/ISO_8601" rel="noreferrer">ISO 8601</a>-compliant format?</p> <p>Note that ISO 8601 defines a number of similar formats. The specific format I am looking for is:</p> <pre><code>yyyy-MM-ddTHH:mm:ssZ </code></pre>
[ { "answer_id": 114997, "author": "Iain", "author_id": 20457, "author_profile": "https://Stackoverflow.com/users/20457", "pm_score": 7, "selected": false, "text": "DateTime.UtcNow.ToString(\"s\")\n UtcNow string.Concat(DateTime.UtcNow.ToString(\"s\"), \"Z\")\n" }, { "answer_id": 115002, "author": "Wayne", "author_id": 8236, "author_profile": "https://Stackoverflow.com/users/8236", "pm_score": 10, "selected": false, "text": "DateTime.UtcNow.ToString(\"yyyy-MM-ddTHH\\\\:mm\\\\:ss.fffffffzzz\", CultureInfo.InvariantCulture);\n DateTime.UtcNow.ToString(\"o\", CultureInfo.InvariantCulture);\n DateTime.UtcNow.ToString(\"yyyy-MM-ddTHH:mm:ssZ\", CultureInfo.InvariantCulture)\n" }, { "answer_id": 115034, "author": "Simon Wilson", "author_id": 12875, "author_profile": "https://Stackoverflow.com/users/12875", "pm_score": 9, "selected": false, "text": "DateTime.UtcNow.ToString(\"s\", System.Globalization.CultureInfo.InvariantCulture) Z \"o\" \"s\"" }, { "answer_id": 322305, "author": "Oppositional", "author_id": 2029, "author_profile": "https://Stackoverflow.com/users/2029", "pm_score": 3, "selected": false, "text": "DateTime.UtcNow.ToString(\"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'\", DateTimeFormatInfo.InvariantInfo)\n" }, { "answer_id": 6216560, "author": "Sumrak", "author_id": 19124, "author_profile": "https://Stackoverflow.com/users/19124", "pm_score": 4, "selected": false, "text": "XmlConvert XmlConvert.ToString(DateTime.UtcNow, XmlDateTimeSerializationMode.RoundtripKind);\n" }, { "answer_id": 12385861, "author": "Amal", "author_id": 314373, "author_profile": "https://Stackoverflow.com/users/314373", "pm_score": 3, "selected": false, "text": "\"s\" \"yyyy'-'MM'-'dd'T'HH':'mm':'ss\"" }, { "answer_id": 12467789, "author": "Don", "author_id": 1669344, "author_profile": "https://Stackoverflow.com/users/1669344", "pm_score": 6, "selected": false, "text": "private void TimeFormats()\n{\n DateTime localTime = DateTime.Now;\n DateTime utcTime = DateTime.UtcNow;\n DateTimeOffset localTimeAndOffset = new DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset(localTime));\n\n //UTC\n string strUtcTime_o = utcTime.ToString(\"o\");\n string strUtcTime_s = utcTime.ToString(\"s\");\n string strUtcTime_custom = utcTime.ToString(\"yyyy-MM-ddTHH:mm:ssK\");\n\n //Local\n string strLocalTimeAndOffset_o = localTimeAndOffset.ToString(\"o\");\n string strLocalTimeAndOffset_s = localTimeAndOffset.ToString(\"s\");\n string strLocalTimeAndOffset_custom = utcTime.ToString(\"yyyy-MM-ddTHH:mm:ssK\");\n\n //Output\n Response.Write(\"<br/>UTC<br/>\");\n Response.Write(\"strUtcTime_o: \" + strUtcTime_o + \"<br/>\");\n Response.Write(\"strUtcTime_s: \" + strUtcTime_s + \"<br/>\");\n Response.Write(\"strUtcTime_custom: \" + strUtcTime_custom + \"<br/>\");\n\n Response.Write(\"<br/>Local Time<br/>\");\n Response.Write(\"strLocalTimeAndOffset_o: \" + strLocalTimeAndOffset_o + \"<br/>\");\n Response.Write(\"strLocalTimeAndOffset_s: \" + strLocalTimeAndOffset_s + \"<br/>\");\n Response.Write(\"strLocalTimeAndOffset_custom: \" + strLocalTimeAndOffset_custom + \"<br/>\");\n\n}\n UTC\n strUtcTime_o: 2012-09-17T22:02:51.4021600Z\n strUtcTime_s: 2012-09-17T22:02:51\n strUtcTime_custom: 2012-09-17T22:02:51Z\n\nLocal Time\n strLocalTimeAndOffset_o: 2012-09-17T15:02:51.4021600-07:00\n strLocalTimeAndOffset_s: 2012-09-17T15:02:51\n strLocalTimeAndOffset_custom: 2012-09-17T22:02:51Z\n" }, { "answer_id": 15656407, "author": "Simon Logic", "author_id": 682256, "author_profile": "https://Stackoverflow.com/users/682256", "pm_score": 2, "selected": false, "text": "using Microsoft.SharePoint;\nusing Microsoft.SharePoint.Utilities;\n...\nstring strISODate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now)\n" }, { "answer_id": 19345594, "author": "Henrik", "author_id": 63621, "author_profile": "https://Stackoverflow.com/users/63621", "pm_score": 6, "selected": false, "text": "System.DateTime.UtcNow.ToString(\"o\")\n val it : string = \"2013-10-13T13:03:50.2950037Z\"\n" }, { "answer_id": 25893406, "author": "Oaxas", "author_id": 1448133, "author_profile": "https://Stackoverflow.com/users/1448133", "pm_score": 5, "selected": false, "text": "Dim tmpDate As DateTime = New DateTime(Now.Ticks, DateTimeKind.Utc)\nDim res as String = tmpDate.toString(\"o\") '2009-06-15T13:45:30.0000000Z\n 2009-06-15T13:45:30.0000000-07:00\n 2009-06-15T13:45:30.0000000Z\n 2009-06-15T13:45:30.0000000\n '2009-06-15T13:45:30.0000000-07:00\nDim strTmp1 As String = New DateTime(Now.Ticks, DateTimeKind.Local).ToString(\"o\")\n\n'2009-06-15T13:45:30.0000000Z\nDim strTmp2 As String = New DateTime(Now.Ticks, DateTimeKind.Utc).ToString(\"o\")\n\n'2009-06-15T13:45:30.0000000\nDim strTmp3 As String = New DateTime(Now.Ticks, DateTimeKind.Unspecified).ToString(\"o\")\n" }, { "answer_id": 27321188, "author": "Justin Turner", "author_id": 604624, "author_profile": "https://Stackoverflow.com/users/604624", "pm_score": 4, "selected": false, "text": "System.DateTime.Now.ToString(\"yyyy-MM-ddTHH:mm:ssK\");\n// or\nSystem.DateTime.Now.ToUniversalTime().ToString(\"yyyy-MM-ddTHH:mm:ssK\");\n" }, { "answer_id": 31250678, "author": "Alex Nolasco", "author_id": 65694, "author_profile": "https://Stackoverflow.com/users/65694", "pm_score": 5, "selected": false, "text": "var date1 = new DateTime(2008, 3, 1, 7, 0, 0);\nConsole.WriteLine(date1.ToString(\"O\"));\nConsole.WriteLine(date1.ToString(\"s\", System.Globalization.CultureInfo.InvariantCulture));\n 2008-03-01T07:00:00.0000000\n2008-03-01T07:00:00\n" }, { "answer_id": 43793679, "author": "Roman Pokrovskij", "author_id": 506147, "author_profile": "https://Stackoverflow.com/users/506147", "pm_score": 3, "selected": false, "text": "_Verify BenchmarkDotNet=v0.10.5, OS=Windows 10.0.14393\nProcessor=Intel Core i5-2500K CPU 3.30GHz (Sandy Bridge), ProcessorCount=4\nFrequency=3233539 Hz, Resolution=309.2587 ns, Timer=TSC\n [Host] : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1637.0\n Clr : Clr 4.0.30319.42000, 64bit RyuJIT-v4.6.1637.0\n Core : .NET Core 4.6.25009.03, 64bit RyuJIT\n\n\n Method | Job | Runtime | Mean | Error | StdDev | Median | Min | Max | Rank | Gen 0 | Allocated |\n--------------------- |----- |-------- |-----------:|----------:|----------:|-----------:|-----------:|-----------:|-----:|-------:|----------:|\n CustomDev1 | Clr | Clr | 1,089.0 ns | 22.179 ns | 20.746 ns | 1,079.9 ns | 1,068.9 ns | 1,133.2 ns | 8 | 0.1086 | 424 B |\n CustomDev2 | Clr | Clr | 1,032.3 ns | 19.897 ns | 21.289 ns | 1,024.7 ns | 1,000.3 ns | 1,072.0 ns | 7 | 0.1165 | 424 B |\n CustomDev2WithMS | Clr | Clr | 1,168.2 ns | 16.543 ns | 15.474 ns | 1,168.5 ns | 1,149.3 ns | 1,189.2 ns | 10 | 0.1625 | 592 B |\n FormatO | Clr | Clr | 1,563.7 ns | 31.244 ns | 54.721 ns | 1,532.5 ns | 1,497.8 ns | 1,703.5 ns | 14 | 0.2897 | 976 B |\n FormatS | Clr | Clr | 1,243.5 ns | 24.615 ns | 31.130 ns | 1,229.3 ns | 1,200.6 ns | 1,324.2 ns | 13 | 0.2865 | 984 B |\n FormatS_Verify | Clr | Clr | 1,217.6 ns | 11.486 ns | 10.744 ns | 1,216.2 ns | 1,205.5 ns | 1,244.3 ns | 12 | 0.2885 | 984 B |\n CustomFormatK | Clr | Clr | 912.2 ns | 17.915 ns | 18.398 ns | 916.6 ns | 878.3 ns | 934.1 ns | 4 | 0.0629 | 240 B |\n CustomFormatK_Verify | Clr | Clr | 894.0 ns | 3.877 ns | 3.626 ns | 893.8 ns | 885.1 ns | 900.0 ns | 3 | 0.0636 | 240 B |\n CustomDev1 | Core | Core | 989.1 ns | 12.550 ns | 11.739 ns | 983.8 ns | 976.8 ns | 1,015.5 ns | 6 | 0.1101 | 423 B |\n CustomDev2 | Core | Core | 964.3 ns | 18.826 ns | 23.809 ns | 954.1 ns | 935.5 ns | 1,015.6 ns | 5 | 0.1267 | 423 B |\n CustomDev2WithMS | Core | Core | 1,136.0 ns | 21.914 ns | 27.714 ns | 1,138.1 ns | 1,099.9 ns | 1,200.2 ns | 9 | 0.1752 | 590 B |\n FormatO | Core | Core | 1,201.5 ns | 16.262 ns | 15.211 ns | 1,202.3 ns | 1,178.2 ns | 1,225.5 ns | 11 | 0.0656 | 271 B |\n FormatS | Core | Core | 993.5 ns | 19.272 ns | 24.372 ns | 999.4 ns | 954.2 ns | 1,029.5 ns | 6 | 0.0633 | 279 B |\n FormatS_Verify | Core | Core | 1,003.1 ns | 17.577 ns | 16.442 ns | 1,009.2 ns | 976.1 ns | 1,024.3 ns | 6 | 0.0674 | 279 B |\n CustomFormatK | Core | Core | 878.2 ns | 17.017 ns | 20.898 ns | 877.7 ns | 851.4 ns | 928.1 ns | 2 | 0.0555 | 215 B |\n CustomFormatK_Verify | Core | Core | 863.6 ns | 3.968 ns | 3.712 ns | 863.0 ns | 858.6 ns | 870.8 ns | 1 | 0.0550 | 215 B |\n public class BenchmarkDateTimeFormat\n {\n public static DateTime dateTime = DateTime.Now;\n\n [Benchmark]\n public string CustomDev1()\n {\n var d = dateTime.ToUniversalTime();\n var sb = new StringBuilder(20);\n\n sb.Append(d.Year).Append(\"-\");\n if (d.Month <= 9)\n sb.Append(\"0\");\n sb.Append(d.Month).Append(\"-\");\n if (d.Day <= 9)\n sb.Append(\"0\");\n sb.Append(d.Day).Append(\"T\");\n if (d.Hour <= 9)\n sb.Append(\"0\");\n sb.Append(d.Hour).Append(\":\");\n if (d.Minute <= 9)\n sb.Append(\"0\");\n sb.Append(d.Minute).Append(\":\");\n if (d.Second <= 9)\n sb.Append(\"0\");\n sb.Append(d.Second).Append(\"Z\");\n var text = sb.ToString();\n return text;\n }\n\n [Benchmark]\n public string CustomDev2()\n {\n var u = dateTime.ToUniversalTime();\n var sb = new StringBuilder(20);\n var y = u.Year;\n var d = u.Day;\n var M = u.Month;\n var h = u.Hour;\n var m = u.Minute;\n var s = u.Second;\n sb.Append(y).Append(\"-\");\n if (M <= 9)\n sb.Append(\"0\");\n sb.Append(M).Append(\"-\");\n if (d <= 9)\n sb.Append(\"0\");\n sb.Append(d).Append(\"T\");\n if (h <= 9)\n sb.Append(\"0\");\n sb.Append(h).Append(\":\");\n if (m <= 9)\n sb.Append(\"0\");\n sb.Append(m).Append(\":\");\n if (s <= 9)\n sb.Append(\"0\");\n sb.Append(s).Append(\"Z\");\n var text = sb.ToString();\n return text;\n }\n\n [Benchmark]\n public string CustomDev2WithMS()\n {\n var u = dateTime.ToUniversalTime();\n var sb = new StringBuilder(23);\n var y = u.Year;\n var d = u.Day;\n var M = u.Month;\n var h = u.Hour;\n var m = u.Minute;\n var s = u.Second;\n var ms = u.Millisecond;\n sb.Append(y).Append(\"-\");\n if (M <= 9)\n sb.Append(\"0\");\n sb.Append(M).Append(\"-\");\n if (d <= 9)\n sb.Append(\"0\");\n sb.Append(d).Append(\"T\");\n if (h <= 9)\n sb.Append(\"0\");\n sb.Append(h).Append(\":\");\n if (m <= 9)\n sb.Append(\"0\");\n sb.Append(m).Append(\":\");\n if (s <= 9)\n sb.Append(\"0\");\n sb.Append(s).Append(\".\");\n sb.Append(ms).Append(\"Z\");\n var text = sb.ToString();\n return text;\n }\n [Benchmark]\n public string FormatO()\n {\n var text = dateTime.ToUniversalTime().ToString(\"o\");\n return text;\n }\n [Benchmark]\n public string FormatS()\n {\n var text = string.Concat(dateTime.ToUniversalTime().ToString(\"s\"),\"Z\");\n return text;\n }\n\n [Benchmark]\n public string FormatS_Verify()\n {\n var text = string.Concat(dateTime.ToUniversalTime().ToString(\"s\"), \"Z\");\n return text;\n }\n\n [Benchmark]\n public string CustomFormatK()\n {\n var text = dateTime.ToUniversalTime().ToString(\"yyyy-MM-ddTHH:mm:ssK\");\n return text;\n }\n\n [Benchmark]\n public string CustomFormatK_Verify()\n {\n var text = dateTime.ToUniversalTime().ToString(\"yyyy-MM-ddTHH:mm:ssK\");\n return text;\n }\n }\n" }, { "answer_id": 50988941, "author": "Nick Gallimore", "author_id": 3097454, "author_profile": "https://Stackoverflow.com/users/3097454", "pm_score": 2, "selected": false, "text": "public static string FormatDateTime(DateTime dateTime)\n{\n return dateTime.ToString(\"s\", System.Globalization.CultureInfo.InvariantCulture);\n}\n" }, { "answer_id": 52103826, "author": "Pablo Salcedo", "author_id": 7641848, "author_profile": "https://Stackoverflow.com/users/7641848", "pm_score": 4, "selected": false, "text": "DateTime.Now.ToString(\"yyyy-MM-dd'T'HH:mm:ss zzz\");\n\nDateTime.Now.ToString(\"O\");\n" }, { "answer_id": 56173223, "author": "rburte", "author_id": 653058, "author_profile": "https://Stackoverflow.com/users/653058", "pm_score": 5, "selected": false, "text": "System.DateTime.UtcNow.ToString(\"u\").Replace(' ','T')\n # Using PowerShell Core to demo\n\n# Lowercase \"u\" format\n[System.DateTime]::UtcNow.ToString(\"u\")\n> 2020-02-06 01:00:32Z\n\n# Lowercase \"u\" format with replacement\n[System.DateTime]::UtcNow.ToString(\"u\").Replace(' ','T')\n> 2020-02-06T01:00:32Z\n\n [Benchmark]\npublic string ReplaceU()\n{\n var text = dateTime.ToUniversalTime().ToString(\"u\").Replace(' ', 'T');\n return text;\n}\n // * Summary *\n\nBenchmarkDotNet=v0.11.5, OS=Windows 10.0.19002\nIntel Xeon CPU E3-1245 v3 3.40GHz, 1 CPU, 8 logical and 4 physical cores\n.NET Core SDK=3.0.100\n [Host] : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT\n DefaultJob : .NET Core 3.0.0 (CoreCLR 4.700.19.46205, CoreFX 4.700.19.46214), 64bit RyuJIT\n\n\n| Method | Mean | Error | StdDev |\n|--------------------- |---------:|----------:|----------:|\n| CustomDev1 | 562.4 ns | 11.135 ns | 10.936 ns |\n| CustomDev2 | 525.3 ns | 3.322 ns | 3.107 ns |\n| CustomDev2WithMS | 609.9 ns | 9.427 ns | 8.356 ns |\n| FormatO | 356.6 ns | 6.008 ns | 5.620 ns |\n| FormatS | 589.3 ns | 7.012 ns | 6.216 ns |\n| FormatS_Verify | 599.8 ns | 12.054 ns | 11.275 ns |\n| CustomFormatK | 549.3 ns | 4.911 ns | 4.594 ns |\n| CustomFormatK_Verify | 539.9 ns | 2.917 ns | 2.436 ns |\n| ReplaceU | 615.5 ns | 12.313 ns | 11.517 ns |\n\n// * Hints *\nOutliers\n BenchmarkDateTimeFormat.CustomDev2WithMS: Default -> 1 outlier was removed (668.16 ns)\n BenchmarkDateTimeFormat.FormatS: Default -> 1 outlier was removed (621.28 ns)\n BenchmarkDateTimeFormat.CustomFormatK: Default -> 1 outlier was detected (542.55 ns)\n BenchmarkDateTimeFormat.CustomFormatK_Verify: Default -> 2 outliers were removed (557.07 ns, 560.95 ns)\n\n// * Legends *\n Mean : Arithmetic mean of all measurements\n Error : Half of 99.9% confidence interval\n StdDev : Standard deviation of all measurements\n 1 ns : 1 Nanosecond (0.000000001 sec)\n\n// ***** BenchmarkRunner: End *****\n\n" }, { "answer_id": 56216091, "author": "blackforest-tom", "author_id": 5274931, "author_profile": "https://Stackoverflow.com/users/5274931", "pm_score": 2, "selected": false, "text": "JsonConvert.SerializeObject(DateTime.UtcNow)\n" }, { "answer_id": 57825706, "author": "Vlad DX", "author_id": 3503521, "author_profile": "https://Stackoverflow.com/users/3503521", "pm_score": 1, "selected": false, "text": "DateTime ZonedDateTime var instant1 = Instant.FromUtc(2020, 06, 29, 10, 15, 22);\n\nvar utcZonedDateTime = new ZonedDateTime(instant1, DateTimeZone.Utc);\nutcZonedDateTime.ToString(\"yyyy-MM-ddTHH:mm:ss'Z'\", CultureInfo.InvariantCulture);\n// 2020-06-29T10:15:22Z\n\n\nvar instant2 = Instant.FromDateTimeUtc(new DateTime(2020, 06, 29, 10, 15, 22, DateTimeKind.Utc));\n\nvar amsterdamZonedDateTime = new ZonedDateTime(instant2, DateTimeZoneProviders.Tzdb[\"Europe/Amsterdam\"]);\namsterdamZonedDateTime.ToString(\"yyyy-MM-ddTHH:mm:ss'Z'\", CultureInfo.InvariantCulture);\n// 2020-06-29T12:15:22Z\n\n NodaTime NodaTime Newtonsoft.Json NodaTime.Serialization.JsonNet services\n .AddMvc()\n .AddJsonOptions(options =>\n {\n var settings=options.SerializerSettings;\n settings.DateParseHandling = DateParseHandling.None;\n settings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);\n });\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20457/" ]
114,996
<p>How can we connect a <code>PHP</code> script to <code>MS Access (.mdb)</code> file?</p> <p>I tried by including following <code>PHP</code> code:</p> <pre><code>$db_path = $_SERVER['DOCUMENT_ROOT'] . '\WebUpdate\\' . $file_name . '.mdb'; $cfg_dsn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" . $db_path; $odbcconnect = odbc_connect($cfg_dsn, '', ''); </code></pre> <p>But it failed and I received following error message:</p> <pre><code> Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\web\WebUpdate\index.php on line 41 </code></pre>
[ { "answer_id": 115009, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 4, "selected": true, "text": "<?php\n$db_conn = new COM(\"ADODB.Connection\");\n$connstr = \"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\". realpath(\"./Northwind.mdb\").\";\";\n$db_conn->open($connstr);\n$rS = $db_conn->execute(\"SELECT * FROM Employees\");\n$f1 = $rS->Fields(0);\n$f2 = $rS->Fields(1);\nwhile (!$rS->EOF)\n{\n print $f1->value.\" \".$f2->value.\"<br />\\n\";\n $rS->MoveNext();\n}\n$rS->Close();\n$db_conn->Close();\n?> \n" }, { "answer_id": 115032, "author": "Pop Catalin", "author_id": 4685, "author_profile": "https://Stackoverflow.com/users/4685", "pm_score": 0, "selected": false, "text": "$db_path = $_SERVER['DOCUMENT_ROOT'] . '\\WebUpdate\\\\' . $file_name . '.mdb';\n" }, { "answer_id": 590768, "author": "OldBuildingAndLoan", "author_id": 70870, "author_profile": "https://Stackoverflow.com/users/70870", "pm_score": 0, "selected": false, "text": "try {\n $conn = @odbc_connect(\"DSNName\", \"\", \"\", \"SQL_CUR_USE_ODBC\");\n // un and pw parameters are passed as empty strings since the DSN \n // has knowledge of the password already.\n // 4th parameter is optional\n\n $exec = @odbc_exec($conn, $insert) or die (\"exec error\");\n echo \"success!\";\n}\ncatch (Exception $e) {\n echo $e->getMessage();\n} // end try catch\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/114996", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6561/" ]
115,008
<p>How to print line numbers to the log. Say when outputting some information to the log, I also want to print the line number where that output is in the source code. As we can see in the stack trace, it displays the line number where the exception has occurred. Stack trace is available on the exception object.</p> <p>Other alternative could be like manually including the line number when printing to the log. Is there any other way?</p>
[ { "answer_id": 115027, "author": "Simon Buchan", "author_id": 20135, "author_profile": "https://Stackoverflow.com/users/20135", "pm_score": 7, "selected": false, "text": "/** Get the current line number.\n * @return int - Current line number.\n */\npublic static int getLineNumber() {\n return Thread.currentThread().getStackTrace()[2].getLineNumber();\n}\n" }, { "answer_id": 115057, "author": "Ron Tuffin", "author_id": 939, "author_profile": "https://Stackoverflow.com/users/939", "pm_score": 3, "selected": false, "text": "Thread.currentThread().getStackTrace()[2].getLineNumber()\n" }, { "answer_id": 115062, "author": "James A Wilson", "author_id": 13892, "author_profile": "https://Stackoverflow.com/users/13892", "pm_score": 5, "selected": false, "text": "logger.debug(\"a really descriptive message\") System.out.println(\"a really descriptive message\")" }, { "answer_id": 115144, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 0, "selected": false, "text": "/**\n * Returns the first \"[class#method(line)]: \" of the first class not equal to \"StackTraceUtils\" and aclass. <br />\n * Allows to get past a certain class.\n * @param aclass class to get pass in the stack trace. If null, only try to get past StackTraceUtils. \n * @return \"[class#method(line)]: \" (never empty, because if aclass is not found, returns first class past StackTraceUtils)\n */\npublic static String getClassMethodLine(final Class aclass) {\n final StackTraceElement st = getCallingStackTraceElement(aclass);\n final String amsg = \"[\" + st.getClassName() + \"#\" + st.getMethodName() + \"(\" + st.getLineNumber()\n +\")] <\" + Thread.currentThread().getName() + \">: \";\n return amsg;\n}\n /**\n * Returns the first stack trace element of the first class not equal to \"StackTraceUtils\" or \"LogUtils\" and aClass. <br />\n * Stored in array of the callstack. <br />\n * Allows to get past a certain class.\n * @param aclass class to get pass in the stack trace. If null, only try to get past StackTraceUtils. \n * @return stackTraceElement (never null, because if aClass is not found, returns first class past StackTraceUtils)\n * @throws AssertionFailedException if resulting statckTrace is null (RuntimeException)\n */\n public static StackTraceElement getCallingStackTraceElement(final Class aclass) {\n final Throwable t = new Throwable();\n final StackTraceElement[] ste = t.getStackTrace();\n int index = 1;\n final int limit = ste.length;\n StackTraceElement st = ste[index];\n String className = st.getClassName();\n boolean aclassfound = false;\n if(aclass == null) {\n aclassfound = true;\n }\n StackTraceElement resst = null;\n while(index < limit) {\n if(shouldExamine(className, aclass) == true) {\n if(resst == null) {\n resst = st;\n }\n if(aclassfound == true) {\n final StackTraceElement ast = onClassfound(aclass, className, st);\n if(ast != null) {\n resst = ast;\n break;\n }\n }\n else\n {\n if(aclass != null && aclass.getName().equals(className) == true) {\n aclassfound = true;\n }\n }\n }\n index = index + 1;\n st = ste[index];\n className = st.getClassName();\n }\n if(isNull(resst)) {\n throw new AssertionFailedException(StackTraceUtils.getClassMethodLine() + \" null argument:\" + \"stack trace should null\"); //$NON-NLS-1$\n }\n return resst;\n }\n\n static private boolean shouldExamine(String className, Class aclass) {\n final boolean res = StackTraceUtils.class.getName().equals(className) == false && (className.endsWith(LOG_UTILS\n ) == false || (aclass !=null && aclass.getName().endsWith(LOG_UTILS)));\n return res;\n }\n\n static private StackTraceElement onClassfound(Class aclass, String className, StackTraceElement st) {\n StackTraceElement resst = null;\n if(aclass != null && aclass.getName().equals(className) == false)\n {\n resst = st;\n }\n if(aclass == null)\n {\n resst = st;\n }\n return resst;\n }\n" }, { "answer_id": 4332163, "author": "Michael Baltaks", "author_id": 23312, "author_profile": "https://Stackoverflow.com/users/23312", "pm_score": 6, "selected": false, "text": "import android.util.Log; \npublic class DebugLog {\n public final static boolean DEBUG = true; \n public static void log(String message) {\n if (DEBUG) {\n String fullClassName = Thread.currentThread().getStackTrace()[2].getClassName();\n String className = fullClassName.substring(fullClassName.lastIndexOf(\".\") + 1);\n String methodName = Thread.currentThread().getStackTrace()[2].getMethodName();\n int lineNumber = Thread.currentThread().getStackTrace()[2].getLineNumber();\n\n Log.d(className + \".\" + methodName + \"():\" + lineNumber, message);\n }\n }\n}\n" }, { "answer_id": 5916374, "author": "Juan", "author_id": 261350, "author_profile": "https://Stackoverflow.com/users/261350", "pm_score": 5, "selected": false, "text": "System.out.println(\"I'm in line #\" + \n new Exception().getStackTrace()[0].getLineNumber());\n StackTraceElement l = new Exception().getStackTrace()[0];\nSystem.out.println(\n l.getClassName()+\"/\"+l.getMethodName()+\":\"+l.getLineNumber());\n com.example.mytest.MyClass/myMethod:103\n" }, { "answer_id": 10992416, "author": "Bobs", "author_id": 779408, "author_profile": "https://Stackoverflow.com/users/779408", "pm_score": 0, "selected": false, "text": "public static int getLineNumber()\n{\n int lineNumber = 0;\n StackTraceElement[] stackTraceElement = Thread.currentThread()\n .getStackTrace();\n int currentIndex = -1;\n for (int i = 0; i < stackTraceElement.length; i++) {\n if (stackTraceElement[i].getMethodName().compareTo(\"getLineNumber\") == 0)\n {\n currentIndex = i + 1;\n break;\n }\n }\n\n lineNumber = stackTraceElement[currentIndex].getLineNumber();\n\n return lineNumber;\n}\n" }, { "answer_id": 14317140, "author": "Raymond", "author_id": 1977074, "author_profile": "https://Stackoverflow.com/users/1977074", "pm_score": 0, "selected": false, "text": "private static final int CLIENT_CODE_STACK_INDEX;\n\nstatic {\n // Finds out the index of \"this code\" in the returned stack Trace - funny but it differs in JDK 1.5 and 1.6\n int i = 0;\n for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {\n i++;\n if (ste.getClassName().equals(Trace.class.getName())) {\n break;\n }\n }\n CLIENT_CODE_STACK_INDEX = i;\n}\n\nprivate String methodName() {\n StackTraceElement ste=Thread.currentThread().getStackTrace()[CLIENT_CODE_STACK_INDEX+1];\n return ste.getMethodName()+\":\"+ste.getLineNumber();\n}\n" }, { "answer_id": 16163512, "author": "EmiDemi", "author_id": 1286980, "author_profile": "https://Stackoverflow.com/users/1286980", "pm_score": -1, "selected": false, "text": "String str = \"select os.name from os where os.idos=\"+nameid; try {\n PreparedStatement stmt = conn.prepareStatement(str);\n ResultSet rs = stmt.executeQuery();\n if (rs.next()) {\n a = rs.getString(\"os.n1ame\");//<<<----Here is the ERROR \n }\n stmt.close();\n } catch (SQLException e) {\n System.out.println(\"error line : \" + e.getStackTrace()[2].getLineNumber()); \n return a;\n }\n" }, { "answer_id": 16839643, "author": "Mark", "author_id": 2344770, "author_profile": "https://Stackoverflow.com/users/2344770", "pm_score": 0, "selected": false, "text": "Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {\n public void uncaughtException(Thread t, Throwable e) { \n if(fShowUncaughtMessage(e,t)) \n System.exit(1);\n }\n });\n" }, { "answer_id": 23035405, "author": "Sydwell", "author_id": 344050, "author_profile": "https://Stackoverflow.com/users/344050", "pm_score": 3, "selected": false, "text": " Log.d(TAG, \"Where did i put this debug code again? \" + Utils.lineOut());\n public static String lineOut() {\n int level = 3;\n StackTraceElement[] traces;\n traces = Thread.currentThread().getStackTrace();\n return (\" at \" + traces[level] + \" \" );\n}\n" }, { "answer_id": 45583330, "author": "Rahul", "author_id": 3774035, "author_profile": "https://Stackoverflow.com/users/3774035", "pm_score": 0, "selected": false, "text": "public class Utils {\n/*\n * debug variable enables/disables all log messages to logcat\n * Useful to disable prior to app store submission\n */\npublic static final boolean debug = true;\n\n/*\n * l method used to log passed string and returns the\n * calling file as the tag, method and line number prior\n * to the string's message\n */\npublic static void l(String s) {\n if (debug) {\n String[] msg = trace(Thread.currentThread().getStackTrace(), 3);\n Log.i(msg[0], msg[1] + s);\n } else {\n return;\n }\n}\n\n/*\n * l (tag, string)\n * used to pass logging messages as normal but can be disabled\n * when debug == false\n */\npublic static void l(String t, String s) {\n if (debug) {\n Log.i(t, s);\n } else {\n return;\n }\n}\n\n/*\n * trace\n * Gathers the calling file, method, and line from the stack\n * returns a string array with element 0 as file name and \n * element 1 as method[line]\n */\npublic static String[] trace(final StackTraceElement e[], final int level) {\n if (e != null && e.length >= level) {\n final StackTraceElement s = e[level];\n if (s != null) { return new String[] {\n e[level].getFileName(), e[level].getMethodName() + \"[\" + e[level].getLineNumber() + \"]\"\n };}\n }\n return null;\n}\n}\n" }, { "answer_id": 55423753, "author": "Loyea", "author_id": 4172311, "author_profile": "https://Stackoverflow.com/users/4172311", "pm_score": 0, "selected": false, "text": "stackLevel stackLevel java.lang.Thread.getStackTrace(Thread.java:1536) public static String getCodeLocationInfo(int stackLevel) {\n StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();\n if (stackLevel < 0 || stackLevel >= stackTraceElements.length) {\n return \"Stack Level Out Of StackTrace Bounds\";\n }\n StackTraceElement stackTraceElement = stackTraceElements[stackLevel];\n String fullClassName = stackTraceElement.getClassName();\n String methodName = stackTraceElement.getMethodName();\n String fileName = stackTraceElement.getFileName();\n int lineNumber = stackTraceElement.getLineNumber();\n\n return String.format(\"%s.%s(%s:%s)\", fullClassName, methodName, fileName, lineNumber);\n}\n" }, { "answer_id": 56856858, "author": "Owen Chen", "author_id": 2997128, "author_profile": "https://Stackoverflow.com/users/2997128", "pm_score": 0, "selected": false, "text": "Lg.d(\"int array:\", intArrayOf(1, 2, 3), \"int list:\", listOf(4, 5, 6))\n StackTraceElement lambda expression static initialization block" }, { "answer_id": 64406183, "author": "Delark", "author_id": 11214643, "author_profile": "https://Stackoverflow.com/users/11214643", "pm_score": 0, "selected": false, "text": "getStackTrace()[3] Thread.currentThread().getStackTrace()[X].getLineNumber(); private static String message(String TAG, String msg) {\n\n int lineNumber = Thread.currentThread().getStackTrace()[3].getLineNumber();\n\n return \".(\" + TAG + \".java:\"+ lineNumber +\")\" + \" \" + msg;\n}\n private static void print(String s) {\n System.out.println(s);\n}\n public static void normal(\n String TAG,\n String message\n) {\n print(\n message(\n TAG,\n message\n )\n );\n}\n Print.normal(TAG, \"StatelessDispatcher\");\n" }, { "answer_id": 72992183, "author": "sezad vakil", "author_id": 7302401, "author_profile": "https://Stackoverflow.com/users/7302401", "pm_score": 0, "selected": false, "text": "Thread.currentThread().getStackTrace()[2].getLineNumber()\n public static void Loge(Context context, String strMessage, int strLineNumber) {\n \n Log.e(context.getClass().getSimpleName(), strLineNumber + \" : \" + strMessage);\n \n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15177/" ]
115,031
<p>I have an assembly, written in C++\CLI, which uses some of enumerations, provided by .Net. It has such kind of properties: </p> <pre><code>property System::ServiceProcess::ServiceControllerStatus ^ Status { ServiceControllerStatus ^ get() { return (ServiceControllerStatus)_status-&gt;dwCurrentState; } } </code></pre> <p>it works fine, but when i use this assembly from my C# code, type of this property is </p> <pre><code>System.Enum </code></pre> <p>and i have to make type-cast</p> <pre><code> if ((ServiceControllerStatus)currentService.Status == ServiceControllerStatus.Running) //do smth </code></pre> <p>The question is simple: why is it so, and how to fix it ?</p>
[ { "answer_id": 115106, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 4, "selected": true, "text": "property System::ServiceProcess::ServiceControllerStatus Status \n{ \n System::ServiceProcess::ServiceControllerStatus get() \n { \n return (System::ServiceProcess::ServiceControllerStatus)_status->dwCurrentState; \n } \n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115031", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6698/" ]
115,039
<p>Suppose that the <strong>ApplicationSettings</strong> class is a general repository of settings that apply to my application such as TimeoutPeriod, DefaultUnitOfMeasure, HistoryWindowSize, etc... And let's say MyClass makes use of one of those settings - DefaultUnitOfMeasure.</p> <p>My reading of proper use of Inversion of Control Containers - and please correct me if I'm wrong on this - is that you define the dependencies of a class in its constructor:</p> <pre><code>public class MyClass { public MyClass(IDataSource ds, UnitOfMeasure default_uom) {...} } </code></pre> <p>and then call instantiate your class with something like</p> <pre><code>var mc = IoC.Container.Resolve&lt;MyClass&gt;(); </code></pre> <p>Where <strong>IDataSource</strong> has been assigned a concrete implementation and default_uom has been wired up to instantiate from the <strong>ApplicationSettings.DefaultUnitOfMeasure</strong> property. I've got to wonder however, if all these hoops are really that necessary to jump through. What trouble am I setting myself up for should I do</p> <pre><code>public class MyClass { public MyClass(IDataSource ds) { UnitOfMeasure duom = IoC.Container.Resolve&lt;UnitOfMeasure&gt;("default_uom"); } } </code></pre> <p>Yes, many of my classes end up with a dependency on <strong>IoC.Container</strong> but that is a dependency that most of my classes will have anyways. It seems like I maybe should make full use of it as long as the classes are coupled. Please Agile gurus, tell me where I'm wrong.</p>
[ { "answer_id": 119005, "author": "Brannon", "author_id": 5745, "author_profile": "https://Stackoverflow.com/users/5745", "pm_score": 2, "selected": false, "text": "public class MyClass {\n public MyClass(IDataSource ds) {\n UnitOfMeasure duom = IoC.Container.Resolve<UnitOfMeasure>(\"default_uom\");\n }\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
115,060
<p>I was reading a post by Brad Wilson (<a href="http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html" rel="nofollow noreferrer">http://bradwilson.typepad.com/blog/2008/08/partial-renderi.html</a>) on the new ViewEngine changes to MVC Preview 5 and thought that it would be great to be able to render a view to string for use in tests. I get the impression from the article that it may be possible to achieve this but cannot figure out how. </p> <p>I believe this would enable us to do away with some of our WatIn tests (which are slow and unreliable) as it would allow us to check that the View has rendered correctly by simply checking the string for expected values/text.</p> <p>Has anyone implemented something like this?</p>
[ { "answer_id": 31016901, "author": "Triet Doan", "author_id": 1814420, "author_profile": "https://Stackoverflow.com/users/1814420", "pm_score": 1, "selected": false, "text": "RenderPartialToString public static string RenderPartialToString(string controlName, object viewData)\n{\n ViewDataDictionary vd = new ViewDataDictionary(viewData);\n ViewPage vp = new ViewPage { ViewData = vd };\n Control control = vp.LoadControl(controlName);\n\n vp.Controls.Add(control);\n\n StringBuilder sb = new StringBuilder();\n using (StringWriter sw = new StringWriter(sb))\n {\n using (HtmlTextWriter tw = new HtmlTextWriter(sw))\n {\n vp.RenderControl(tw);\n }\n }\n\n return sb.ToString();\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11557/" ]
115,095
<p>I have my web browsers set to save what I type into text boxes on forms. I have a lot of search terms stored in the text box of my browser and would like to get at it via a program of some sort before I clear these values out. There are far too many for me to go through one at a time. </p> <p>The web browser must store this data somewhere, does anyone know where? Is it possible to retrieve these values? <em>Firefox</em>, more so than IE -- but either, if anyone knows a script that can extract these values? Thanks.</p>
[ { "answer_id": 31016901, "author": "Triet Doan", "author_id": 1814420, "author_profile": "https://Stackoverflow.com/users/1814420", "pm_score": 1, "selected": false, "text": "RenderPartialToString public static string RenderPartialToString(string controlName, object viewData)\n{\n ViewDataDictionary vd = new ViewDataDictionary(viewData);\n ViewPage vp = new ViewPage { ViewData = vd };\n Control control = vp.LoadControl(controlName);\n\n vp.Controls.Add(control);\n\n StringBuilder sb = new StringBuilder();\n using (StringWriter sw = new StringWriter(sb))\n {\n using (HtmlTextWriter tw = new HtmlTextWriter(sw))\n {\n vp.RenderControl(tw);\n }\n }\n\n return sb.ToString();\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14728/" ]
115,103
<p>I am trying to implement position-sensitive zooming inside a <code>JScrollPane</code>. The <code>JScrollPane</code> contains a component with a customized <code>paint</code> that will draw itself inside whatever space it is allocated - so zooming is as easy as using a <code>MouseWheelListener</code> that resizes the inner component as required.</p> <p>But I also want zooming into (or out of) a point to keep that point as central as possible within the resulting zoomed-in (or -out) view (this is what I refer to as 'position-sensitive' zooming), similar to how zooming works in google maps. I am sure this has been done many times before - does anybody know the "right" way to do it under Java Swing?. Would it be better to play with <code>Graphic2D</code>'s transformations instead of using <code>JScrollPanes</code>?</p> <p>Sample code follows:</p> <pre><code>package test; import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; public class FPanel extends javax.swing.JPanel { private Dimension preferredSize = new Dimension(400, 400); private Rectangle2D[] rects = new Rectangle2D[50]; public static void main(String[] args) { JFrame jf = new JFrame("test"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jf.setSize(400, 400); jf.add(new JScrollPane(new FPanel())); jf.setVisible(true); } public FPanel() { // generate rectangles with pseudo-random coords for (int i=0; i&lt;rects.length; i++) { rects[i] = new Rectangle2D.Double( Math.random()*.8, Math.random()*.8, Math.random()*.2, Math.random()*.2); } // mouse listener to detect scrollwheel events addMouseWheelListener(new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { updatePreferredSize(e.getWheelRotation(), e.getPoint()); } }); } private void updatePreferredSize(int n, Point p) { double d = (double) n * 1.08; d = (n &gt; 0) ? 1 / d : -d; int w = (int) (getWidth() * d); int h = (int) (getHeight() * d); preferredSize.setSize(w, h); getParent().doLayout(); // Question: how do I keep 'p' centered in the resulting view? } public Dimension getPreferredSize() { return preferredSize; } private Rectangle2D r = new Rectangle2D.Float(); public void paint(Graphics g) { super.paint(g); g.setColor(Color.red); int w = getWidth(); int h = getHeight(); for (Rectangle2D rect : rects) { r.setRect(rect.getX() * w, rect.getY() * h, rect.getWidth() * w, rect.getHeight() * h); ((Graphics2D)g).draw(r); } } } </code></pre>
[ { "answer_id": 2598320, "author": "xycf7", "author_id": 262537, "author_profile": "https://Stackoverflow.com/users/262537", "pm_score": 1, "selected": false, "text": "\nprivate void updatePreferredSize(int n, Point p) {\n double d = (double) n * 1.08;\n d = (n > 0) ? 1 / d : -d;\n int w = (int) (getWidth() * d);\n int h = (int) (getHeight() * d);\n preferredSize.setSize(w, h);\n\n // Question: how do I keep 'p' centered in the resulting view?\n\n int parentWdt = this.getParent( ).getWidth( ) ;\n int parentHgt = this.getParent( ).getHeight( ) ;\n\n int newLeft = p.getLocation( ).x - ( p.x - ( parentWdt / 2 ) ) ;\n int newTop = p.getLocation( ).y - ( p.y - ( parentHgt / 2 ) ) ;\n this.setLocation( newLeft, newTop ) ;\n\n getParent().doLayout();\n}\n\n" }, { "answer_id": 2605254, "author": "Kevin K", "author_id": 292728, "author_profile": "https://Stackoverflow.com/users/292728", "pm_score": 4, "selected": true, "text": "private void updatePreferredSize(int n, Point p) {\n double d = (double) n * 1.08;\n d = (n > 0) ? 1 / d : -d;\n\n int w = (int) (getWidth() * d);\n int h = (int) (getHeight() * d);\n preferredSize.setSize(w, h);\n\n int offX = (int)(p.x * d) - p.x;\n int offY = (int)(p.y * d) - p.y;\n setLocation(getLocation().x-offX,getLocation().y-offY);\n\n getParent().doLayout();\n}\n p FPanel p p" }, { "answer_id": 2609144, "author": "Carl Manaster", "author_id": 82118, "author_profile": "https://Stackoverflow.com/users/82118", "pm_score": 2, "selected": false, "text": "private void updatePreferredSize(int wheelRotation, Point stablePoint) {\n double scaleFactor = findScaleFactor(wheelRotation);\n scaleBy(scaleFactor);\n Point offset = findOffset(stablePoint, scaleFactor);\n offsetBy(offset);\n getParent().doLayout();\n}\n\nprivate double findScaleFactor(int wheelRotation) {\n double d = wheelRotation * 1.08;\n return (d > 0) ? 1 / d : -d;\n}\n\nprivate void scaleBy(double scaleFactor) {\n int w = (int) (getWidth() * scaleFactor);\n int h = (int) (getHeight() * scaleFactor);\n preferredSize.setSize(w, h);\n}\n\nprivate Point findOffset(Point stablePoint, double scaleFactor) {\n int x = (int) (stablePoint.x * scaleFactor) - stablePoint.x;\n int y = (int) (stablePoint.y * scaleFactor) - stablePoint.y;\n return new Point(x, y);\n}\n\nprivate void offsetBy(Point offset) {\n Point location = getLocation();\n setLocation(location.x - offset.x, location.y - offset.y);\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15472/" ]
115,115
<p><strong>Has anyone had success automating testing directly on embedded hardware?</strong></p> <p>Specifically, I am thinking of automating a battery of unit tests for hardware layer modules. We need to have greater confidence in our hardware layer code. A lot of our projects use interrupt driven timers, ADCs, serial io, serial SPI devices (flash memory) etc..</p> <p><strong>Is this even worth the effort?</strong></p> <p>We typically target:</p> <p>Processor: 8 or 16 bit microcontrollers (some DSP stuff)<br> Language: C (sometimes c++). </p>
[ { "answer_id": 115162, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 4, "selected": false, "text": "TEST_EQUAL TEST_BITSET TEST_BITVLR" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445087/" ]
115,121
<p>Does anyone know why there is no <code>respond_to</code> block for generated <code>edit</code> actions? Every other action in typical scaffold controllers has a <code>respond_to</code> block in order to output <code>html</code> and <code>xml</code> formats. Why is the <code>edit</code> action an exception?</p> <p>I'm using the latest version of Ruby on Rails (2.1.1).</p>
[ { "answer_id": 115211, "author": "Pete", "author_id": 13472, "author_profile": "https://Stackoverflow.com/users/13472", "pm_score": 5, "selected": true, "text": "GET /my_models/[:id].xml (Show) \n PUT /my_models/[:id].xml (Update) \n GET /my_models/[:id]/edit \n" }, { "answer_id": 116792, "author": "Ryan McGeary", "author_id": 8985, "author_profile": "https://Stackoverflow.com/users/8985", "pm_score": 2, "selected": false, "text": "GET /my_models/new.xml\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20467/" ]
115,159
<p>I have been using ASP.NET for years, but I can never remember when using the # and = are appropriate.</p> <p>For example:</p> <pre><code>&lt;%= Grid.ClientID %&gt; </code></pre> <p>or</p> <pre><code>&lt;%# Eval("FullName")%&gt; </code></pre> <p>Can someone explain when each should be used so I can keep it straight in my mind? Is # only used in controls that support databinding?</p>
[ { "answer_id": 115212, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 5, "selected": false, "text": "<%@ <%$ <%= <%# <%-- <%: <%#:" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/417/" ]
115,167
<p>I've been developing a site over the past few weeks using CodeIgniter as the framework. I've been thinking of the best way to accomplish something, which in a lot of other frameworks in other languages is relatively simple: sortable tables. CodeIgniter switches off query strings by default, because your URLs contain method parameters. So a URL might look like:</p> <pre><code>/controller/method/param1/param2 </code></pre> <p>You might think that you could just add in <code>sortBy</code> and <code>sortOrder</code> as two additional parameters to the controller method. I don't particularly want to do that, mainly because I want to have a re-usable controller. When you use query string parameters, PHP can easily tell you whether there is a parameter called <code>sortBy</code>. However, when you're using URL based parameters, it will vary with each controller.</p> <p>I was wondering what my options were. As far as I can see they are something like:</p> <ul> <li>Pass in my <code>sortBy</code> and <code>sortOrder</code> parameters, just suck it up, and develop some less-than-reusable component for it.</li> <li>Have an additional controller, which will store the <code>sortBy</code> and <code>sortOrder</code> in the session (although it would have to know where you came from, and send you back to the original page).</li> <li>Have some kind of AJAX function, which would call the controller above; then reload the page.</li> <li>Hack CodeIgniter to turn query strings back on. Actually, if this is the only option, any links to how to do this would be appreciated.</li> </ul> <p>I just can't quite believe such a simple task would present such a problem! Am I missing something? Does anyone have any recommendations?</p> <p>While I love jQuery, and I'm already using it on the site, so TableSorter is a good option. However, I would like to do server-side sorting as there are some pages with potentially large numbers of results, including pagination.</p>
[ { "answer_id": 119265, "author": "JayTee", "author_id": 20153, "author_profile": "https://Stackoverflow.com/users/20153", "pm_score": 1, "selected": false, "text": "$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\\-,';\n function sorter() {\n //get the sort params\n $sort = explode(\",\",$this->uri->segment(3)); //the 3rd segment is the column/order\n //pass the params to the model\n $data = $this->model_name->get_the_data($sort[0],$sort[1]);\n $this->_show($data);\n}\nfunction _show($data) {\n //all the code for displaying your table\n}\n function showGrid() {\n $sort = $this->uri->segment(3);\n if ($sort) {\n //get the data sorted\n } else {\n //get the data the default way\n }\n //rest of your view logic\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
115,210
<p>I'm processing some data files that are supposed to be valid UTF-8 but aren't, which causes the parser (not under my control) to fail. I'd like to add a stage of pre-validating the data for UTF-8 well-formedness, but I've not yet found a utility to help do this.</p> <p>There's a <a href="http://www.w3.org/2005/01/yacker/uploads/utf8-validator" rel="noreferrer">web service</a> at W3C which appears to be dead, and I've found a Windows-only validation <a href="http://web.archive.org/web/20081101142036/http://bolek.techno.cz:80/UTF8-Validator/" rel="noreferrer">tool</a> that reports invalid UTF-8 files but doesn't report which lines/characters to fix.</p> <p>I'd be happy with either a tool I can drop in and use (ideally cross-platform), or a ruby/perl script I can make part of my data loading process. </p>
[ { "answer_id": 115241, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 3, "selected": false, "text": ">>> a=\"γεια\"\n>>> a\n'\\xce\\xb3\\xce\\xb5\\xce\\xb9\\xce\\xb1'\n>>> b='\\xce\\xb3\\xce\\xb5\\xce\\xb9\\xff\\xb1' # note second-to-last char changed\n>>> print b.decode(\"utf_8\")\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/usr/local/lib/python2.5/encodings/utf_8.py\", line 16, in decode\n return codecs.utf_8_decode(input, errors, True)\nUnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 6: unexpected code byte\n >>> try: print b.decode(\"utf_8\")\n... except UnicodeDecodeError, exc: pass\n...\n>>> exc\nUnicodeDecodeError('utf8', '\\xce\\xb3\\xce\\xb5\\xce\\xb9\\xff\\xb1', 6, 7, 'unexpected code byte')\n>>> exc.args\n('utf8', '\\xce\\xb3\\xce\\xb5\\xce\\xb9\\xff\\xb1', 6, 7, 'unexpected code byte')\n" }, { "answer_id": 115262, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 8, "selected": true, "text": "$ iconv -f UTF-8 your_file -o /dev/null; echo $?\n $ iconv -f UTF-8 your_file > /dev/null; echo $?\n" }, { "answer_id": 37450729, "author": "Roger Dahl", "author_id": 442006, "author_profile": "https://Stackoverflow.com/users/442006", "pm_score": 3, "selected": false, "text": "$ apt-get install moreutils\n$ isutf8 your_file\n --quiet" }, { "answer_id": 60328220, "author": "mivk", "author_id": 111036, "author_profile": "https://Stackoverflow.com/users/111036", "pm_score": 0, "selected": false, "text": "recode if recode utf8/..UCS < \"$FILE\" >/dev/null 2>&1; then\n echo \"Valid utf8 : $FILE\"\nelse\n echo \"NOT valid utf8: $FILE\"\nfi\n" }, { "answer_id": 61083154, "author": "Sherzad", "author_id": 2021982, "author_profile": "https://Stackoverflow.com/users/2021982", "pm_score": 2, "selected": false, "text": "#!/bin/bash\n\ninputFile=\"./testFile.txt\"\n\niconv -f UTF-8 \"$inputFile\" -o /dev/null\n\nif [[ $? -eq 0 ]]\nthen\n echo \"Valid UTF-8 file.\";\nelse\n echo \"Invalid UTF-8 file!\";\nfi\n --from-code -f --to-code -t --output -o" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6716/" ]
115,222
<p>I have a file I need to move that's already under perforce. Once moved it needs some editing - update the package, etc - appropriate to its new location. Should I submit the move changespec and then reopen it for edit, or can I do this in one go? If so, what is the appropriate sequence of events?</p>
[ { "answer_id": 115290, "author": "Jough Dempsey", "author_id": 20497, "author_profile": "https://Stackoverflow.com/users/20497", "pm_score": 0, "selected": false, "text": "<text> <ktext> p4 filelog -i" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4893/" ]
115,237
<p>I am using Visual Studio, developing a native application, I have a programmatical breakpoint (assert) in my code placed using __asm int 3 or __debugbreak. Sometimes when I hit it, I would like to disable it so that successive hits in the same debugging session no longer break into the debugger. How can I do this?</p>
[ { "answer_id": 115238, "author": "Suma", "author_id": 16673, "author_profile": "https://Stackoverflow.com/users/16673", "pm_score": 6, "selected": true, "text": "*(char *)eip,x *(char *)rip,x *(int *)iar,x" }, { "answer_id": 6228529, "author": "Fili", "author_id": 675305, "author_profile": "https://Stackoverflow.com/users/675305", "pm_score": 2, "selected": false, "text": "#define ASSERT(x) {\\\n if (!(x)) \\\n { \\\n static bool ignore = false; \\\n if (!ignore) \\\n { \\\n ignore = true; \\\n __asm int 3 \\\n } \\\n }\\\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16673/" ]
115,249
<p>I am trying to have a logout page where is displays a messages and then redirects to the login page. This is in ASP.net 2.0.</p> <p>I have this in my <code>Page_Load</code>:</p> <pre><code>ClientScript.RegisterStartupScript(typeof(Page), "pageredirect", JavascriptRedirect() ); </code></pre> <p>This is my redirect function:</p> <pre><code>private string JavascriptRedirect() { StringBuilder sb = new StringBuilder(); sb.Append("&lt;script type=\"text/javascript\" language=\"javascript\"&gt;"); sb.Append("var x = 5;"); sb.Append("var y = 1;"); sb.Append("function startClock(){"); sb.Append("x = x-y;"); sb.Append("t=setTimeout(\"startClock()\", 1000);"); sb.Append("if(x==0){"); sb.Append("window.location='login.aspx';"); sb.Append("clearTimeout(t);"); sb.Append(" }"); sb.Append(" }"); sb.Append("startClock();"); sb.Append("&lt;/script&gt;"); return sb.ToString(); } </code></pre> <p>When I test there is no javascript in my resulting logout page. Anyone have an idea on what is happening. Is <code>Page_Load</code> to late to register this?</p>
[ { "answer_id": 115286, "author": "Johannes Hädrich", "author_id": 18246, "author_profile": "https://Stackoverflow.com/users/18246", "pm_score": 2, "selected": true, "text": "<HEAD> <meta http-equiv=\"refresh\" content=\"5; URL=login.aspx\">\n" }, { "answer_id": 115373, "author": "brock.holum", "author_id": 15860, "author_profile": "https://Stackoverflow.com/users/15860", "pm_score": 0, "selected": false, "text": "Page.ClientScript.RegisterStartupScript(this.GetType(), \"Redirect\", \"script here\", true);\n Page.ClientScript.RegisterClientScriptInclude(\"RedirectInclude\", \"scripts/redirect.js\");\nPage.ClientScript.RegisterStartupScript(this.GetType(), \"Redirect\", \"JavascriptRedirect();\", true);\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3208/" ]
115,269
<p>There's something very unsatisfactory about this code:</p> <pre><code>/* Given a command string in which the first 8 characters are the command name padded on the right with whitespace, construct the appropriate kind of Command object. */ public class CommandFactory { public Command getCommand(String cmd) { cmdName = cmd.subString(0,8).trim(); if(cmdName.equals("START")) { return new StartCommand(cmd); } if(cmdName.equals("END")) { return new EndCommand(cmd); } // ... more commands in more if blocks here // else it's a bad command. return new InvalidCommand(cmd); } } </code></pre> <p>I'm unrepentant about the multiple exit points - the structure is clear. But I'm not happy about the series of near-identical if statements. I've considered making a Map of Strings to Commands:</p> <pre><code>commandMap = new HashMap(); commandMap.put("START",StartCommand.class); // ... etc. </code></pre> <p>... then using Reflection to make instances of the appropriate class looked up from the Map. However while conceptually elegant, this involves a fair amount of Reflection code that whoever inherits this code might not appreciate - although that cost might be offset by the benefits. All the lines hardcoding values into the commandMap smell almost as bad as the if block.</p> <p>Even better would be if the factory's constructor could scan the classpath for subclasses of Command, query them for String representations, and automatically add them them to its repertoire.</p> <p>So - how should I go about refactoring this?</p> <p>I guess some of the frameworks out there give me this kind of thing for free. Let's assume I'm not in a position to migrate this stuff into such a framework.</p>
[ { "answer_id": 115313, "author": "davetron5000", "author_id": 3029, "author_profile": "https://Stackoverflow.com/users/3029", "pm_score": 5, "selected": true, "text": "Class c = commandMap.get(cmdName);\nif (c != null)\n return c.newInstance();\nelse\n throw new IllegalArgumentException(cmdName + \" is not as valid command\");\n enum CommandInterface public enum Command\n{\n START(StartCommand.class),\n END(EndCommand.class);\n\n private Class<? extends CommandInterface> mappedClass;\n private Command(Class<? extends CommandInterface> c) { mappedClass = c; }\n public CommandInterface getInstance()\n {\n return mappedClass.newInstance();\n }\n}\n EnumSet" }, { "answer_id": 115325, "author": "Tim Frey", "author_id": 1471, "author_profile": "https://Stackoverflow.com/users/1471", "pm_score": 2, "selected": false, "text": "cmd.subString(0,8).trim();\n" }, { "answer_id": 115329, "author": "Auron", "author_id": 1679, "author_profile": "https://Stackoverflow.com/users/1679", "pm_score": 2, "selected": false, "text": "commandMap = new HashMap();\ncommandMap.put(\"START\",new StartCommand());\n command = ((Command) commandMap.get(cmdName)).clone();\n command.setCommandString(cmdName);\n" }, { "answer_id": 115331, "author": "Tetha", "author_id": 17663, "author_profile": "https://Stackoverflow.com/users/17663", "pm_score": 0, "selected": false, "text": "class CreateStartCommands implements CommandCreator {\n public bool is_fitting_commandstring(String identifier) {\n return identifier == \"START\"\n }\n public Startcommand create_instance(cmd) {\n return StartCommand(cmd);\n }\n}\n" }, { "answer_id": 115339, "author": "Mike Deck", "author_id": 1247, "author_profile": "https://Stackoverflow.com/users/1247", "pm_score": 2, "selected": false, "text": "public class CommandFactory {\n private static List<Command> commands = new ArrayList<Command>(); \n\n public static void registerCommand(Command cmd) {\n commands.add(cmd);\n }\n\n public Command getCommand(String cmd) {\n for(Command instance : commands) {\n if(instance.identifier(cmd)) {\n return cmd;\n }\n }\n throw new CommandNotRegisteredException(cmd);\n }\n}\n" }, { "answer_id": 115628, "author": "Roel Spilker", "author_id": 12634, "author_profile": "https://Stackoverflow.com/users/12634", "pm_score": 4, "selected": false, "text": "public enum CommandFactory {\n START {\n @Override\n Command create(String cmd) {\n return new StartCommand(cmd);\n }\n },\n END {\n @Override\n Command create(String cmd) {\n return new EndCommand(cmd);\n }\n };\n\n abstract Command create(String cmd);\n\n public static Command getCommand(String cmd) {\n String cmdName = cmd.substring(0, 8).trim();\n\n CommandFactory factory;\n try {\n factory = valueOf(cmdName);\n }\n catch (IllegalArgumentException e) {\n return new InvalidCommand(cmd);\n }\n return factory.create(cmd);\n }\n}\n valueOf(String) IllegalArgumentException InvalidCommand create(String cmd) CommandFactory.START.create(String cmd" }, { "answer_id": 115688, "author": "bpapa", "author_id": 543, "author_profile": "https://Stackoverflow.com/users/543", "pm_score": 0, "selected": false, "text": "public static Member getCommandObjectForRegistration();\npublic static Member getCommandObjectForChangePassword();\n" }, { "answer_id": 115737, "author": "Tom Hawtin - tackline", "author_id": 4725, "author_profile": "https://Stackoverflow.com/users/4725", "pm_score": 0, "selected": false, "text": " return \n cmdName.equals(\"START\") ? new StartCommand (cmd) :\n cmdName.equals(\"END\" ) ? new EndCommand (cmd) :\n new InvalidCommand(cmd);\n import xx.example.Command.*;\n\n Command command = Command.valueOf(commandStr);\n return \n command == START ? new StartCommand (commandLine) :\n command == END ? new EndCommand (commandLine) :\n new InvalidCommand(commandLine);\n" }, { "answer_id": 118300, "author": "MetroidFan2002", "author_id": 8026, "author_profile": "https://Stackoverflow.com/users/8026", "pm_score": 0, "selected": false, "text": "public class CommandFactory {\n public Command getCommand(String cmd) {\n if(cmd == null) {\n return new InvalidCommand(cmd);\n }\n\n Class commandClass = (Class) commandMap.get(cmd);\n\n if(commandClass == null) {\n return new InvalidCommand(cmd);\n }\n\n try {\n Command newCommand = (Command) commandClass.newInstance();\n newCommand.setCommandString(cmd);\n return newCommand;\n }\n catch(Exception e) {\n return new InvalidCommand(cmd);\n }\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115269", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7512/" ]
115,277
<p>I'm wandering myself what component is the best for displaying fast search results in swing. I want to create something like this, make a text field where user can enter some text, during his entering I'll improve in back end fast search on database, and I want to show data bellow the text box, and he will be able to browse the results and on pres enter result will be displayed in table. So my question is is there any component which already have this logic for displaying? Or is it's not, what is the best way to implement that.</p> <p>This search will be something what ajax gives me on web, same logic same look and feel, if it's possible on desktop application.</p>
[ { "answer_id": 115355, "author": "davetron5000", "author_id": 3029, "author_profile": "https://Stackoverflow.com/users/3029", "pm_score": 2, "selected": false, "text": "JTextField Document" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16039/" ]
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://web.archive.org/web/20181001011217/http://www.diveintopython.net/soap_web_services/" rel="noreferrer">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds" rel="noreferrer">suds</a> which works partly, but breaks with certain types (suds.TypeNotFound: Type not found: 'item').</p> <p>I have also looked at <a href="http://trac.optio.webfactional.com/wiki" rel="noreferrer">Client</a> but this does not appear to support WSDL.</p> <p>And I have looked at <a href="http://pywebsvcs.sourceforge.net/zsi.html" rel="noreferrer">ZSI</a> but it looks very complex. Does anyone have any sample code for it?</p> <p>The WSDL is <a href="https://ws.pingdom.com/soap/PingdomAPI.wsdl" rel="noreferrer">https://ws.pingdom.com/soap/PingdomAPI.wsdl</a> and works fine with the PHP 5 SOAP client.</p>
[ { "answer_id": 27302096, "author": "Teddy Belay", "author_id": 4325298, "author_profile": "https://Stackoverflow.com/users/4325298", "pm_score": 4, "selected": false, "text": "import logging\nfrom suds.client import Client\nfrom suds.wsse import *\nfrom datetime import timedelta,date,datetime,tzinfo\nimport requests\nfrom requests.auth import HTTPBasicAuth\nimport suds_requests\n username=input('Username:')\npassword=input('password:')\nsession = requests.session()\nsession.auth=(username, password)\n client = Client(WSDL_URL, faults=False, cachingpolicy=1, location=WSDL_URL, transport=suds_requests.RequestsTransport(session))\n ...\naddSecurityHeader(client,username,password)\n....\n\ndef addSecurityHeader(client,username,password):\n security=Security()\n userNameToken=UsernameToken(username,password)\n timeStampToken=Timestamp(validity=600)\n security.tokens.append(userNameToken)\n security.tokens.append(timeStampToken)\n client.set_options(wsse=security)\n result=client.service.methodName(Inputs)\n logging.basicConfig(level=logging.INFO) \nlogging.getLogger('suds.client').setLevel(logging.DEBUG) \nlogging.getLogger('suds.transport').setLevel(logging.DEBUG)\n (200, (collectionNodeLmp){\n timestamp = 2014-12-03 00:00:00-05:00\n nodeLmp[] = \n (nodeLmp){\n pnodeId = 35010357\n name = \"YADKIN\"\n mccValue = -0.19\n mlcValue = -0.13\n price = 36.46\n type = \"500 KV\"\n timestamp = 2014-12-03 01:00:00-05:00\n errorCodeId = 0\n },\n (nodeLmp){\n pnodeId = 33138769\n name = \"ZION 1\"\n mccValue = -0.18\n mlcValue = -1.86\n price = 34.75\n type = \"Aggregate\"\n timestamp = 2014-12-03 01:00:00-05:00\n errorCodeId = 0\n },\n })\n" }, { "answer_id": 42981300, "author": "Down the Stream", "author_id": 1243786, "author_profile": "https://Stackoverflow.com/users/1243786", "pm_score": 1, "selected": false, "text": "#!/usr/bin/python\n# -*- coding: utf-8 -*-\n# consume_wsdl_soap_ws_pss.py\nimport logging.config\nfrom pysimplesoap.client import SoapClient\n\nlogging.config.dictConfig({\n 'version': 1,\n 'formatters': {\n 'verbose': {\n 'format': '%(name)s: %(message)s'\n }\n },\n 'handlers': {\n 'console': {\n 'level': 'DEBUG',\n 'class': 'logging.StreamHandler',\n 'formatter': 'verbose',\n },\n },\n 'loggers': {\n 'pysimplesoap.helpers': {\n 'level': 'DEBUG',\n 'propagate': True,\n 'handlers': ['console'],\n },\n }\n})\n\nWSDL_URL = 'http://www.webservicex.net/stockquote.asmx?WSDL'\nclient = SoapClient(wsdl=WSDL_URL, ns=\"web\", trace=True)\nclient['AuthHeaderElement'] = {'username': 'someone', 'password': 'nottelling'}\n\n#Discover operations\nlist_of_services = [service for service in client.services]\nprint(list_of_services)\n\n#Discover params\nmethod = client.services['StockQuote']\n\nresponse = client.GetQuote(symbol='GOOG')\nprint('GetQuote: {}'.format(response['GetQuoteResult']))\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2183/" ]
115,319
<p>I'm using C# and connecting to a WebService via an auto-generated C# proxy object. The method I'm calling can be long running, and sometimes times out. I get different errors back, sometimes I get a <code>System.Net.WebException</code> or a <code>System.Web.Services.Protocols.SoapException</code>. These exceptions have properties I can interrogate to find the specific type of error from which I can display a human-friendly version of to the user.</p> <p>But sometimes I just get an <code>InvalidOperationException</code>, and it has the following Message. Is there any way I can interpret what this is without digging through the string for things I recognize, that feels very dirty, and isn't internationalization agnostic, the error message might come back in a different language.</p> <pre><code>Client found response content type of 'text/html; charset=utf-8', but expected 'text/xml'. The request failed with the error message: -- &lt;html&gt; &lt;head&gt; &lt;title&gt;Request timed out.&lt;/title&gt; &lt;style&gt; body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: .9em} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } &lt;/style&gt; &lt;/head&gt; &lt;body bgcolor="white"&gt; &lt;span&gt;&lt;H1&gt;Server Error in '/PerformanceManager' Application.&lt;hr width=100% size=1 color=silver&gt;&lt;/H1&gt; &lt;h2&gt; &lt;i&gt;Request timed out.&lt;/i&gt; &lt;/h2&gt;&lt;/span&gt; &lt;font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "&gt; &lt;b&gt; Description: &lt;/b&gt;An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. &lt;br&gt;&lt;br&gt; &lt;b&gt; Exception Details: &lt;/b&gt;System.Web.HttpException: Request timed out.&lt;br&gt;&lt;br&gt; &lt;b&gt;Source Error:&lt;/b&gt; &lt;br&gt;&lt;br&gt; &lt;table width=100% bgcolor="#ffffcc"&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt; An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.&lt;/code&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br&gt; &lt;b&gt;Stack Trace:&lt;/b&gt; &lt;br&gt;&lt;br&gt; &lt;table width=100% bgcolor="#ffffcc"&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;&lt;pre&gt; [HttpException (0x80004005): Request timed out.] &lt;/pre&gt;&lt;/code&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;br&gt; &lt;hr width=100% size=1 color=silver&gt; &lt;b&gt;Version Information:&lt;/b&gt; Microsoft .NET Framework Version:2.0.50727.312; ASP.NET Version:2.0.50727.833 &lt;/font&gt; &lt;/body&gt; &lt;/html&gt; &lt;!-- [HttpException]: Request timed out. --&gt; --. </code></pre> <p>Edit: I have a try-catch around the method on the web-server. I have debugged it, and the web-server method returns (after a minute or so) without any exception. I also added an unhandled exception handler in the web service and a breakpoint there wasn't hit. As soon as the web-service returns, I get this error in the client instead of the result I expected.</p>
[ { "answer_id": 6207632, "author": "Mhoque", "author_id": 557700, "author_profile": "https://Stackoverflow.com/users/557700", "pm_score": 3, "selected": false, "text": " <httpRuntime requestValidationMode=\"2.0\" />\n <pages validateRequest=\"false\" />\n" }, { "answer_id": 33893246, "author": "Zameer Ansari", "author_id": 2404470, "author_profile": "https://Stackoverflow.com/users/2404470", "pm_score": 2, "selected": false, "text": "[WebMethod]\npublic int Foo()\n{\n return 0;\n}\n [SoapDocumentMethod(OneWay = true)]\n[WebMethod]\npublic void Foo()\n{\n return;\n}\n" }, { "answer_id": 51866257, "author": "Phi", "author_id": 3200493, "author_profile": "https://Stackoverflow.com/users/3200493", "pm_score": 1, "selected": false, "text": "asmx using (wsWebService yourService = new wsWebService())\n{\n yourService.Url = \"https://myUrlService.com/wsWebService.asmx?op=someOption\";\n yourService.UseDefaultCredentials = true; // this line depends on your authentication type\n yourService.SoapVersion = SoapProtocolVersion.Soap11; // asign the version of SOAP\n var result = yourService.SomeMethod(\"Parameter\");\n}\n wsWebService" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11898/" ]
115,328
<p>I have the following class</p> <pre> public class Car { public Name {get; set;} } </pre> <p>and I want to bind this programmatically to a text box.</p> <p>How do I do that?</p> <p>Shooting in the dark:</p> <pre> ... Car car = new Car(); TextEdit editBox = new TextEdit(); editBox.DataBinding.Add("Name", car, "Car - Name"); ... </pre> <p>I get the following error</p> <blockquote> <p>"Cannot bind to the propery 'Name' on the target control.</p> </blockquote> <p>What am I doing wrong and how should I be doing this? I am finding the databinding concept a bit difficult to grasp coming from web-development.</p>
[ { "answer_id": 115346, "author": "Danimal", "author_id": 2757, "author_profile": "https://Stackoverflow.com/users/2757", "pm_score": 4, "selected": false, "text": "editBox.DataBinding.Add(\"Text\", car, \"Name\");\n" }, { "answer_id": 115351, "author": "ageektrapped", "author_id": 631, "author_profile": "https://Stackoverflow.com/users/631", "pm_score": 7, "selected": true, "text": "editBox.DataBindings.Add(\"Text\", car, \"Name\");\n" }, { "answer_id": 115354, "author": "TcKs", "author_id": 20382, "author_profile": "https://Stackoverflow.com/users/20382", "pm_score": 2, "selected": false, "text": "editBox.DataBinding.Add( \"Text\", car\", \"Name\" );\n" }, { "answer_id": 115360, "author": "itsmatt", "author_id": 7862, "author_profile": "https://Stackoverflow.com/users/7862", "pm_score": 2, "selected": false, "text": "editBox.DataBindings.Add(new Binding(\"Text\", car, \"Name\"));" }, { "answer_id": 115365, "author": "Romain Verdier", "author_id": 4687, "author_profile": "https://Stackoverflow.com/users/4687", "pm_score": 3, "selected": false, "text": "editBox.DataBinding.Add(\"Text\", car, \"Name\");\n" }, { "answer_id": 115441, "author": "John Hunter", "author_id": 2253, "author_profile": "https://Stackoverflow.com/users/2253", "pm_score": 3, "selected": false, "text": "editBox.DataBinding.Add(\"Text\", car, \"Name\");\n" }, { "answer_id": 39832923, "author": "tofo", "author_id": 2987439, "author_profile": "https://Stackoverflow.com/users/2987439", "pm_score": 0, "selected": false, "text": "public class NotifyValue<datatype> : INotifyPropertyChanged \n{\n public event PropertyChangedEventHandler PropertyChanged = delegate { };\n\n datatype _value;\n public datatype Value\n {\n get\n {\n return _value;\n }\n set\n {\n _value = value;\n PropertyChanged.Invoke(this, new PropertyChangedEventArgs(\"Value\"));\n }\n }\n\n}\n public NotifyValue<int> myInteger = new NotifyValue<int>();\n Textbox1.DataBindings.Add(\n \"Text\", \n this, \n \"myInteger.Value\", \n false, \n DataSourceUpdateMode.OnPropertyChanged\n);\n" }, { "answer_id": 44983067, "author": "Graviton", "author_id": 3834, "author_profile": "https://Stackoverflow.com/users/3834", "pm_score": 2, "selected": false, "text": "editBox.DataBinding.Add(nameof(editBox.Text), car, nameof(car.Name));\n datamember car" }, { "answer_id": 46167248, "author": "Ramgy Borja", "author_id": 7978302, "author_profile": "https://Stackoverflow.com/users/7978302", "pm_score": 0, "selected": false, "text": " this.editBox.DataBindings.Add(new Binding(\"Text\", car, \"Name\"));\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15771/" ]
115,369
<p>I feel that my shop has a hole because we don't have a solid process in place for versioning our database schema changes. We do a lot of backups so we're more or less covered, but it's bad practice to rely on your last line of defense in this way. </p> <p>Surprisingly, this seems to be a common thread. Many shops I have spoken to ignore this issue because their databases don't change often, and they basically just try to be meticulous.</p> <p>However, I know how that story goes. It's only a matter of time before things line up just wrong and something goes missing. </p> <p>Are there any best practices for this? What are some strategies that have worked for you? </p>
[ { "answer_id": 115422, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 5, "selected": false, "text": "if [ $VERSION \\< '8.0.108' ] ; then\n psql -U cosuser $dbName << EOF8.0.108\n BEGIN TRANSACTION;\n --\n -- Remove foreign key that shouldn't have been there.\n -- PCR:35665\n --\n ALTER TABLE migratorjobitems\n DROP CONSTRAINT migratorjobitems_destcmaid_fkey;\n -- \n -- Increment the version\n UPDATE sys_info\n SET value = '8.0.108'\n WHERE key = 'DB VERSION';\n END TRANSACTION;\nEOF8.0.108\nfi\n\nif [ $VERSION \\< '8.0.109' ] ; then\n psql -U cosuser $dbName << EOF8.0.109\n BEGIN TRANSACTION;\n --\n -- I missed a couple of cases when I changed the legacy playlist\n -- from reporting showplaylistidnum to playlistidnum\n --\n ALTER TABLE featureidrequestkdcs\n DROP CONSTRAINT featureidrequestkdcs_cosfeatureid_fkey;\n ALTER TABLE featureidrequestkdcs\n ADD CONSTRAINT featureidrequestkdcs_cosfeatureid_fkey\n FOREIGN KEY (cosfeatureid)\n REFERENCES playlist(playlistidnum)\n ON DELETE CASCADE;\n --\n ALTER TABLE ticket_system_ids\n DROP CONSTRAINT ticket_system_ids_showplaylistidnum_fkey;\n ALTER TABLE ticket_system_ids\n RENAME showplaylistidnum\n TO playlistidnum;\n ALTER TABLE ticket_system_ids\n ADD CONSTRAINT ticket_system_ids_playlistidnum_fkey\n FOREIGN KEY (playlistidnum)\n REFERENCES playlist(playlistidnum)\n ON DELETE CASCADE;\n -- \n -- Increment the version\n UPDATE sys_info\n SET value = '8.0.109'\n WHERE key = 'DB VERSION';\n END TRANSACTION;\nEOF8.0.109\nfi\n" }, { "answer_id": 115885, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "DROP TABLE IF EXISTS `meta`;\nCREATE TABLE `meta` (\n `property` varchar(255),\n `value` varchar(255),\n PRIMARY KEY (`property`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1;\nINSERT INTO `meta` VALUES ('version', '$Rev: 240 $');\n" }, { "answer_id": 258421, "author": "WW.", "author_id": 14663, "author_profile": "https://Stackoverflow.com/users/14663", "pm_score": 2, "selected": false, "text": "INSERT INTO Currency (CurrencyCode, CurrencyName) \nVALUES ('AUD', 'Australian Dollars');\n\nINSERT INTO Currency (CurrencyCode, CurrencyName) \nVALUES ('USD', 'US Dollars');\n currency.sql" }, { "answer_id": 777224, "author": "Yordan Georgiev", "author_id": 65706, "author_profile": "https://Stackoverflow.com/users/65706", "pm_score": 2, "selected": false, "text": "USE [master]\nGO\n\n/****** Object: Database [DBGA_DEV] Script Date: 04/22/2009 13:22:01 ******/\nCREATE DATABASE [DBGA_DEV] ON PRIMARY \n( NAME = N'DBGA_DEV', FILENAME = N'D:\\GENAPP\\DATA\\DBFILES\\DBGA_DEV.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )\n LOG ON \n( NAME = N'DBGA_DEV_log', FILENAME = N'D:\\GENAPP\\DATA\\DBFILES\\DBGA_DEV_log.ldf' , SIZE = 6208KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)\nGO\n\nALTER DATABASE [DBGA_DEV] SET COMPATIBILITY_LEVEL = 100\nGO\n\nIF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))\nbegin\nEXEC [DBGA_DEV].[dbo].[sp_fulltext_database] @action = 'enable'\nend\nGO\n\nALTER DATABASE [DBGA_DEV] SET ANSI_NULL_DEFAULT OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET ANSI_NULLS OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET ANSI_PADDING ON \nGO\n\nALTER DATABASE [DBGA_DEV] SET ANSI_WARNINGS OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET ARITHABORT OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET AUTO_CLOSE OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET AUTO_CREATE_STATISTICS ON \nGO\n\nALTER DATABASE [DBGA_DEV] SET AUTO_SHRINK OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET AUTO_UPDATE_STATISTICS ON \nGO\n\nALTER DATABASE [DBGA_DEV] SET CURSOR_CLOSE_ON_COMMIT OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET CURSOR_DEFAULT GLOBAL \nGO\n\nALTER DATABASE [DBGA_DEV] SET CONCAT_NULL_YIELDS_NULL OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET NUMERIC_ROUNDABORT OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET QUOTED_IDENTIFIER OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET RECURSIVE_TRIGGERS OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET DISABLE_BROKER \nGO\n\nALTER DATABASE [DBGA_DEV] SET AUTO_UPDATE_STATISTICS_ASYNC OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET DATE_CORRELATION_OPTIMIZATION OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET TRUSTWORTHY OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET ALLOW_SNAPSHOT_ISOLATION OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET PARAMETERIZATION SIMPLE \nGO\n\nALTER DATABASE [DBGA_DEV] SET READ_COMMITTED_SNAPSHOT OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET HONOR_BROKER_PRIORITY OFF \nGO\n\nALTER DATABASE [DBGA_DEV] SET READ_WRITE \nGO\n\nALTER DATABASE [DBGA_DEV] SET RECOVERY FULL \nGO\n\nALTER DATABASE [DBGA_DEV] SET MULTI_USER \nGO\n\nALTER DATABASE [DBGA_DEV] SET PAGE_VERIFY CHECKSUM \nGO\n\nALTER DATABASE [DBGA_DEV] SET DB_CHAINING OFF \nGO\n\nEXEC [DBGA_DEV].sys.sp_addextendedproperty @name=N'DbType', @value=N'DEV' \nGO\n\nEXEC [DBGA_DEV].sys.sp_addextendedproperty @name=N'DbVersion', @value=N'0.0.1.20090414.1100' \nGO\n\n\n\nUSE [DBGA_DEV]\nGO\n/****** Object: Schema [ga] Script Date: 04/22/2009 13:21:29 ******/\nCREATE SCHEMA [ga] AUTHORIZATION [dbo]\nGO\nEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Contains the objects of the Generic Application database' , @level0type=N'SCHEMA',@level0name=N'ga'\nGO\n/****** Object: Table [ga].[tb_DataMeta_ObjChangeLog] Script Date: 04/22/2009 13:21:40 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nSET ANSI_PADDING ON\nGO\nCREATE TABLE [ga].[tb_DataMeta_ObjChangeLog](\n [LogId] [int] IDENTITY(1,1) NOT NULL,\n [TimeStamp] [timestamp] NOT NULL,\n [DatabaseName] [varchar](256) NOT NULL,\n [SchemaName] [varchar](256) NOT NULL,\n [DbVersion] [varchar](20) NOT NULL,\n [DbType] [varchar](20) NOT NULL,\n [EventType] [varchar](50) NOT NULL,\n [ObjectName] [varchar](256) NOT NULL,\n [ObjectType] [varchar](25) NOT NULL,\n [Version] [varchar](50) NULL,\n [SqlCommand] [varchar](max) NOT NULL,\n [EventDate] [datetime] NOT NULL,\n [LoginName] [varchar](256) NOT NULL,\n [FirstName] [varchar](256) NULL,\n [LastName] [varchar](50) NULL,\n [ChangeDescription] [varchar](1000) NULL,\n [Description] [varchar](1000) NULL,\n [ObjVersion] [varchar](20) NOT NULL\n) ON [PRIMARY]\nGO\nSET ANSI_PADDING ON\nGO\nEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The database version as written in the extended prop of the database' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'TABLE',@level1name=N'tb_DataMeta_ObjChangeLog', @level2type=N'COLUMN',@level2name=N'DbVersion'\nGO\nEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'dev , test , qa , fb or prod' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'TABLE',@level1name=N'tb_DataMeta_ObjChangeLog', @level2type=N'COLUMN',@level2name=N'DbType'\nGO\nEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'The name of the object as it is registered in the sys.objects ' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'TABLE',@level1name=N'tb_DataMeta_ObjChangeLog', @level2type=N'COLUMN',@level2name=N'ObjectName'\nGO\nEXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'TABLE',@level1name=N'tb_DataMeta_ObjChangeLog', @level2type=N'COLUMN',@level2name=N'Description'\nGO\nSET IDENTITY_INSERT [ga].[tb_DataMeta_ObjChangeLog] ON\nINSERT [ga].[tb_DataMeta_ObjChangeLog] ([LogId], [DatabaseName], [SchemaName], [DbVersion], [DbType], [EventType], [ObjectName], [ObjectType], [Version], [SqlCommand], [EventDate], [LoginName], [FirstName], [LastName], [ChangeDescription], [Description], [ObjVersion]) VALUES (3, N'DBGA_DEV', N'en', N'0.0.1.20090414.1100', N'DEV', N'DROP_TABLE', N'tb_BL_Products', N'TABLE', N' some', N'<EVENT_INSTANCE><EventType>DROP_TABLE</EventType><PostTime>2009-04-22T11:03:11.880</PostTime><SPID>57</SPID><ServerName>YSG</ServerName><LoginName>ysg\\yordgeor</LoginName><UserName>dbo</UserName><DatabaseName>DBGA_DEV</DatabaseName><SchemaName>en</SchemaName><ObjectName>tb_BL_Products</ObjectName><ObjectType>TABLE</ObjectType><TSQLCommand><SetOptions ANSI_NULLS=\"ON\" ANSI_NULL_DEFAULT=\"ON\" ANSI_PADDING=\"ON\" QUOTED_IDENTIFIER=\"ON\" ENCRYPTED=\"FALSE\"/><CommandText>drop TABLE [en].[tb_BL_Products] --<Version> some</Version>&#x0D;\n</CommandText></TSQLCommand></EVENT_INSTANCE>', CAST(0x00009BF300B6271C AS DateTime), N'ysg\\yordgeor', N'Yordan', N'Georgiev', NULL, NULL, N'0.0.0')\nINSERT [ga].[tb_DataMeta_ObjChangeLog] ([LogId], [DatabaseName], [SchemaName], [DbVersion], [DbType], [EventType], [ObjectName], [ObjectType], [Version], [SqlCommand], [EventDate], [LoginName], [FirstName], [LastName], [ChangeDescription], [Description], [ObjVersion]) VALUES (4, N'DBGA_DEV', N'en', N'0.0.1.20090414.1100', N'DEV', N'CREATE_TABLE', N'tb_BL_Products', N'TABLE', N' 2.2.2 ', N'<EVENT_INSTANCE><EventType>CREATE_TABLE</EventType><PostTime>2009-04-22T11:03:18.620</PostTime><SPID>57</SPID><ServerName>YSG</ServerName><LoginName>ysg\\yordgeor</LoginName><UserName>dbo</UserName><DatabaseName>DBGA_DEV</DatabaseName><SchemaName>en</SchemaName><ObjectName>tb_BL_Products</ObjectName><ObjectType>TABLE</ObjectType><TSQLCommand><SetOptions ANSI_NULLS=\"ON\" ANSI_NULL_DEFAULT=\"ON\" ANSI_PADDING=\"ON\" QUOTED_IDENTIFIER=\"ON\" ENCRYPTED=\"FALSE\"/><CommandText>CREATE TABLE [en].[tb_BL_Products](&#x0D;\n [ProducId] [int] NULL,&#x0D;\n [ProductName] [nchar](10) NULL,&#x0D;\n [ProductDescription] [varchar](5000) NULL&#x0D;\n) ON [PRIMARY]&#x0D;\n/*&#x0D;\n<Version> 2.2.2 </Version>&#x0D;\n&#x0D;\n*/&#x0D;\n</CommandText></TSQLCommand></EVENT_INSTANCE>', CAST(0x00009BF300B62F07 AS DateTime), N'ysg\\yordgeor', N'Yordan', N'Georgiev', NULL, NULL, N'0.0.0')\nINSERT [ga].[tb_DataMeta_ObjChangeLog] ([LogId], [DatabaseName], [SchemaName], [DbVersion], [DbType], [EventType], [ObjectName], [ObjectType], [Version], [SqlCommand], [EventDate], [LoginName], [FirstName], [LastName], [ChangeDescription], [Description], [ObjVersion]) VALUES (5, N'DBGA_DEV', N'en', N'0.0.1.20090414.1100', N'DEV', N'DROP_TABLE', N'tb_BL_Products', N'TABLE', N' 2.2.2 ', N'<EVENT_INSTANCE><EventType>DROP_TABLE</EventType><PostTime>2009-04-22T11:25:12.620</PostTime><SPID>57</SPID><ServerName>YSG</ServerName><LoginName>ysg\\yordgeor</LoginName><UserName>dbo</UserName><DatabaseName>DBGA_DEV</DatabaseName><SchemaName>en</SchemaName><ObjectName>tb_BL_Products</ObjectName><ObjectType>TABLE</ObjectType><TSQLCommand><SetOptions ANSI_NULLS=\"ON\" ANSI_NULL_DEFAULT=\"ON\" ANSI_PADDING=\"ON\" QUOTED_IDENTIFIER=\"ON\" ENCRYPTED=\"FALSE\"/><CommandText>drop TABLE [en].[tb_BL_Products] &#x0D;\n</CommandText></TSQLCommand></EVENT_INSTANCE>', CAST(0x00009BF300BC32F1 AS DateTime), N'ysg\\yordgeor', N'Yordan', N'Georgiev', NULL, NULL, N'0.0.0')\nINSERT [ga].[tb_DataMeta_ObjChangeLog] ([LogId], [DatabaseName], [SchemaName], [DbVersion], [DbType], [EventType], [ObjectName], [ObjectType], [Version], [SqlCommand], [EventDate], [LoginName], [FirstName], [LastName], [ChangeDescription], [Description], [ObjVersion]) VALUES (6, N'DBGA_DEV', N'en', N'0.0.1.20090414.1100', N'DEV', N'CREATE_TABLE', N'tb_BL_Products', N'TABLE', N' 2.2.2 ', N'<EVENT_INSTANCE><EventType>CREATE_TABLE</EventType><PostTime>2009-04-22T11:25:19.053</PostTime><SPID>57</SPID><ServerName>YSG</ServerName><LoginName>ysg\\yordgeor</LoginName><UserName>dbo</UserName><DatabaseName>DBGA_DEV</DatabaseName><SchemaName>en</SchemaName><ObjectName>tb_BL_Products</ObjectName><ObjectType>TABLE</ObjectType><TSQLCommand><SetOptions ANSI_NULLS=\"ON\" ANSI_NULL_DEFAULT=\"ON\" ANSI_PADDING=\"ON\" QUOTED_IDENTIFIER=\"ON\" ENCRYPTED=\"FALSE\"/><CommandText>CREATE TABLE [en].[tb_BL_Products](&#x0D;\n [ProducId] [int] NULL,&#x0D;\n [ProductName] [nchar](10) NULL,&#x0D;\n [ProductDescription] [varchar](5000) NULL&#x0D;\n) ON [PRIMARY]&#x0D;\n/*&#x0D;\n<Version> 2.2.2 </Version>&#x0D;\n&#x0D;\n*/&#x0D;\n</CommandText></TSQLCommand></EVENT_INSTANCE>', CAST(0x00009BF300BC3A69 AS DateTime), N'ysg\\yordgeor', N'Yordan', N'Georgiev', NULL, NULL, N'0.0.0')\nSET IDENTITY_INSERT [ga].[tb_DataMeta_ObjChangeLog] OFF\n/****** Object: Table [ga].[tb_BLSec_LoginsForUsers] Script Date: 04/22/2009 13:21:40 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nSET ANSI_PADDING ON\nGO\nCREATE TABLE [ga].[tb_BLSec_LoginsForUsers](\n [LoginsForUsersId] [int] IDENTITY(1,1) NOT NULL,\n [LoginName] [nvarchar](100) NOT NULL,\n [FirstName] [varchar](100) NOT NULL,\n [SecondName] [varchar](100) NULL,\n [LastName] [varchar](100) NOT NULL,\n [DomainName] [varchar](100) NOT NULL\n) ON [PRIMARY]\nGO\nSET ANSI_PADDING ON\nGO\nSET IDENTITY_INSERT [ga].[tb_BLSec_LoginsForUsers] ON\nINSERT [ga].[tb_BLSec_LoginsForUsers] ([LoginsForUsersId], [LoginName], [FirstName], [SecondName], [LastName], [DomainName]) VALUES (1, N'ysg\\yordgeor', N'Yordan', N'Stanchev', N'Georgiev', N'yordgeor')\nSET IDENTITY_INSERT [ga].[tb_BLSec_LoginsForUsers] OFF\n/****** Object: Table [en].[tb_BL_Products] Script Date: 04/22/2009 13:21:40 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nSET ANSI_PADDING ON\nGO\nCREATE TABLE [en].[tb_BL_Products](\n [ProducId] [int] NULL,\n [ProductName] [nchar](10) NULL,\n [ProductDescription] [varchar](5000) NULL\n) ON [PRIMARY]\nGO\nSET ANSI_PADDING ON\nGO\n/****** Object: StoredProcedure [ga].[procUtils_SqlCheatSheet] Script Date: 04/22/2009 13:21:37 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nCREATE PROCEDURE [ga].[procUtils_SqlCheatSheet] \n\nas \nset nocount on \n\n--what was the name of the table with something like role \n/* \nSELECT * from sys.tables where [name] like '%POC%' \n*/ \n-- what are the columns of this table \n/* \nselect column_name , DATA_TYPE , CHARACTER_MAXIMUM_LENGTH, table_name from Information_schema.columns where table_name='tbGui_ExecutePOC' \n*/ \n\n-- find proc \n--what was the name of procedure with something like role \n/* \nselect * from sys.procedures where [name] like '%ext%' \nexec sp_HelpText procName \n*/ \n/* \nexec sp_helpText procUtils_InsertGenerator \n*/ \n--how to list all databases in sql server \n/* \nSELECT database_id AS ID, NULL AS ParentID, name AS Text FROM sys.databases ORDER BY [name] \n*/ \n\n--HOW-TO LIST ALL TABLES IN A SQL SERVER 2005 DATABASE \n/* \nSELECT TABLE_NAME FROM [POC].INFORMATION_SCHEMA.TABLES \nWHERE TABLE_TYPE = 'BASE TABLE' \nAND TABLE_NAME <> 'dtproperties' \nORDER BY TABLE_NAME \n\n\n*/ \n--HOW-TO ENABLE XP_CMDSHELL START \n------------------------------------------------------------------------- \n-- configure verbose mode temporarily \n-- EXECUTE sp_configure 'show advanced options', 1 \n-- RECONFIGURE WITH OVERRIDE \n--GO \n\n\n--ENABLE xp_cmdshell \n-- EXECUTE sp_configure 'xp_cmdshell', '1' \n-- RECONFIGURE WITH OVERRIDE \n-- EXEC SP_CONFIGURE 'show advanced option', '1'; \n-- SHOW THE CONFIGURATION \n-- EXEC SP_CONFIGURE; \n\n\n--turn show advance options off \n-- GO \n--EXECUTE sp_configure 'show advanced options', 0 \n-- RECONFIGURE WITH OVERRIDE \n-- GO \n\n--HOW-TO ENABLE XP_CMDSHELL END \n------------------------------------------------------------------------- \n\n--HOW-TO IMPLEMENT SLEEP \n-- sleep for 10 seconds \n-- WAITFOR DELAY '00:00:10' SELECT * FROM My_Table \n\n/* LIST ALL PRIMARY KEYS \n\nSELECT \n INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME AS TABLE_NAME, \n INFORMATION_SCHEMA.KEY_COLUMN_USAGE.COLUMN_NAME AS COLUMN_NAME, \n REPLACE(INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_TYPE,' ', '_') AS CONSTRAINT_TYPE \nFROM \n INFORMATION_SCHEMA.TABLE_CONSTRAINTS \n INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE ON \n INFORMATION_SCHEMA.TABLE_CONSTRAINTS.CONSTRAINT_NAME = \n INFORMATION_SCHEMA.KEY_COLUMN_USAGE.CONSTRAINT_NAME \nWHERE \n INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME <> N'sysdiagrams' \nORDER BY \n INFORMATION_SCHEMA.TABLE_CONSTRAINTS.TABLE_NAME ASC \n\n*/ \n\n--HOW-TO COPY TABLE AND THE WHOLE TABLE DATA , COPY TABLE FROM DB TO DB \n--==================================================START \n/* \nuse Poc_Dev \ngo \ndrop table tbGui_LinksVisibility \n\nuse POc_test \ngo \nselect * \nINTO [POC_Dev].[ga].[tbGui_LinksVisibility] \nfrom [POC_TEST].[ga].[tbGui_LinksVisibility] \n\n\n*/ \n--HOW-TO COPY TABLE AND THE WHOLE TABLE DATA , COPY TABLE FROM DB TO DB \n--====================================================END \n--=================================================== SEE TABLE METADATA START \n/* \n\n\n\nSELECT c.name AS [COLUMN_NAME], sc.data_type AS [DATA_TYPE], [value] AS \n[DESCRIPTION] , c.max_length as [MAX_LENGTH] , c.is_nullable AS [OPTIONAL] \n, c.is_identity AS [IS_PRIMARY_KEY] FROM sys.extended_properties AS ep \nINNER JOIN sys.tables AS t ON ep.major_id = t.object_id \nINNER JOIN sys.columns AS c ON ep.major_id = c.object_id AND ep.minor_id \n= c.column_id \nINNER JOIN INFORMATION_SCHEMA.COLUMNS sc ON t.name = sc.table_name and \nc.name = sc.column_name \nWHERE class = 1 and t.name = 'tbGui_ExecutePOC' ORDER BY SC.DATA_TYPE \n\n\n*/ \n--=================================================== SEE TABLE METADATA END \n /* \nselect * from Information_schema.columns \nselect table_name , column_name from Information_schema.columns where table_name='tbGui_Wizards' \n */ \n\n\n--=================================================== LIST ALL TABLES AND THEIR DESCRIPTOINS START \n/* \n\nSELECT T.name AS TableName, CAST(Props.value AS varchar(1000)) AS \nTableDescription \nFROM sys.tables AS T LEFT OUTER JOIN \n(SELECT class, class_desc, major_id, minor_id, \nname, value \nFROM sys.extended_properties \nWHERE (minor_id = 0) AND (class = 1)) AS \nProps ON T.object_id = Props.major_id \nWHERE (T.type = 'U') AND (T.name <> N'sysdiagrams') \nORDER BY TableName \n*/ \n--=================================================== LIST ALL TABLES AND THEIR DESCRIPTOINS START \n\n--=================================================== LIST ALL OBJECTS FROM DB START \n/* \n\n\nuse DB \n--HOW-TO LIST ALL PROCEDURE IN A DATABASE \nselect s.name from sysobjects s where type = 'P' \n--HOW-TO LIST ALL TRIGGERS BY NAME IN A DATABASE \nselect s.name from sysobjects s where type = 'TR' \n--HOW-TO LIST TABLES IN A DATABASE \nselect s.name from sysobjects s where type = 'U' \n--how-to list all system tables in a database \nselect s.name from sysobjects s where type = 's' \n--how-to list all the views in a database \nselect s.name from sysobjects s where type = 'v' \n\n\n*/ \n\n/* \nSimilarly you can find out other objects created by user, simple change type = \n\nC = CHECK constraint \n\nD = Default or DEFAULT constraint \n\nF = FOREIGN KEY constraint \n\nL = Log \n\nFN = Scalar function \n\nIF = In-lined table-function \n\nP = Stored procedure \n\nPK = PRIMARY KEY constraint (type is K) \n\nRF = Replication filter stored procedure \n\nS = System table \n\nTF = Table function \n\nTR = Trigger \n\nU = User table ( this is the one I discussed above in the example) \n\nUQ = UNIQUE constraint (type is K) \n\nV = View \n\nX = Extended stored procedure \n*/ \n\n\n\n--=================================================== HOW-TO SEE ALL MY PERMISSIONS START \n\n\n/* \n\nSELECT * FROM fn_my_permissions(NULL, 'SERVER'); \nUSE poc_qa; \nSELECT * FROM fn_my_permissions (NULL, 'database'); \nGO \n\n*/ \n--=================================================== HOW-TO SEE ALL MY PERMISSIONS END \n\n/* \n--find table \n\nuse poc_dev \ngo \nselect s.name from sysobjects s where type = 'u' and s.name like '%Visibility%' \nselect * from tbGui_LinksVisibility \n\n*/ \n\n/* find cursor \n\nuse poc \ngo \nDECLARE @procName varchar(100) \nDECLARE @cursorProcNames CURSOR \nSET @cursorProcNames = CURSOR FOR \nselect name from sys.procedures where modify_date > '2009-02-05 13:12:15.273' order by modify_date desc \n\nOPEN @cursorProcNames \nFETCH NEXT \nFROM @cursorProcNames INTO @procName \nWHILE @@FETCH_STATUS = 0 \nBEGIN \n\nset nocount off; \nexec sp_HelpText @procName --- or print them \n-- print @procName \n\nFETCH NEXT \nFROM @cursorProcNames INTO @procName \nEND \nCLOSE @cursorProcNames \n\nselect @@error \n\n*/ \n\n\n/* -- SEE STORED PROCEDURE EXT PROPS \n\nSELECT ep.name as 'EXT_PROP_NAME' , SP.NAME , [value] as 'DESCRIPTION' FROM sys.extended_properties as ep left join sys.procedures as sp on sp.object_id = ep.major_id where sp.type='P' \n\n\n-- what the hell I ve been doing lately on sql server 2005 / 2008\nselect o.name , \n(SELECT [definition] AS [text()] FROM sys.all_sql_modules where sys.all_sql_modules.object_id=a.object_id FOR XML PATH(''), TYPE) AS Statement_Text\n, a.object_id, o.modify_date from sys.all_sql_modules a left join sys.objects o on a.object_id=o.object_id order by 4 desc\n\n\n\n-- GET THE RIGHT LANG SCHEMA START \nDECLARE @template AS varchar(max)\nSET @template = 'SELECT * FROM {object_name}'\n\nDECLARE @object_name AS sysname\n\nSELECT @object_name = QUOTENAME(s.name) + '.' + QUOTENAME(o.name)\nFROM sys.objects o\nINNER JOIN sys.schemas s\n ON s.schema_id = o.schema_id\nWHERE o.object_id = OBJECT_ID(QUOTENAME(@LANG) + '.[TestingLanguagesInNameSpacesDelMe]')\n\nIF @object_name IS NOT NULL\nBEGIN\n DECLARE @sql AS varchar(max)\n SET @sql = REPLACE(@template, '{object_name}', @object_name)\n EXEC (@sql)\nEND\n-- GET THE RIGHT LANG SCHEMA END \n\n-- SEE STORED PROCEDURE EXT PROPS end*/ \nset nocount off\nGO\nEXEC sys.sp_addextendedproperty @name=N'AuthorName', @value=N'Yordan Georgiev' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'PROCEDURE',@level1name=N'procUtils_SqlCheatSheet'\nGO\nEXEC sys.sp_addextendedproperty @name=N'ProcDescription', @value=N'TODO:ADD HERE DESCRPIPTION' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'PROCEDURE',@level1name=N'procUtils_SqlCheatSheet'\nGO\nEXEC sys.sp_addextendedproperty @name=N'ProcVersion', @value=N'0.1.0.20090406.1317' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'PROCEDURE',@level1name=N'procUtils_SqlCheatSheet'\nGO\n/****** Object: UserDefinedFunction [ga].[GetDbVersion] Script Date: 04/22/2009 13:21:42 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nCREATE FUNCTION [ga].[GetDbVersion]()\nRETURNS VARCHAR(20)\n BEGIN\n RETURN convert(varchar(20) , (select value from sys.extended_properties where name='DbVersion' and class_desc='DATABASE') )\n END\nGO\nEXEC sys.sp_addextendedproperty @name=N'AuthorName', @value=N'Yordan Georgiev' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'FUNCTION',@level1name=N'GetDbVersion'\nGO\nEXEC sys.sp_addextendedproperty @name=N'ChangeDescription', @value=N'Initial creation' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'FUNCTION',@level1name=N'GetDbVersion'\nGO\nEXEC sys.sp_addextendedproperty @name=N'CreatedWhen', @value=N'getDate()' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'FUNCTION',@level1name=N'GetDbVersion'\nGO\nEXEC sys.sp_addextendedproperty @name=N'Description', @value=N'Gets the current version of the database ' , @level0type=N'SCHEMA',@level0name=N'ga', @level1type=N'FUNCTION',@level1name=N'GetDbVersion'\nGO\n/****** Object: UserDefinedFunction [ga].[GetDbType] Script Date: 04/22/2009 13:21:42 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\nCREATE FUNCTION [ga].[GetDbType]()\nRETURNS VARCHAR(30)\n BEGIN\n RETURN convert(varchar(30) , (select value from sys.extended_properties where name='DbType' and class_desc='DATABASE') )\n END\nGO\n/****** Object: Default [DF_tb_DataMeta_ObjChangeLog_DbVersion] Script Date: 04/22/2009 13:21:40 ******/\nALTER TABLE [ga].[tb_DataMeta_ObjChangeLog] ADD CONSTRAINT [DF_tb_DataMeta_ObjChangeLog_DbVersion] DEFAULT ('select ga.GetDbVersion()') FOR [DbVersion]\nGO\n/****** Object: Default [DF_tb_DataMeta_ObjChangeLog_EventDate] Script Date: 04/22/2009 13:21:40 ******/\nALTER TABLE [ga].[tb_DataMeta_ObjChangeLog] ADD CONSTRAINT [DF_tb_DataMeta_ObjChangeLog_EventDate] DEFAULT (getdate()) FOR [EventDate]\nGO\n/****** Object: Default [DF_tb_DataMeta_ObjChangeLog_ObjVersion] Script Date: 04/22/2009 13:21:40 ******/\nALTER TABLE [ga].[tb_DataMeta_ObjChangeLog] ADD CONSTRAINT [DF_tb_DataMeta_ObjChangeLog_ObjVersion] DEFAULT ('0.0.0') FOR [ObjVersion]\nGO\n/****** Object: DdlTrigger [trigMetaDoc_TraceDbChanges] Script Date: 04/22/2009 13:21:29 ******/\nSET ANSI_NULLS ON\nGO\nSET QUOTED_IDENTIFIER ON\nGO\ncreate trigger [trigMetaDoc_TraceDbChanges]\non database\nfor create_procedure, alter_procedure, drop_procedure,\ncreate_table, alter_table, drop_table,\ncreate_function, alter_function, drop_function , \ncreate_trigger , alter_trigger , drop_trigger \nas\n\nset nocount on\n\ndeclare @data xml\nset @data = EVENTDATA()\ndeclare @DbVersion varchar(20)\nset @DbVersion =(select ga.GetDbVersion())\ndeclare @DbType varchar(20)\nset @DbType =(select ga.GetDbType())\ndeclare @DbName varchar(256)\nset @DbName =@data.value('(/EVENT_INSTANCE/DatabaseName)[1]', 'varchar(256)')\ndeclare @EventType varchar(256)\nset @EventType =@data.value('(/EVENT_INSTANCE/EventType)[1]', 'varchar(50)')\ndeclare @ObjectName varchar(256)\nset @ObjectName = @data.value('(/EVENT_INSTANCE/ObjectName)[1]', 'varchar(256)')\ndeclare @ObjectType varchar(25)\nset @ObjectType = @data.value('(/EVENT_INSTANCE/ObjectType)[1]', 'varchar(25)')\ndeclare @TSQLCommand varchar(max)\nset @TSQLCommand = @data.value('(/EVENT_INSTANCE/TSQLCommand)[1]', 'varchar(max)')\ndeclare @opentag varchar(4)\nset @opentag= '&lt;'\ndeclare @closetag varchar(4) \nset @closetag= '&gt;'\ndeclare @newDataTxt varchar(max) \nset @newDataTxt= cast(@data as varchar(max))\nset @newDataTxt = REPLACE ( REPLACE(@newDataTxt , @opentag , '<') , @closetag , '>')\n-- print @newDataTxt\ndeclare @newDataXml xml \nset @newDataXml = CONVERT ( xml , @newDataTxt)\ndeclare @Version varchar(50)\nset @Version = @newDataXml.value('(/EVENT_INSTANCE/TSQLCommand/CommandText/Version)[1]', 'varchar(50)')\n\n-- if we are dropping take the version from the existing object \nif ( SUBSTRING(@EventType , 0 , 5)) = 'DROP'\nset @Version =( select top 1 [Version] from ga.tb_DataMeta_ObjChangeLog where ObjectName=@ObjectName order by [LogId] desc)\n\n\n\ndeclare @LoginName varchar(256) \nset @LoginName = @data.value('(/EVENT_INSTANCE/LoginName)[1]', 'varchar(256)')\ndeclare @FirstName varchar(50)\nset @FirstName= (select [FirstName] from [ga].[tb_BLSec_LoginsForUsers] where [LoginName] = @LoginName)\ndeclare @LastName varchar(50)\nset @LastName = (select [LastName] from [ga].[tb_BLSec_LoginsForUsers] where [LoginName] = @LoginName)\ndeclare @SchemaName sysname \nset @SchemaName = @data.value('(/EVENT_INSTANCE/SchemaName)[1]', 'sysname');\n--declare @Description xml \n--set @Description = @data.query('(/EVENT_INSTANCE/TSQLCommand/text())')\n\n\n\n\n--print 'VERSION IS ' + @Version\n--print @newDataTxt\n--print cast(@data as varchar(max))\n\n\n-- select column_name from information_schema.columns where table_name ='tb_DataMeta_ObjChangeLog'\ninsert into [ga].[tb_DataMeta_ObjChangeLog]\n(\n[DatabaseName] ,\n[SchemaName],\n[DbVersion] ,\n[DbType],\n[EventType],\n[ObjectName],\n[ObjectType] ,\n[Version],\n[SqlCommand] ,\n[LoginName] ,\n[FirstName],\n[LastName] \n)\n\nvalues(\n\n@DbName,\n@SchemaName,\n@DbVersion,\n@DbType,\n@EventType, \n@ObjectName, \n@ObjectType , \n@Version,\n@newDataTxt, \n@LoginName , \n@FirstName , \n@LastName\n)\nGO\nSET ANSI_NULLS OFF\nGO\nSET QUOTED_IDENTIFIER OFF\nGO\nDISABLE TRIGGER [trigMetaDoc_TraceDbChanges] ON DATABASE\nGO\n/****** Object: DdlTrigger [trigMetaDoc_TraceDbChanges] Script Date: 04/22/2009 13:21:29 ******/\nEnable Trigger [trigMetaDoc_TraceDbChanges] ON Database\nGO\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115369", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16082/" ]
115,389
<p>How do you update your SQL sever database when installing your product's update? Are there any tools that will integrate with windows installer? My typical schema changes are:</p> <ul> <li>Adding/removing columns</li> <li>Adding/removing tables.</li> <li>Adding views.</li> <li>Adding/alter indexs.</li> </ul>
[ { "answer_id": 116254, "author": "Philippe Grondier", "author_id": 11436, "author_profile": "https://Stackoverflow.com/users/11436", "pm_score": 0, "selected": false, "text": "//instruction 1, batch instructions for version#2.162\nUSE myDatabase\nGO\nALTER TABLE myTable\n ADD myColumn uniqueIdentifier Null\nGO\n//instruction 2, batch instructions for version#2.162\nUSE myDatabase\nALTER TABLE myTable\n ADD CONSTRAINT myTable_myColumn FOREIGN KEY (myColumn) ...\nGO\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5618/" ]
115,399
<p>My credit card processor requires I send a two-digit year from the credit card expiration date. Here is how I am currently processing:</p> <ol> <li>I put a <code>DropDownList</code> of the 4-digit year on the page.</li> <li>I validate the expiration date in a <code>DateTime</code> field to be sure that the expiration date being passed to the CC processor isn't expired.</li> <li>I send a two-digit year to the CC processor (as required). I do this via a substring of the value from the year DDL.</li> </ol> <p>Is there a method out there to convert a four-digit year to a two-digit year. I am not seeing anything on the <code>DateTime</code> object. Or should I just keep processing it as I am?</p>
[ { "answer_id": 115440, "author": "brock.holum", "author_id": 15860, "author_profile": "https://Stackoverflow.com/users/15860", "pm_score": 8, "selected": true, "text": "DateTime expirationDate = new DateTime(2008, 1, 31); // random date\nstring lastTwoDigitsOfYear = expirationDate.ToString(\"yy\");\n" }, { "answer_id": 115480, "author": "Seb Nilsson", "author_id": 2429, "author_profile": "https://Stackoverflow.com/users/2429", "pm_score": 3, "selected": false, "text": "public int Get4LetterYear(int twoLetterYear)\n{\n int firstTwoDigits =\n Convert.ToInt32(DateTime.Now.Year.ToString().Substring(2, 2));\n return Get4LetterYear(twoLetterYear, firstTwoDigits);\n}\n\npublic int Get4LetterYear(int twoLetterYear, int firstTwoDigits)\n{\n return Convert.ToInt32(firstTwoDigits.ToString() + twoLetterYear.ToString());\n}\n\npublic int Get2LetterYear(int fourLetterYear)\n{\n return Convert.ToInt32(fourLetterYear.ToString().Substring(2, 2));\n}\n" }, { "answer_id": 115494, "author": "Harv", "author_id": 10004, "author_profile": "https://Stackoverflow.com/users/10004", "pm_score": 0, "selected": false, "text": "'Create a var. named rightNow and set it to the current date/time\nDim rightNow as DateTime = DateTime.Now\nDim s as String 'create a string\n\ns = rightNow.ToString(\"MMM dd, yyyy\")\n" }, { "answer_id": 5685703, "author": "V.K.D Baghel", "author_id": 711026, "author_profile": "https://Stackoverflow.com/users/711026", "pm_score": 2, "selected": false, "text": "//using java script\nvar curDate = new Date();\nvar curYear = curDate.getFullYear();\ncurYear = curYear.toString().slice(2);\ndocument.write(curYear)\n//using java script\n//using sqlserver\nselect Right(Year(getDate()),2)\n//using sql server\n//Using c#.net \nDateTime dt = DateTime.Now;\n string curYear = dt.Year.ToString().Substring(2,2).ToString() ;\n//using c#.net\n" }, { "answer_id": 6235347, "author": "Phiplex", "author_id": 783708, "author_profile": "https://Stackoverflow.com/users/783708", "pm_score": 1, "selected": false, "text": "DateTime.Now.Year - (DateTime.Now.Year / 100 * 100)\n DateTime.Now.Year" }, { "answer_id": 23782904, "author": "Chris W", "author_id": 890258, "author_profile": "https://Stackoverflow.com/users/890258", "pm_score": 6, "selected": false, "text": "yourDateTime.Year % 100\n yourDateTime.ToString(\"yy\")\n" }, { "answer_id": 30935175, "author": "Christian Phillips", "author_id": 1449181, "author_profile": "https://Stackoverflow.com/users/1449181", "pm_score": 0, "selected": false, "text": "ExtensionMethod public static class DateTimeExtensions\n {\n public static int ToYearLastTwoDigit(this DateTime date)\n {\n var temp = date.ToString(\"yy\");\n return int.Parse(temp);\n }\n }\n DateTime var dateTime = new DateTime(2015, 06, 19);\nvar year = cob.ToYearLastTwoDigit();\n" }, { "answer_id": 40234891, "author": "Iliass Nassibane", "author_id": 5847256, "author_profile": "https://Stackoverflow.com/users/5847256", "pm_score": 1, "selected": false, "text": "DateTime Today = DateTime.Today;\nstring zeroBased = Today.ToString(\"yy-MM-dd\");\n" }, { "answer_id": 44357335, "author": "Sadid Khan", "author_id": 1999720, "author_profile": "https://Stackoverflow.com/users/1999720", "pm_score": 4, "selected": false, "text": "DateTime.Now.Year.ToString(\"yy\"); DateTime.Now.ToString(\"yy\");" }, { "answer_id": 53219298, "author": "John", "author_id": 7297374, "author_profile": "https://Stackoverflow.com/users/7297374", "pm_score": 0, "selected": false, "text": "yourDateTime.ToString().Substring(2);" }, { "answer_id": 67874599, "author": "JakeMc", "author_id": 2859272, "author_profile": "https://Stackoverflow.com/users/2859272", "pm_score": 2, "selected": false, "text": "DateTime date = DateTime.Now;\n\nstring myTwoDigitYear = $\"{date:yy};\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115399", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2535/" ]
115,418
<p>How to get an instance's member's values?</p> <p>With propertyInfos there is a <code>propertyInfo.GetValue(instance, index)</code>, but no such thing exists in memberInfo.</p> <p>I searched the net, but it seems to stop at getting the member's name and type.</p>
[ { "answer_id": 115429, "author": "Matt Howells", "author_id": 16881, "author_profile": "https://Stackoverflow.com/users/16881", "pm_score": 5, "selected": true, "text": "FieldInfo" }, { "answer_id": 8801597, "author": "Carlo V. Dango", "author_id": 454017, "author_profile": "https://Stackoverflow.com/users/454017", "pm_score": 5, "selected": false, "text": "FieldInfo PropertyInfo switch (memberInfo)\n{\n case FieldInfo fieldInfo:\n return fieldInfo.GetValue(obj);\n case PropertyInfo propertyInfo:\n return propertyInfo.GetValue(obj);\n default:\n throw new InvalidOperationException();\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11333/" ]
115,420
<p>When trying to run the Flex Builder 3 profiler on any I don't get the profiler dialog window and then after a few seconds I get "Socket timeout" in the console window. Any ideas why it can't connect?</p> <p>I've got the latest debug version of Flash player and have tried shutting off my firewall.<br> I'm running it on XP from the local drive, ie. not through localhost.</p> <p>Thanks, Alex</p>
[ { "answer_id": 1092530, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation:\n file:///C|%2Fwork%2Flabsense%2Fbranches%2Frel%5F1%5F2%5F5%5FEA%2Fsources%2Fui%2F.metadata%2F.plugins%2Fcom.adobe.flash.profiler%2FProfilerAgent.swf?host=localhost&port=9999\n cannot load data from localhost:9999.\n at ProfilerAgent()[C:\\SVN\\branches\\3.2.0\\modules\\profiler3\\as\\ProfilerAgent.as:127]\n PreloadSwf=C:\\work\\labsense\\Sources\\ui\\.metadata\\.plugins\\com.adobe.flash.profiler\\ProfilerAgent.swf?host=localhost&port=9999 \n PreloadSwf=C:\\work\\labsense\\Sources\\ui\\.metadata\\.plugins\\com.adobe.flash.profiler\\ProfilerAgent.swf?host=localhost&port=9998\n PreloadSwf=C:/work/labsense/Sources/ui/.metadata/.plugins/com.adobe.flash.profiler/ProfilerAgent.swf?host=localhost&port=9999\n PreloadSwf=C: \\ work \\ labsense \\ Sources \\ ui \\ .metadata \\ .plugins \\ com.adobe.flash.profiler \\ ProfilerAgent.swf?host=localhost&port=9999\n C:\\work\\labsense\\Sources\\ui\\.metadata\\.plugins\\com.adobe.flash.profiler\\ProfilerAgent.swf?\n TraceOutputFileName=C:\\Users\\zivo\\AppData\\Roaming\\Macromedia\\Flash Player\\Logs\\flashlog.txt\nErrorReportingEnable=1\nMaxWarnings=0\nTraceOutputFileEnable=1\nProfilingFileOutputEnable=1\n PreloadSwf=C:/work/labsense/branches/rel_1_2_5_EA/sources/ui/.metadata/.plugins/com.adobe.flash.profiler/ProfilerAgent.swf?host=127.0.0.1&port=9999\n # Copyright (c) 1993-2006 Microsoft Corp.\n#\n# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.\n#\n# This file contains the mappings of IP addresses to host names. Each\n# entry should be kept on an individual line. The IP address should\n# be placed in the first column followed by the corresponding host name.\n# The IP address and the host name should be separated by at least one\n# space.\n#\n# Additionally, comments (such as these) may be inserted on individual\n# lines or following the machine name denoted by a '#' symbol.\n#\n# For example:\n#\n# 102.54.94.97 rhino.acme.com # source server\n# 38.25.63.10 x.acme.com # x client host\n\n::1 localhost\n127.0.0.1 iDBO # LMS GENERATED LINE\n # ::1 localhost\n# 127.0.0.1 iDBO # LMS GENERATED LINE\n127.0.0.1 localhost\n" }, { "answer_id": 9336949, "author": "Eric Hedstrom", "author_id": 775398, "author_profile": "https://Stackoverflow.com/users/775398", "pm_score": 0, "selected": false, "text": "PreloadSwf=C:\\Users\\ehedstrom\\Documents\\FLEXBU~1\\.metadata\\.plugins\\com.adobe.flash.profiler\\ProfilerAgent.swf?host=localhost&port=9999\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15899/" ]
115,425
<p>Aside from trying</p> <pre><code>perldoc &lt;module name&gt; </code></pre> <p>individually for any CPAN module that takes my fancy or going through the file system and looking at the directories I have no idea what modules we have installed. </p> <p>What's the easiest way to just get a big list of every CPAN module installed? From the command line or otherwise.</p>
[ { "answer_id": 115439, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 5, "selected": false, "text": "perldoc perllocal\n" }, { "answer_id": 115564, "author": "amoore", "author_id": 7573, "author_profile": "https://Stackoverflow.com/users/7573", "pm_score": 3, "selected": false, "text": "sudo perl -MCPAN -e shell\n sudo cpan\n" }, { "answer_id": 115793, "author": "shelfoo", "author_id": 3444, "author_profile": "https://Stackoverflow.com/users/3444", "pm_score": 3, "selected": false, "text": "\nfor my $path (@INC) {\n my @list = `ls -R $path/**/*.pm`;\n for (@list) {\n s/$path\\///g;\n s/\\//::/g;\n s/\\.pm$//g;\n print;\n }\n}\n" }, { "answer_id": 117386, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 4, "selected": false, "text": ".packlist @INC cpan -l cpan -a" }, { "answer_id": 117771, "author": "dland", "author_id": 18625, "author_profile": "https://Stackoverflow.com/users/18625", "pm_score": 1, "selected": false, "text": "File::Find::Rule #! /usr/bin/perl -l\n\nuse strict;\nuse warnings;\nuse File::Find::Rule;\n\nmy %seen;\nfor my $path (@INC) {\n for my $file (File::Find::Rule->name('*.pm')->in($path)) {\n my $module = substr($file, length($path)+1);\n $module =~ s/.pm$//;\n $module =~ s{[\\\\/]}{::}g;\n print $module unless $seen{$module}++;\n }\n}\n" }, { "answer_id": 118855, "author": "pjf", "author_id": 19422, "author_profile": "https://Stackoverflow.com/users/19422", "pm_score": 7, "selected": true, "text": "perldoc -q installed ExtUtils::Installed File::Find" }, { "answer_id": 931074, "author": "Sinan Ünür", "author_id": 100754, "author_profile": "https://Stackoverflow.com/users/100754", "pm_score": 2, "selected": false, "text": "perldoc perltoc\n" }, { "answer_id": 931213, "author": "aks", "author_id": 2533756, "author_profile": "https://Stackoverflow.com/users/2533756", "pm_score": 1, "selected": false, "text": "perl perlmod.pl\n perl perlmod.pl <module name> #Case-insensitive(eg. perl perlmod.pl ftp)\n grep { $_ !~ '^\\.$' } @INC\n @INC\n" }, { "answer_id": 934268, "author": "Walter H", "author_id": 115384, "author_profile": "https://Stackoverflow.com/users/115384", "pm_score": 2, "selected": false, "text": "man perllocal perldoc perllocal" }, { "answer_id": 5577447, "author": "Joakim", "author_id": 305996, "author_profile": "https://Stackoverflow.com/users/305996", "pm_score": 4, "selected": false, "text": "use ExtUtils::Installed;\n\nmy $inst = ExtUtils::Installed->new();\nmy @modules = $inst->modules();\nforeach $module (@modules){\n print $module .\" - \". $inst->version($module). \"\\n\";\n}\n\n=head1 ABOUT\n\nThis scripts lists installed cpan modules using the ExtUtils modules\n\n=head1 FORMAT\n\nPrints each module in the following format\n<name> - <version>\n\n=cut\n" }, { "answer_id": 7112891, "author": "thealexbaron", "author_id": 407164, "author_profile": "https://Stackoverflow.com/users/407164", "pm_score": 0, "selected": false, "text": "perl -MExtUtils::Installed -MData::Dumper -e 'my ($inst) = ExtUtils::Installed->new(); print Dumper($inst->modules());'\n" }, { "answer_id": 14598354, "author": "user2024286", "author_id": 2024286, "author_profile": "https://Stackoverflow.com/users/2024286", "pm_score": 3, "selected": false, "text": "instmodsh\n l" }, { "answer_id": 14599339, "author": "slayedbylucifer", "author_id": 1251660, "author_profile": "https://Stackoverflow.com/users/1251660", "pm_score": 3, "selected": false, "text": "perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\\.pm\\z/ }, no_chdir => 1 }, @INC'\n" }, { "answer_id": 15166368, "author": "Paul Rubel", "author_id": 351984, "author_profile": "https://Stackoverflow.com/users/351984", "pm_score": 5, "selected": false, "text": "perldoc -q installed cpan -l cpan -a" }, { "answer_id": 19976944, "author": "Thiyagu ATR", "author_id": 1859477, "author_profile": "https://Stackoverflow.com/users/1859477", "pm_score": 3, "selected": false, "text": "instmodsh l - List all installed modules\n m <module> - Select a module\n q - Quit the program\n" }, { "answer_id": 21918638, "author": "mpersico", "author_id": 1830614, "author_profile": "https://Stackoverflow.com/users/1830614", "pm_score": 0, "selected": false, "text": "cd /the/lib/dir/of/your/perl/installation\nperldoc $(find . -name perllocal.pod)\n" }, { "answer_id": 30671631, "author": "Dan", "author_id": 3884826, "author_profile": "https://Stackoverflow.com/users/3884826", "pm_score": 5, "selected": false, "text": "$ for M in `perldoc -t perllocal|grep Module |sed -e 's/^.*\" //'`; do V=`perldoc -t perllocal|awk \"/$M/{y=1;next}y\" |grep VERSION |head -n 1`; printf \"%30s %s\\n\" \"$M\" \"$V\"; done |sort\n Class::Inspector * \"VERSION: 1.28\"\n Crypt::CBC * \"VERSION: 2.33\"\n Crypt::Rijndael * \"VERSION: 1.11\"\n Data::Dump * \"VERSION: 1.22\"\n DBD::Oracle * \"VERSION: 1.68\"\n DBI * \"VERSION: 1.630\"\n Digest::SHA * \"VERSION: 5.92\"\n ExtUtils::MakeMaker * \"VERSION: 6.84\"\n install * \"VERSION: 6.84\"\n IO::SessionData * \"VERSION: 1.03\"\n IO::Socket::SSL * \"VERSION: 2.016\"\n JSON * \"VERSION: 2.90\"\n MIME::Base64 * \"VERSION: 3.14\"\n MIME::Base64 * \"VERSION: 3.14\"\n Mozilla::CA * \"VERSION: 20141217\"\n Net::SSLeay * \"VERSION: 1.68\"\n parent * \"VERSION: 0.228\"\n REST::Client * \"VERSION: 271\"\n SOAP::Lite * \"VERSION: 1.08\"\n Task::Weaken * \"VERSION: 1.04\"\n Term::ReadKey * \"VERSION: 2.31\"\n Test::Manifest * \"VERSION: 1.23\"\n Test::Simple * \"VERSION: 1.001002\"\n Text::CSV_XS * \"VERSION: 1.16\"\n Try::Tiny * \"VERSION: 0.22\"\n XML::LibXML * \"VERSION: 2.0108\"\n XML::NamespaceSupport * \"VERSION: 1.11\"\n XML::SAX::Base * \"VERSION: 1.08\"\n" }, { "answer_id": 44709219, "author": "caot", "author_id": 3882744, "author_profile": "https://Stackoverflow.com/users/3882744", "pm_score": 1, "selected": false, "text": "$ perldoc perllocal | grep Module\n$ perldoc perllocal | grep -E 'VERSION|Module'\n" }, { "answer_id": 45776727, "author": "Henrik", "author_id": 5725091, "author_profile": "https://Stackoverflow.com/users/5725091", "pm_score": -1, "selected": false, "text": "#!/bin/bash\n\necho -e -n \"Content-type: text/plain\\n\\n\"\n\ninc=`perl -e '$, = \"\\n\"; print @INC;'`\n\nfor d in $inc\ndo\n find $d -name '*.pm'\ndone\n" }, { "answer_id": 47173830, "author": "Yasiru G", "author_id": 1383889, "author_profile": "https://Stackoverflow.com/users/1383889", "pm_score": -1, "selected": false, "text": "dpkg -l | grep \"perl\"\n" }, { "answer_id": 52566268, "author": "Wernfried Domscheit", "author_id": 3027266, "author_profile": "https://Stackoverflow.com/users/3027266", "pm_score": 3, "selected": false, "text": "perl -e 'print qx/find $_ -name \"*.pm\"/ foreach ( @INC );' \n @INC" }, { "answer_id": 58114369, "author": "user2967328", "author_id": 2967328, "author_profile": "https://Stackoverflow.com/users/2967328", "pm_score": 2, "selected": false, "text": "grep -RhIP '^package [A-Z][\\w:]+;' `perl -e 'print join \" \",@INC'` | sed 's/package //' | sort | uniq\n grep -RhIP '^package [A-Z][\\w:]+;' `perl -e 'print join \" \",@INC'` | sed 's/package //' | sort | uniq > modules-installed\n cat modules-installed | grep -i dbm \n\nAnyDBM_File;\nMemoize::AnyDBM_File;\nMemoize::NDBM_File;\nMemoize::SDBM_File;\nWWW::RobotRules::AnyDBM_File;\n" }, { "answer_id": 64310781, "author": "Nicholas Sushkin", "author_id": 789544, "author_profile": "https://Stackoverflow.com/users/789544", "pm_score": 2, "selected": false, "text": "perl -MExtUtils::Installed -e '$i=ExtUtils::Installed->new(); \n print \"$_ \".$i->version($_).\"\\n\" for $i->modules();'\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115425", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3404/" ]
115,426
<p>I'm looking for an algorithm to detect if two rectangles intersect (one at an arbitrary angle, the other with only vertical/horizontal lines).</p> <p>Testing if a corner of one is in the other ALMOST works. It fails if the rectangles form a cross-like shape.</p> <p>It seems like a good idea to avoid using slopes of the lines, which would require special cases for vertical lines.</p>
[ { "answer_id": 115520, "author": "Nils Pipenbrinck", "author_id": 15955, "author_profile": "https://Stackoverflow.com/users/15955", "pm_score": 8, "selected": true, "text": " edge = v(n) - v(n-1)\n rotated.x = -unrotated.y\n rotated.y = unrotated.x\n // rotated: your rotated edge\n // v(n-1) any point from the edge.\n // testpoint: the point you want to find out which side it's on.\n\n side = sign (rotated.x * (testpoint.x - v(n-1).x) + \n rotated.y * (testpoint.y - v(n-1).y);\n" }, { "answer_id": 13550752, "author": "tristan", "author_id": 1109630, "author_profile": "https://Stackoverflow.com/users/1109630", "pm_score": 2, "selected": false, "text": "struct Rect {\n x, // the center in x axis\n y, // the center in y axis\n width,\n height\n}\n if Math.abs(rectA.x - rectB.x) < (Math.abs(rectA.width + rectB.width) / 2) \n&& (Math.abs(rectA.y - rectB.y) < (Math.abs(rectA.height + rectB.height) / 2))\n then\n // A and B collide\n end if\n struct RotatedRect : Rect {\n double angle; // the rotating angle oriented to its center\n}\n Math.sqrt(rectA.width*rectA.width + rectA.height*rectA.height) * Math.cos(rectA.angle) Math.sqrt(rectB.width*rectB.width + rectB.height*rectB.height) * Math.cos(rectB.angle) if Math.abs(rectA.x - rectB.x) < (Math.abs(widthA' + widthB') / 2) \n&& (Math.abs(rectA.y - rectB.y) < (Math.abs(heightA' + heightB') / 2))\n then\n // A and B collide\n end if\n" }, { "answer_id": 13878566, "author": "Leonardo", "author_id": 1903977, "author_profile": "https://Stackoverflow.com/users/1903977", "pm_score": 2, "selected": false, "text": "- (BOOL)DoesThisRectSelectMe:(NSRect)selectedArea\n{\n NSRect localArea = [self convertRect:selectedArea fromView:self.superview];\n\n return NSIntersectsRect(localArea, self.bounds);\n}\n\n\n- (NSView *)hitTest:(NSPoint)aPoint\n{\n NSPoint localPoint = [self convertPoint:aPoint fromView:self.superview];\n return NSPointInRect(localPoint, self.bounds) ? self : nil;\n}\n" }, { "answer_id": 14145813, "author": "user1517108", "author_id": 1517108, "author_profile": "https://Stackoverflow.com/users/1517108", "pm_score": 0, "selected": false, "text": " xIntersect = false;\n yIntersect = false;\n if (!(Math.min(x1, x2, x3, x4) > Math.max(X1, X2, X3, X4) || Math.max(x1, x2, x3, x4) < Math.min(X1, X2, X3, X4))) xIntersect = true;\n if (!(Math.min(y1, y2, y3, y4) > Math.max(Y1, Y2, Y3, Y4) || Math.max(y1, y2, y3, y4) < Math.min(Y1, Y2, Y3, Y4))) yIntersect = true;\n if (xIntersect && yIntersect) {alert(\"Intersect\");}\n" }, { "answer_id": 15444203, "author": "Robotbugs", "author_id": 986059, "author_profile": "https://Stackoverflow.com/users/986059", "pm_score": 0, "selected": false, "text": "bool rectCollision(const CGRect &boundsA, const Matrix3x3 &mB, const CGRect &boundsB)\n{\n float Axmin = boundsA.origin.x;\n float Axmax = Axmin + boundsA.size.width;\n float Aymin = boundsA.origin.y;\n float Aymax = Aymin + boundsA.size.height;\n\n float Bxmin = boundsB.origin.x;\n float Bxmax = Bxmin + boundsB.size.width;\n float Bymin = boundsB.origin.y;\n float Bymax = Bymin + boundsB.size.height;\n\n // find location of B corners in A space\n float B0x = mB(0,0) * Bxmin + mB(0,1) * Bymin + mB(0,2);\n float B0y = mB(1,0) * Bxmin + mB(1,1) * Bymin + mB(1,2);\n\n float B1x = mB(0,0) * Bxmax + mB(0,1) * Bymin + mB(0,2);\n float B1y = mB(1,0) * Bxmax + mB(1,1) * Bymin + mB(1,2);\n\n float B2x = mB(0,0) * Bxmin + mB(0,1) * Bymax + mB(0,2);\n float B2y = mB(1,0) * Bxmin + mB(1,1) * Bymax + mB(1,2);\n\n float B3x = mB(0,0) * Bxmax + mB(0,1) * Bymax + mB(0,2);\n float B3y = mB(1,0) * Bxmax + mB(1,1) * Bymax + mB(1,2);\n\n if(B0x<Axmin && B1x<Axmin && B2x<Axmin && B3x<Axmin)\n return false;\n if(B0x>Axmax && B1x>Axmax && B2x>Axmax && B3x>Axmax)\n return false;\n if(B0y<Aymin && B1y<Aymin && B2y<Aymin && B3y<Aymin)\n return false;\n if(B0y>Aymax && B1y>Aymax && B2y>Aymax && B3y>Aymax)\n return false;\n\n float det = mB(0,0)*mB(1,1) - mB(0,1)*mB(1,0);\n float dx = mB(1,2)*mB(0,1) - mB(0,2)*mB(1,1);\n float dy = mB(0,2)*mB(1,0) - mB(1,2)*mB(0,0);\n\n // find location of A corners in B space\n float A0x = (mB(1,1) * Axmin - mB(0,1) * Aymin + dx)/det;\n float A0y = (-mB(1,0) * Axmin + mB(0,0) * Aymin + dy)/det;\n\n float A1x = (mB(1,1) * Axmax - mB(0,1) * Aymin + dx)/det;\n float A1y = (-mB(1,0) * Axmax + mB(0,0) * Aymin + dy)/det;\n\n float A2x = (mB(1,1) * Axmin - mB(0,1) * Aymax + dx)/det;\n float A2y = (-mB(1,0) * Axmin + mB(0,0) * Aymax + dy)/det;\n\n float A3x = (mB(1,1) * Axmax - mB(0,1) * Aymax + dx)/det;\n float A3y = (-mB(1,0) * Axmax + mB(0,0) * Aymax + dy)/det;\n\n if(A0x<Bxmin && A1x<Bxmin && A2x<Bxmin && A3x<Bxmin)\n return false;\n if(A0x>Bxmax && A1x>Bxmax && A2x>Bxmax && A3x>Bxmax)\n return false;\n if(A0y<Bymin && A1y<Bymin && A2y<Bymin && A3y<Bymin)\n return false;\n if(A0y>Bymax && A1y>Bymax && A2y>Bymax && A3y>Bymax)\n return false;\n\n return true;\n}\n" }, { "answer_id": 44210241, "author": "Jed", "author_id": 5535270, "author_profile": "https://Stackoverflow.com/users/5535270", "pm_score": 0, "selected": false, "text": "function olap_flag = ol(A,B,sub)\n\n%A and B should be 4 x 2 matrices containing the xy coordinates of the corners in clockwise order\n\nif nargin == 2\n olap_flag = ol(A,B,1) && ol(B,A,1);\n return;\nend\n\nurdl = diff(A([1:4 1],:));\ns = sum(urdl .* A, 2);\nsdiff = B * urdl' - repmat(s,[1 4]);\n\nolap_flag = ~any(max(sdiff)<0);\n" }, { "answer_id": 44216173, "author": "Siva Srinivas Kolukula", "author_id": 2118434, "author_profile": "https://Stackoverflow.com/users/2118434", "pm_score": 0, "selected": false, "text": "C1 = [0, 0]; % Centre of rectangle 1 (x,y)\nC2 = [1, 1]; % Centre of rectangle 2 (x,y)\nW1 = 5; W2 = 3; % Widths of rectangles 1 and 2\nH1 = 2; H2 = 3; % Heights of rectangles 1 and 2\n% Define the corner points of the rectangles using the above\nR1 = [C1(1) + [W1; W1; -W1; -W1]/2, C1(2) + [H1; -H1; -H1; H1]/2];\nR2 = [C2(1) + [W2; W2; -W2; -W2]/2, C2(2) + [H2; -H2; -H2; H2]/2];\n\nR1 = [R1 ; R1(1,:)] ;\nR2 = [R2 ; R2(1,:)] ;\n\nplot(R1(:,1),R1(:,2),'r')\nhold on\nplot(R2(:,1),R2(:,2),'b')\n\n\n%% lines of Rectangles \nL1 = [R1(1:end-1,:) R1(2:end,:)] ;\nL2 = [R2(1:end-1,:) R2(2:end,:)] ;\n%% GEt intersection points\nP = zeros(2,[]) ;\ncount = 0 ;\nfor i = 1:4\n line1 = reshape(L1(i,:),2,2) ;\n for j = 1:4\n line2 = reshape(L2(j,:),2,2) ;\n point = InterX(line1,line2) ;\n if ~isempty(point)\n count = count+1 ;\n P(:,count) = point ;\n end\n end\nend\n%%\nif ~isempty(P)\n fprintf('Given rectangles intersect at %d points:\\n',size(P,2))\n plot(P(1,:),P(2,:),'*k')\nend\n" }, { "answer_id": 50918572, "author": "Przemek", "author_id": 959552, "author_profile": "https://Stackoverflow.com/users/959552", "pm_score": 0, "selected": false, "text": "!(a.left > b.right || b.left > a.right || a.top > b.bottom || b.top > a.bottom);\n" }, { "answer_id": 64162017, "author": "Puco4", "author_id": 12131616, "author_profile": "https://Stackoverflow.com/users/12131616", "pm_score": 2, "selected": false, "text": " function isRectangleACollidingWithRectangleB:\n if d > 2 * R:\n return False\n ...\n function isRectangleACollidingWithRectangleB:\n ...\n #Consider first rectangle A:\n Si-1 = Vertex_A[4] - Vertex_A[1]\n for i in Vertex_A:\n Si+1 = Vertex_A[i+1] - Vertex_A[i]\n Ni = [- Si+1.y, Si+1.x ]\n sgn_i = sign( dot_product(Si-1, Ni) ) #sgn_i is the sign of rectangle A with respect the separating axis\n\n for j in Vertex_B:\n sij = Vertex_B[j] - Vertex_A[i]\n sgn_j = sign( dot_product(sij, Ni) ) #sgnj is the sign of vertex j of square B with respect the separating axis\n if sgn_i * sgn_j > 0: #i.e., we have the same sign\n break #Vertex i does not define separating axis\n else:\n if j == 4: #we have reached the last vertex so vertex i defines the separating axis\n return False\n \n Si-1 = - Si+1\n\n #Repeat for rectangle B\n ...\n\n #If we do not find any separating axis\n return True \n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20493/" ]
115,428
<p>I am looking to convert a <code>MySQL timestamp</code> to a epoch time in seconds using <code>PHP</code>, and vice versa. </p> <p>What's the cleanest way to do this?</p>
[ { "answer_id": 115510, "author": "Michał Niedźwiedzki", "author_id": 2169, "author_profile": "https://Stackoverflow.com/users/2169", "pm_score": 3, "selected": false, "text": "$unixTimestamp = strtotime($mysqlDate);\n$mysqlDate = date('Y-m-d h:i:s', $unixTimestamp);\n" }, { "answer_id": 115514, "author": "Magsol", "author_id": 13604, "author_profile": "https://Stackoverflow.com/users/13604", "pm_score": 0, "selected": false, "text": "strtotime($mysql_timestamp);\n $mysql_timestamp = date('Y-m-d H:i:s', time());\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
115,431
<p>Suppose I have some XAML like this:</p> <pre><code>&lt;Window.Resources&gt; &lt;v:MyClass x:Key="whatever" Text="foo\nbar" /&gt; &lt;/Window.Resources&gt; </code></pre> <p>Obviously I want a newline character in the MyClass.Text property, but the XAML parser constructs the object with the literal string "foo\nbar".</p> <p>Is there (a) a way to convince the parser to translate escape sequences, or (b) a .NET method to interpret a string in the way that the C# compiler would?</p> <p>I realize that I can go in there looking for <code>\n</code> sequences, but it would be nicer to have a generic way to do this.</p>
[ { "answer_id": 115543, "author": "deepcode.co.uk", "author_id": 20524, "author_profile": "https://Stackoverflow.com/users/20524", "pm_score": 1, "selected": false, "text": "<v:MyClass x:Key=\"whatever\" Text=\"{MyBinder foo\\nbar}\"/> <v:MyClass x:Key=\"whatever\">\nfoo\nbar\n</v:MyClass>\n" }, { "answer_id": 115718, "author": "Matthew Scharley", "author_id": 15537, "author_profile": "https://Stackoverflow.com/users/15537", "pm_score": 1, "selected": false, "text": "string s = \"foo\\\\nbar\";\ns = s.Replace(\"\\\\n\", \"\\n\");\n using System.Text.RegularExpressions;\n\n// snip\nstring s = \"foo\\\\nbar\";\nRegex r = new Regex(\"\\\\\\\\[rnt\\\\\\\\]\");\ns = r.Replace(s, ReplaceControlChars); ;\n// /snip\n\nstring ReplaceControlChars(Match m)\n{\n switch (m.ToString()[1])\n {\n case 'r': return \"\\r\";\n case 'n': return \"\\n\";\n case '\\\\': return \"\\\\\";\n case 't': return \"\\t\";\n // some control character we don't know how to handle\n default: return m.ToString();\n }\n}\n" }, { "answer_id": 115738, "author": "SmartyP", "author_id": 18005, "author_profile": "https://Stackoverflow.com/users/18005", "pm_score": 0, "selected": false, "text": " <TextBlock>\n Line 1\n <LineBreak />\n Line 2\n </TextBlock>\n" }, { "answer_id": 116706, "author": "Vriff Polo", "author_id": 20653, "author_profile": "https://Stackoverflow.com/users/20653", "pm_score": 5, "selected": true, "text": "<TextBlock Text=\"Hello&#13;World!\"/>\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9591/" ]
115,462
<p>I'm having a little bit of a problem scaling my images to a properly predefined size. I was wondering - since it is purely mathematics, if there's some sort of common logical algorithm that works in every language (PHP, ActionScript, Javascript etc.) to scale images proportionally.</p> <p>I'm using this at the moment: </p> <pre><code>var maxHeight = 300; var maxWidth = 300; var ratio:Number = height / width; if (height &gt; maxHeight) { height = maxHeight; width = Math.round(height / ratio); } else if(width &gt; maxWidth) { width = maxWidth; height = Math.round(width * ratio); } </code></pre> <p>But it doesn't work properly. The images scales proportionately, sure enough, but the size isn't set at 300 (either in width or in height). It kind of makes sense, but I was wondering if there's a fool-proof, easy way to scale images proportionally.</p>
[ { "answer_id": 115492, "author": "Dark Shikari", "author_id": 11206, "author_profile": "https://Stackoverflow.com/users/11206", "pm_score": 7, "selected": true, "text": "ratio = MIN( maxWidth / width, maxHeight/ height );\nwidth = ratio * width;\nheight = ratio * height;\n" }, { "answer_id": 7746280, "author": "Bogdan Ciocoiu", "author_id": 914832, "author_profile": "https://Stackoverflow.com/users/914832", "pm_score": 0, "selected": false, "text": "<?php\n\n$thumb_width = 500;\n$thumb_height = 500;\n\nif ($handle = opendir('to-do')) {\n echo \"Directory handle: $handle<br />\";\n echo \"Files:<br /><br />\";\n\n /* This is the correct way to loop over the directory. */\n while (false !== ($file = readdir($handle))) {\n\n if ( ($file != \".\") && ($file != \"..\") ){\n echo \"$file\";\n\n $original_path = \"to-do/\" . $file;\n\n $source_image = ImageCreateFromJPEG( $original_path );\n $thumb_width = $thumb_width;\n $thumb_height = $thumb_height;\n\n // Create the image, of the required size\n $thumbnail = imagecreatetruecolor($thumb_width, $thumb_height);\n if($thumbnail === false) {\n //creation failed -- probably not enough memory\n return null;\n }\n\n // Fill the image with a white color (this will be visible in the padding around the image,\n // if the aspect ratios of the image and the thumbnail do not match)\n // Replace this with any color you want, or comment it out for black.\n // I used grey for testing =)\n $fill = imagecolorallocate($thumbnail, 255, 255, 255);\n imagefill($thumbnail, 0, 0, $fill);\n\n // Compute resize ratio\n $hratio = $thumb_height / imagesy($source_image);\n $wratio = $thumb_width / imagesx($source_image);\n $ratio = min($hratio, $wratio);\n\n // If the source is smaller than the thumbnail size, \n // Don't resize -- add a margin instead\n // (that is, dont magnify images)\n if ($ratio > 1.0)\n $ratio = 1.0;\n\n // Compute sizes\n $sy = floor(imagesy($source_image) * $ratio);\n $sx = floor(imagesx($source_image) * $ratio);\n\n // Compute margins\n // Using these margins centers the image in the thumbnail.\n // If you always want the image to the top left, set both of these to 0\n $m_y = floor(($thumb_height - $sy) / 2);\n $m_x = floor(($thumb_width - $sx) / 2);\n\n // Copy the image data, and resample\n // If you want a fast and ugly thumbnail, replace imagecopyresampled with imagecopyresized\n if (!imagecopyresampled($thumbnail, $source_image,\n $m_x, $m_y, //dest x, y (margins)\n 0, 0, //src x, y (0,0 means top left)\n $sx, $sy,//dest w, h (resample to this size (computed above)\n imagesx($source_image), imagesy($source_image)) //src w, h (the full size of the original)\n ) {\n //copy failed\n imagedestroy($thumbnail);\n return null;\n }\n\n /* Set the new file name */\n $thumbnail_file_name = $file;\n\n /* Apply changes on the original image and write the result on the disk */\n ImageJPEG( $thumbnail, $complete_path . \"done/\" . $thumbnail_file_name );\n unset($source_image);\n unset($thumbnail);\n unset($original_path);\n unset($targeted_image_size);\n\n echo \" done<br />\";\n\n }\n\n }\n\n closedir($handle);\n}\n\n?>\n" }, { "answer_id": 8961028, "author": "Nicholas", "author_id": 1163414, "author_profile": "https://Stackoverflow.com/users/1163414", "pm_score": 0, "selected": false, "text": " function scaleProportional($img_w,$img_h,$max=50)\n {\n $w = 0;\n $h = 0;\n\n $img_w > $img_h ? $w = $img_w / $img_h : $w = 1;\n $img_h > $img_w ? $h = $img_h / $img_w : $h = 1;\n\n $ws = $w > $h ? $ws = ($w / $w) * $max : $ws = (1 / $h) * $max;\n $hs = $h > $w ? $hs = ($h / $h) * $max : $hs = (1 / $w) * $max;\n\n return array(\n 'width'=>$ws,\n 'height'=>$hs\n );\n }\n $getScale = scaleProportional(600,200,500);\n $targ_w = $getScale['width']; //returns 500\n $targ_h = $getScale['height']; //returns 16,6666667\n" }, { "answer_id": 9505587, "author": "Arvin", "author_id": 628864, "author_profile": "https://Stackoverflow.com/users/628864", "pm_score": 2, "selected": false, "text": "+ (NSSize) scaleHeight:(NSSize)origSize \n newHeight:(CGFloat)height {\n\n NSSize newSize = NSZeroSize;\n if ( origSize.height == 0 ) return newSize;\n\n newSize.height = height;\n CGFloat factor = ( height / origSize.height );\n newSize.width = (origSize.width * factor );\n\n return newSize;\n}\n\n+ (NSSize) scaleWidth:(NSSize)origSize \n newWidth:(CGFloat)width {\n\n NSSize newSize = NSZeroSize;\n if ( origSize.width == 0 ) return newSize;\n\n newSize.width = width;\n CGFloat factor = ( width / origSize.width );\n newSize.height = (origSize.height * factor );\n\n return newSize;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17362/" ]
115,472
<p>I'm working on a .NET 3.5 website, with three projects under one solution. I'm using jQuery in this project. I'd like to use the Visual Studio JavaScript debugger to step through my JavaScript code. If I set a breakpoint in any of the .js files I get a warning that says:</p> <blockquote> <p>The breakpoint will not currently be hit. No symbols have been loaded for this document.</p> </blockquote> <p>How do I fix this? I'm guessing that Visual Studio is having some trouble parsing through some of the jQuery code. I will try to replace the minimized version of <code>jQuery.js</code> with the expanded version, but I don't think that will fix it.</p>
[ { "answer_id": 466131, "author": "Ian Robinson", "author_id": 326, "author_profile": "https://Stackoverflow.com/users/326", "pm_score": 5, "selected": true, "text": "debugger;" }, { "answer_id": 1278156, "author": "ExceptionRaiser", "author_id": 156528, "author_profile": "https://Stackoverflow.com/users/156528", "pm_score": 3, "selected": false, "text": "IExplorer.exe" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13800/" ]
115,478
<p>The following code is in the <code>/Courses/Detail</code> action:</p> <pre><code> [AcceptVerbs("GET")] public ActionResult Detail(int id) { ViewData["Title"] = "A View Title"; return View(tmdc.GetCourseById(id)); } </code></pre> <p>The <code>tmdc.GetCourseById(id)</code> method returns an instance of type <code>Course</code> for the View. In the View I am using </p> <pre><code>&lt;%= HTML.TextBox("Title")%&gt; </code></pre> <p>to display the value of the <code>Title</code> property for the <code>Course</code> object. Instead the text box is displaying the string <code>A View Title</code>. Is this normal/expected behavior? What would be the best way to handle this?</p> <p><b>Update</b><br /> As a workaround, I've changed <code>ViewData["Title"]</code> to <code>ViewData["VIEW_TITLE"]</code> but would like a cleaner way to handle this collision or to know if this is an expected result.</p>
[ { "answer_id": 466131, "author": "Ian Robinson", "author_id": 326, "author_profile": "https://Stackoverflow.com/users/326", "pm_score": 5, "selected": true, "text": "debugger;" }, { "answer_id": 1278156, "author": "ExceptionRaiser", "author_id": 156528, "author_profile": "https://Stackoverflow.com/users/156528", "pm_score": 3, "selected": false, "text": "IExplorer.exe" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19251/" ]
115,488
<p>I am having difficulty reliably creating / removing event sources during the installation of my .Net Windows Service.</p> <p>Here is the code from my ProjectInstaller class:</p> <pre><code>// Create Process Installer ServiceProcessInstaller spi = new ServiceProcessInstaller(); spi.Account = ServiceAccount.LocalSystem; // Create Service ServiceInstaller si = new ServiceInstaller(); si.ServiceName = Facade.GetServiceName(); si.Description = "Processes ..."; si.DisplayName = "Auto Checkout"; si.StartType = ServiceStartMode.Automatic; // Remove Event Source if already there if (EventLog.SourceExists("AutoCheckout")) EventLog.DeleteEventSource("AutoCheckout"); // Create Event Source and Event Log EventLogInstaller log = new EventLogInstaller(); log.Source = "AutoCheckout"; log.Log = "AutoCheckoutLog"; Installers.AddRange(new Installer[] { spi, si, log }); </code></pre> <p>The facade methods referenced just return the strings for the name of the log, service, etc.</p> <p>This code works most of the time, but recently after installing I started getting my log entries showing up in the Application Log instead of the custom log. And the following errors are in the log as well:</p> <blockquote> <p>The description for Event ID ( 0 ) in Source ( AutoCheckout ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. </p> </blockquote> <p>For some reason it either isn't properly removing the source during the uninstall or it isn't creating it during the install.</p> <p>Any help with best practices here is appreciated.</p> <p>Thanks!</p> <p>In addition, here is a sample of how I am writing exceptions to the log:</p> <pre><code>// Write to Log EventLog.WriteEntry(Facade.GetEventLogSource(), errorDetails, EventLogEntryType.Error, 99); </code></pre> <p><strong>Regarding stephbu's answer:</strong> The recommended path is an installer script and installutil, or a Windows Setup routine.</p> <p>I am using a Setup Project, which performs the installation of the service and sets up the log. Whether I use the installutil.exe or the windows setup project I believe they both call the same ProjectInstaller class I show above.</p> <p>I see how the state of my test machine could be causing the error if the log isn't truly removed until rebooting. I will experiment more to see if that solves the issue.</p> <p><strong>Edit:</strong> I'm interested in a sure fire way to register the source and the log name during the installation of the service. So if the service had previously been installed, it would remove the source, or reuse the source during subsequent installations.</p> <p>I haven't yet had an opportunity to learn WiX to try that route.</p>
[ { "answer_id": 1287334, "author": "helb", "author_id": 157690, "author_profile": "https://Stackoverflow.com/users/157690", "pm_score": 5, "selected": false, "text": "ServiceInstaller EventLogInstaller ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();\nserviceProcessInstaller.Password = null;\nserviceProcessInstaller.Username = null;\nserviceProcessInstaller.Account = ServiceAccount.LocalSystem;\n\n// serviceInstaller\nServiceInstaller serviceInstaller = new ServiceInstaller();\nserviceInstaller.ServiceName = \"MyService\";\nserviceInstaller.DisplayName = \"My Service\";\nserviceInstaller.StartType = ServiceStartMode.Automatic;\nserviceInstaller.Description = \"My Service Description\";\n// kill the default event log installer\nserviceInstaller.Installers.Clear(); \n\n// Create Event Source and Event Log \nEventLogInstaller logInstaller = new EventLogInstaller();\nlogInstaller.Source = \"MyService\"; // use same as ServiceName\nlogInstaller.Log = \"MyLog\";\n\n// Add all installers\nthis.Installers.AddRange(new Installer[] {\n serviceProcessInstaller, serviceInstaller, logInstaller\n});\n" }, { "answer_id": 3674774, "author": "Tod Flak", "author_id": 380605, "author_profile": "https://Stackoverflow.com/users/380605", "pm_score": 2, "selected": false, "text": " ' remove the default event log installer \n Me.ServiceInstaller1.Installers.Clear()\n\n ' Create an EventLogInstaller, and set the Event Source and Event Log \n Dim logInstaller As New EventLogInstaller\n logInstaller.Source = \"MyServiceName\"\n logInstaller.Log = \"MyCustomEventLogName\"\n\n ' Add the event log installer\n Me.ServiceInstaller1.Installers.Add(logInstaller)\n Private Function EventLogSourceNameExists() As Boolean\n 'ensures that the EventSource name exists, and that it is associated to the correct Log \n\n Dim EventLog_SourceName As String = Utility.RetrieveAppSetting(\"EventLog_SourceName\")\n Dim EventLog_LogName As String = Utility.RetrieveAppSetting(\"EventLog_LogName\")\n\n Dim SourceExists As Boolean = EventLog.SourceExists(EventLog_SourceName)\n If Not SourceExists Then\n ' Create the source, if it does not already exist.\n ' An event log source should not be created and immediately used.\n ' There is a latency time to enable the source, it should be created\n ' prior to executing the application that uses the source.\n 'So pass back a False to cause the service to terminate. User will have \n 'to re-start the application to make it work. This ought to happen only once on the \n 'machine on which the service is newly installed\n\n EventLog.CreateEventSource(EventLog_SourceName, EventLog_LogName) 'create as a source for the SMRT event log\n Else\n 'make sure the source is associated with the log file that we want\n Dim el As New EventLog\n el.Source = EventLog_SourceName\n If el.Log <> EventLog_LogName Then\n el.WriteEntry(String.Format(\"About to delete this source '{0}' from this log '{1}'. You may have to kill the service using Task Manageer. Then please reboot the computer; then restart the service two times more to ensure that this event source is created in the log {2}.\", _\n EventLog_SourceName, el.Log, EventLog_LogName))\n\n EventLog.DeleteEventSource(EventLog_SourceName)\n SourceExists = False 'force a close of service\n End If\n End If\n Return SourceExists\n End Function\n" }, { "answer_id": 5608532, "author": "netniV", "author_id": 697159, "author_profile": "https://Stackoverflow.com/users/697159", "pm_score": 1, "selected": false, "text": "SortedList<string, string> eventSources = new SortedList<string, string>();\nprivate void serviceProcessInstaller_BeforeInstall(object sender, InstallEventArgs e)\n{\n RemoveServiceEventLogs();\n}\n\nprivate void RemoveServiceEventLogs()\n{\n foreach (Installer installer in this.Installers)\n if (installer is ServiceInstaller)\n {\n ServiceInstaller serviceInstaller = installer as ServiceInstaller;\n if (EventLog.SourceExists(serviceInstaller.ServiceName))\n {\n eventSources.Add(serviceInstaller.ServiceName, EventLog.LogNameFromSourceName(serviceInstaller.ServiceName, Environment.MachineName));\n EventLog.DeleteEventSource(serviceInstaller.ServiceName);\n }\n }\n}\n\nprivate void serviceProcessInstaller_Committed(object sender, InstallEventArgs e)\n{\n RemoveServiceEventLogs();\n foreach (KeyValuePair<string, string> eventSource in eventSources)\n {\n if (EventLog.SourceExists(eventSource.Key))\n EventLog.DeleteEventSource(eventSource.Key);\n\n EventLog.CreateEventSource(eventSource.Key, eventSource.Value);\n }\n}\n" }, { "answer_id": 28111365, "author": "Simon Mattes", "author_id": 3687883, "author_profile": "https://Stackoverflow.com/users/3687883", "pm_score": 0, "selected": false, "text": "[RunInstaller( true )]\npublic partial class ProjectInstaller : System.Configuration.Install.Installer\n{\n public ProjectInstaller()\n {\n InitializeComponent();\n\n //Skip through all ServiceInstallers.\n foreach( ServiceInstaller ThisInstaller in Installers.OfType<ServiceInstaller>() )\n {\n //Find the first default EventLogInstaller.\n EventLogInstaller ThisLogInstaller = ThisInstaller.Installers.OfType<EventLogInstaller>().FirstOrDefault();\n if( ThisLogInstaller == null )\n continue;\n\n //Modify the used log from \"Application\" to the same name as the source name. This creates a source in the \"Applications and Services log\" which separates your service logs from the default application log.\n ThisLogInstaller.Log = ThisLogInstaller.Source;\n }\n }\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13368/" ]
115,496
<p>How to customize the color of the symbol inserted in the "glasses mode" in Emacs? I have not found the option for this. Can anyone suggest anything?</p>
[ { "answer_id": 115940, "author": "Allen", "author_id": 6043, "author_profile": "https://Stackoverflow.com/users/6043", "pm_score": 4, "selected": true, "text": "glasses-face" }, { "answer_id": 115947, "author": "dmckee --- ex-moderator kitten", "author_id": 2509, "author_profile": "https://Stackoverflow.com/users/2509", "pm_score": 2, "selected": false, "text": "glasses-separator (setq glasses-separator \"~\")\n" }, { "answer_id": 120505, "author": "David Webb", "author_id": 3171, "author_profile": "https://Stackoverflow.com/users/3171", "pm_score": 0, "selected": false, "text": "glasses-mode M-x customize-group\n glasses Customize group (default emacs):" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20514/" ]
115,500
<p>In Java you can give the number zero as a single parameter for the Socket or DatagramSocket constructor. Java binds that Socket to a free port then. Is it possible to limit the port lookup to a specific range?</p>
[ { "answer_id": 116113, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 2, "selected": false, "text": "public static Socket getListeningSocket() {\n for ( int port = MIN_PORT ; port <= MAX_PORT ; port++ )\n {\n try {\n ServerSocket s = new ServerSocket( port );\n return s; // no exception means port was available\n } catch (IOException e) {\n // try the next port\n }\n }\n return null; // port not found, perhaps throw exception?\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16515/" ]
115,503
<p>I recently asked a question about Oracle Encryption. Along the way to finding a solution for myself I decided to move the encryption (well, obfuscation) to the application side for certain tasks. </p> <p>My problem is that the database is already encrypting data a certain way and I need Java code to duplicate that functionality, so that text encrypted by one system can be decrypted by the other and vice versa.</p> <p>I want the encryption to be compatible with what the DB was already doing but couldn't find the documentation that describes exactly what Oracle is doing. How do I replicate this in Java?</p> <pre><code>dbms_obfuscation_toolkit.DESEncrypt( input_string =&gt; v_string, key_string =&gt; key_string, encrypted_string =&gt; encrypted_string ); RETURN UTL_RAW.CAST_TO_RAW(encrypted_string); </code></pre> <p>No matter what I try, it seems as if the Java DES encryption is different than Oracle's.</p>
[ { "answer_id": 115540, "author": "Mr. Shiny and New 安宇", "author_id": 7867, "author_profile": "https://Stackoverflow.com/users/7867", "pm_score": 3, "selected": true, "text": "KeySpec ks = new DESKeySpec(new byte[] {'s','e','c','r','e','t','!','!'});\nSecretKeyFactory skf = SecretKeyFactory.getInstance(\"DES\");\nSecretKey sk = skf.generateSecret(ks);\nCipher c = Cipher.getInstance(\"DES/CBC/NoPadding\");\nIvParameterSpec ips = new IvParameterSpec(new byte[] {0,0,0,0,0,0,0,0});\nc.init(Cipher.ENCRYPT, sk, ips);\n// or\nc.init(Cipher.DECRYPT, sk, ips);\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7867/" ]
115,508
<p>I am connecting to a Windows XP machine via Microsoft's Remote Desktop Connection Client, version 2.0.0 Beta 3, running on a Mac. On the Windows machine there is a Java console running, where I want to send a Ctrl-Break so I can see the Java threads running.</p> <p>According to the RDC help, Alt/Option-F3 is break, but Ctrl-Opt-F3 and various other combinations do not have an effect.</p> <p>Any ideas on how to send a Ctrl-Break?</p>
[ { "answer_id": 8670518, "author": "andrew", "author_id": 1121554, "author_profile": "https://Stackoverflow.com/users/1121554", "pm_score": 2, "selected": false, "text": "fn + Esc\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
115,526
<p>I'm running an c# .net app in an iframe of an asp page on an older site. Accessing the Asp page's session information is somewhat difficult, so I'd like to make my .net app simply verify that it's being called from an approved page, or else immediately halt.</p> <p>Is there a way for a page to find out the url of it's parent document?</p>
[ { "answer_id": 115533, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 5, "selected": true, "text": "top.location.href\n" }, { "answer_id": 116157, "author": "Raleigh Buckner", "author_id": 1153, "author_profile": "https://Stackoverflow.com/users/1153", "pm_score": 1, "selected": false, "text": "parent.location.href\n" }, { "answer_id": 2835018, "author": "jumpdart", "author_id": 341335, "author_profile": "https://Stackoverflow.com/users/341335", "pm_score": 2, "selected": false, "text": "Request.UrlReferrer....\n NameValueCollection qs = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12382/" ]
115,548
<p>This code in JS gives me a popup saying "i think null is a number", which I find slightly disturbing. What am I missing?</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>if (isNaN(null)) { alert("null is not a number"); } else { alert("i think null is a number"); }</code></pre> </div> </div> </p> <p>I'm using Firefox 3. Is that a browser bug?</p> <p>Other tests:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>console.log(null == NaN); // false console.log(isNaN("text")); // true console.log(NaN == "text"); // false</code></pre> </div> </div> </p> <p>So, the problem seems not to be an exact comparison with NaN?</p> <p><i><b>Edit:</b> Now the question has been answered, I have cleaned up my post to have a better version for the archive. However, this renders some comments and even some answers a little incomprehensible. Don't blame their authors. Among the things I changed was:</p> <ul> <li>Removed a note saying that I had screwed up the headline in the first place by reverting its meaning</li> <li>Earlier answers showed that I didn't state clearly enough why I thought the behaviour was weird, so I added the examples that check a string and do a manual comparison. </i></li> </ul>
[ { "answer_id": 115696, "author": "Glenn Moss", "author_id": 5726, "author_profile": "https://Stackoverflow.com/users/5726", "pm_score": 8, "selected": true, "text": "x x = null isNaN() NaN NaN isNaN(null) == false null NaN isNaN(x) Number(x) NaN Number(x) NaN x NaN x = null null Number(null) isNaN(0) 'abcd' isNaN('abcd') Number('abcd') NaN NaN x == NaN NaN" }, { "answer_id": 118084, "author": "treat your mods well", "author_id": 20772, "author_profile": "https://Stackoverflow.com/users/20772", "pm_score": 3, "selected": false, "text": "var x = [undefined, NaN, 'blah', 0/0, null, 0, '0', 1, 1/0, -1/0, Number(5)]\n ,NaN,blah,NaN,,0,0,1,Infinity,-Infinity,5\n x.map(isNaN) true,true,true,true,false,false,false,false,false,false,false\n isNaN x.map(function(n){return typeof n})\n-> undefined,number,string,number,object,number,string,number,number,number,number\n" }, { "answer_id": 118154, "author": "treat your mods well", "author_id": 20772, "author_profile": "https://Stackoverflow.com/users/20772", "pm_score": 4, "selected": false, "text": "ToNumber undefined number NaN NaN string undefined NaN new Number(NaN) NaN ToNumber true isNaN null true" }, { "answer_id": 120499, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": -1, "selected": false, "text": "\"1\" == 1 // true\n\"1\" === 1 // false\n" }, { "answer_id": 20629324, "author": "guy mograbi", "author_id": 1068746, "author_profile": "https://Stackoverflow.com/users/1068746", "pm_score": 5, "selected": false, "text": "isNaN(parseInt(myInt)) var x = [undefined, NaN, 'blah', 0/0, null, 0, '0', 1, 1/0, -1/0, Number(5)]\nx.map( function(n){ return isNaN(parseInt(n))})\n [true, true, true, true, true, false, false, false, true, true, false]\n" }, { "answer_id": 29821670, "author": "rab", "author_id": 1722625, "author_profile": "https://Stackoverflow.com/users/1722625", "pm_score": 2, "selected": false, "text": "isNaN (number) ToNumber(Null) +0 isNaN(null) false" }, { "answer_id": 67980304, "author": "5ervant - techintel.github.io", "author_id": 2007055, "author_profile": "https://Stackoverflow.com/users/2007055", "pm_score": -1, "selected": false, "text": "(NaN == null) // false\n(NaN != null) // true\n (NaN == true) // false\n(NaN == false) // false\n(NaN) // false\n(!NaN) // true\n (NaN == false) (!NaN)" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115548", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2077/" ]
115,557
<p>We are struggling to configure our web app to be able to connect with web services via Spring WS. We have tried to use the example from the documentation of client-side Spring-WS, but we end up with a WebServiceTransportException. The XML config looks like this:</p> <pre><code>&lt;bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"&gt; &lt;constructor-arg ref="messageFactory"/&gt; &lt;property name="messageSender"&gt; &lt;bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender"&gt; &lt;property name="credentials"&gt; &lt;bean class="org.apache.commons.httpclient.UsernamePasswordCredentials"&gt; &lt;constructor-arg value="john"/&gt; &lt;constructor-arg value="secret"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>We have been able to configure the application programmatically, but this configuration was not possible to "transfer" to a Spring XML config because some setters did not use the format Spring expects. (HttpState.setCredentials(...) takes two parameters). The config was lifted from some other Spring-WS client code in the company.</p> <p>This is the configuration that works:</p> <pre><code> public List&lt;String&gt; getAll() { List&lt;String&gt; carTypes = new ArrayList&lt;String&gt;(); try { Source source = new ResourceSource(request); JDOMResult result = new JDOMResult(); SaajSoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance()); WebServiceTemplate template = new WebServiceTemplate(soapMessageFactory); HttpClientParams clientParams = new HttpClientParams(); clientParams.setSoTimeout(60000); clientParams.setConnectionManagerTimeout(60000); clientParams.setAuthenticationPreemptive(true); HttpClient client = new HttpClient(clientParams); client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("username", "password")); CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender(client); template.setMessageSender(messageSender); template.sendSourceAndReceiveToResult(SERVICE_URI, source, result); // Handle the XML } catch (IOException e) { throw new RuntimeException(e); } catch (SOAPException e) { throw new RuntimeException(e); } return carTypes; } </code></pre> <p>Does anyone know how to solve my problem? Every tutorial I have see out there lists the first configuration. It seems that when I set the credentials on the messageSender object, they are just ignored...</p>
[ { "answer_id": 150178, "author": "Symbioxys", "author_id": 1841427, "author_profile": "https://Stackoverflow.com/users/1841427", "pm_score": 1, "selected": false, "text": "<constructor-arg value=\"john\"/>\n<constructor-arg value=\"secret\"/>\n <property name=\"userName\" value=\"john\" />\n<property name=\"password\" value=\"secret\" />\n" }, { "answer_id": 1915645, "author": "DonHaji", "author_id": 233092, "author_profile": "https://Stackoverflow.com/users/233092", "pm_score": 2, "selected": false, "text": "public MyHttpClient(HttpClientParams params, UsernamePasswordCredentials usernamePasswordCredentials) {\n super(params); \n getState().setCredentials(AuthScope.ANY, usernamePasswordCredentials);\n }\n" }, { "answer_id": 25661201, "author": "Jemo", "author_id": 1010056, "author_profile": "https://Stackoverflow.com/users/1010056", "pm_score": 0, "selected": false, "text": "<bean id=\"authenticationEnabledCommonsHttpMessageSender\" parent=\"commonsHttpMessageSender\"\n p:credentials-ref=\"clientCredentials\" lazy-init=\"true\" />\n<bean id=\"clientCredentials\"\n class=\"org.apache.commons.httpclient.UsernamePasswordCredentials\"\n c:userName=\"${clientCredentials.userName}\"\n c:password=\"${clientCredentials.password}\"\n lazy-init=\"true\" />\n public Message sendRequest(OutgoingRequest message, MessageHeaders headers,\n EndpointInfoProvider endpointInfoProvider,\n WebServiceMessageCallback requestCallback){\n Assert.notNull(endpointInfoProvider, \"Destination provider is required!\");\n final Credentials credentials = endpointInfoProvider.getCredentials();\n URI destinationUri = endpointInfoProvider.getDestination();\n for (WebServiceMessageSender messageSender : webServiceTemplate.getMessageSenders()) {\n if (messageSender instanceof CommonsHttpMessageSender) {\n HttpClient httpClient = ((CommonsHttpMessageSender) messageSender).getHttpClient();\n httpClient.getState().setCredentials(\n new AuthScope(destinationUri.getHost(),\n destinationUri.getPort(), AuthScope.ANY_REALM,\n AuthScope.ANY_SCHEME), credentials\n );\n httpClient.getParams().setAuthenticationPreemptive(true);\n ((CommonsHttpMessageSender) messageSender)\n .setConnectionTimeout(endpointInfoProvider\n .getTimeOutDuration());\n }\n }\n @Override\npublic Credentials getCredentials(){\n if (credentials != null) {\n return credentials;\n }\n String username = parameterService.usernameFor(getServiceName());\n String password = parameterService.passwordFor(getServiceName());\n if (username == null && password == null) {\n return null;\n }\n credentials = new UsernamePasswordCredentials(username, password);\n return credentials;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115557", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20529/" ]
115,573
<p>I'm sure we all have received the wonderfully vague "Object reference not set to instance of an Object" exception at some time or another. Identifying the object that is the problem is often a tedious task of setting breakpoints and inspecting all members in each statement. </p> <p>Does anyone have any tricks to easily and efficiently identify the object that causes the exception, either via programmatical means or otherwise?</p> <p>--edit</p> <p>It seems I was vague like the exception =). The point is to _not have to debug the app to find the errant object. The compiler/runtime does know that the object has been allocated/declared, and that the object has not yet been instantiated. Is there a way to extract / identify those details in a caught exception</p> <p>@ W. Craig Trader</p> <p>Your explanation that it is a result of a design problem is probably the best answer I could get. I am fairly compulsive with defensive coding and have managed to get rid of most of these errors after fixing my habits over time. The remaining ones just <strong><em>tweak</em></strong> me to no end, and lead me to posting this question to the community. </p> <p>Thanks for everyone's suggestions.</p>
[ { "answer_id": 115619, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 1, "selected": false, "text": "ArgumentNullException NullReferenceException ArgumentNullException InvalidStateException" }, { "answer_id": 115732, "author": "Craig Trader", "author_id": 12895, "author_profile": "https://Stackoverflow.com/users/12895", "pm_score": 5, "selected": true, "text": "public class NullPointerExample {\n public static void Main()\n {\n Object foo;\n System.Console.WriteLine( foo.ToString() );\n }\n}\n" }, { "answer_id": 116424, "author": "Matt Ryan", "author_id": 19548, "author_profile": "https://Stackoverflow.com/users/19548", "pm_score": 4, "selected": false, "text": "Try\n ' // Do some work '\nCatch ex As Exception When CallMethodToInspectException(ex)\n\nEnd Try\n int colNumber = new System.Diagnostics.StackTrace(ex, true).GetFrame(0).GetFileColumnNumber();\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16391/" ]
115,643
<p>PowerShell is definitely in the category of dynamic languages, but would it be considered strongly typed? </p>
[ { "answer_id": 115676, "author": "David Mohundro", "author_id": 4570, "author_profile": "https://Stackoverflow.com/users/4570", "pm_score": 3, "selected": false, "text": "[1] » [int]$x = 5\n[2] » $x\n5\n[3] » $x = 'haha'\nCannot convert value \"haha\" to type \"System.Int32\". Error: \"Input string was not in a correct format.\"\nAt line:1 char:3\n+ $x <<<< = 'haha'\n[4] »\n" }, { "answer_id": 115677, "author": "Guy Starbuck", "author_id": 2194, "author_profile": "https://Stackoverflow.com/users/2194", "pm_score": 1, "selected": false, "text": "$compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters\n" }, { "answer_id": 115815, "author": "JacquesB", "author_id": 7488, "author_profile": "https://Stackoverflow.com/users/7488", "pm_score": 5, "selected": false, "text": "> $x=100\n> $x=dir\n > [int]$x = 100\n> $x = dir\nCannot convert \"scripts-2.5\" to \"System.Int32\".\n var > [int]$a = 1\n> [string]$b = $a\n> $b\n1\n> $b.GetType()\n\nIsPublic IsSerial Name BaseType\n-------- -------- ---- --------\nTrue True String System.Object\n" }, { "answer_id": 115914, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 1, "selected": false, "text": "4 + \"4\"\n \"4\" 4 + [System.Convert]::ToInt32(\"4\")\n \"4\" 19# $foo = \"4\"\n20# $foo.GetType()\n\nIsPublic IsSerial Name BaseType\n-------- -------- ---- --------\nTrue True String System.Object\n\n\n21# 4 + $foo\n8\n22# $foo.GetType()\n\nIsPublic IsSerial Name BaseType\n-------- -------- ---- --------\nTrue True String System.Object\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115643", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3289/" ]
115,658
<p>In my C# application I am using the Microsoft Jet OLEDB data provider to read a CSV file. The connection string looks like this:</p> <pre><code>Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Data;Extended Properties="text;HDR=Yes;FMT=Delimited </code></pre> <p>I open an ADO.NET OleDbConnection using that connection string and select all the rows from the CSV file with the command:</p> <pre><code>select * from Data.csv </code></pre> <p>When I open an OleDbDataReader and examine the data types of the columns it returns, I find that something in the stack has tried to guess at the data types based on the first row of data in the file. For example, suppose the CSV file contains:</p> <pre><code>House,Street,Town 123,Fake Street,Springfield 12a,Evergreen Terrace,Springfield </code></pre> <p>Calling the OleDbDataReader.GetDataTypeName method for the House column will reveal that the column has been given the data type "DBTYPE_I4", so all values read from it are interpreted as integers. My problem is that House should be a string - when I try to read the House value from the second row, the OleDbDataReader returns null.</p> <p>How can I tell either the Jet database provider or the OleDbDataReader to interpret a column as strings instead of numbers?</p>
[ { "answer_id": 116111, "author": "Rory MacLeod", "author_id": 1016, "author_profile": "https://Stackoverflow.com/users/1016", "pm_score": 4, "selected": false, "text": "[Data.csv]\nColNameHeader=True\nCol1=House Text\nCol2=Street Text\nCol3=Town Text\n [Data.csv]\nColNameHeader=true\nMaxScanRows=0\n" }, { "answer_id": 7658003, "author": "Akhil", "author_id": 574328, "author_profile": "https://Stackoverflow.com/users/574328", "pm_score": 3, "selected": false, "text": "using (var reader = new CsvReader(\"data.csv\"))\n{\n reader.ReadHeaderRecord();\n foreach (var record in reader.DataRecords)\n {\n var name = record[\"Name\"];\n var age = record[\"Age\"];\n }\n}\n" }, { "answer_id": 47577138, "author": "Jon", "author_id": 2350083, "author_profile": "https://Stackoverflow.com/users/2350083", "pm_score": 0, "selected": false, "text": "MaxScanRows=0 public static DataTable GetDataFromCsvFile(string filePath, bool isFirstRowHeader = true)\n {\n if (!File.Exists(filePath))\n {\n throw new FileNotFoundException(\"The path: \" + filePath + \" doesn't exist!\");\n }\n\n if (!(Path.GetExtension(filePath) ?? string.Empty).ToUpper().Equals(\".CSV\"))\n {\n throw new ArgumentException(\"Only CSV files are supported\");\n }\n var pathOnly = Path.GetDirectoryName(filePath);\n var filename = Path.GetFileName(filePath);\n var schemaIni =\n $\"[{filename}]{Environment.NewLine}\" +\n $\"Format=CSVDelimited{Environment.NewLine}\" +\n $\"ColNameHeader={(isFirstRowHeader ? \"True\" : \"False\")}{Environment.NewLine}\" +\n $\"MaxScanRows=0{Environment.NewLine}\" +\n $\" ; scan all rows for data type{Environment.NewLine}\" +\n $\" ; This file was automatically generated\";\n var schemaFile = pathOnly != null ? Path.Combine(pathOnly, \"schema.ini\") : \"schema.ini\";\n File.WriteAllText(schemaFile, schemaIni);\n\n try\n {\n var sqlCommand = $@\"SELECT * FROM [{filename}]\";\n\n var oleDbConnString =\n $\"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={pathOnly};Extended Properties=\\\"Text;HDR={(isFirstRowHeader ? \"Yes\" : \"No\")}\\\"\";\n\n using (var oleDbConnection = new OleDbConnection(oleDbConnString))\n using (var adapter = new OleDbDataAdapter(sqlCommand, oleDbConnection))\n using (var dataTable = new DataTable())\n {\n adapter.FillSchema(dataTable, SchemaType.Source);\n adapter.Fill(dataTable);\n return dataTable;\n }\n }\n finally\n {\n if (File.Exists(schemaFile))\n {\n File.Delete(schemaFile);\n }\n }\n }\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1016/" ]
115,665
<p>I'm using the <code>cacheCounter</code> in <code>CakePHP</code>, which increments a counter for related fields.</p> <p>Example, I have a Person table a Source table. Person.source_id maps to a row in the Source table. Each person has one Source, and each Source has none or many Person rows.</p> <p><code>cacheCounter</code> is working great when I change the value of a source on a person. It increments <code>Source.Person_Count</code>. Cool.</p> <p>But when it increments, it adds it to the destination source for a person, but doesn't remove it from the old value. I tried <code>updateCacheControl()</code> in <code>afterSave</code>, but that didn't do anything.</p> <p>So then I wrote some code in my model for <code>afterSave</code> that would subtract the source source_id, but it always did this even when I wasn't even changing the <code>source_id</code>. (So the count went negative).</p> <p>My question: Is there a way to tell if a field was changed in the model in <code>CakePHP</code>?</p>
[ { "answer_id": 123485, "author": "neilcrookes", "author_id": 9968, "author_profile": "https://Stackoverflow.com/users/9968", "pm_score": 0, "selected": false, "text": "echo $form->input('field_to_monitor');\necho $form->hidden('field_to_monitor_prev', array('value'=>$form->value('field_to_monitor')));\n" }, { "answer_id": 138574, "author": "Alexander Morland", "author_id": 4013, "author_profile": "https://Stackoverflow.com/users/4013", "pm_score": 5, "selected": true, "text": "function beforeSave() {\n $this->recursive = -1;\n $this->old = $this->find(array($this->primaryKey => $this->id));\n if ($this->old){\n $changed_fields = array();\n foreach ($this->data[$this->alias] as $key =>$value) {\n if ($this->old[$this->alias][$key] != $value) {\n $changed_fields[] = $key;\n }\n }\n }\n // $changed_fields is an array of fields that changed\n return true;\n}\n" }, { "answer_id": 7408274, "author": "Sajib Hassan", "author_id": 943382, "author_profile": "https://Stackoverflow.com/users/943382", "pm_score": -1, "selected": false, "text": "/**\n * Returns the number of rows affected by the last query\n *\n * @return int Number of rows\n * @access public\n */\n function getAffectedRows() {\n $db =& ConnectionManager::getDataSource($this->useDbConfig);\n return $db->lastAffected();\n }\n" }, { "answer_id": 12103681, "author": "Vins", "author_id": 733087, "author_profile": "https://Stackoverflow.com/users/733087", "pm_score": 3, "selected": false, "text": "$result = array_diff_assoc($this->old[$this->alias],$this->data[$this->alias]);\n" }, { "answer_id": 63474054, "author": "Sebastian Sperandio", "author_id": 1934672, "author_profile": "https://Stackoverflow.com/users/1934672", "pm_score": 0, "selected": false, "text": "// Prior to 3.5 use dirty()\n$article->isDirty('title');\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43/" ]
115,681
<p>I have to restore a database that has been inadvertently DROPped in MySQL 5.0. From checking the backup files, I only seem to have .FRM files to hold the database data.</p> <p>Can anyone advise whether this is all I need to perform a database restore/import from the backup, or are there other files I should have to hand to complete this?</p>
[ { "answer_id": 11069206, "author": "Ash", "author_id": 23548, "author_profile": "https://Stackoverflow.com/users/23548", "pm_score": 4, "selected": false, "text": "_ib_logfile0\n_ib_logfile1\n_ibdata1\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7703/" ]
115,685
<p>I once wrote this line in a Java class. This compiled fine in Eclipse but not on the command line. </p> <p>This is on</p> <ul> <li>Eclipse 3.3</li> <li>JDK 1.5</li> <li>Windows XP Professional</li> </ul> <p>Any clues?</p> <p>Error given on the command line is:</p> <pre><code>Icons.java:16: code too large public static final byte[] compileIcon = { 71, 73, 70, 56, 57, 97, 50, ^ </code></pre> <p>The code line in question is:</p> <pre><code>public static final byte[] compileIcon = { 71, 73, 70, 56, 57, 97, 50, 0, 50, 0, -9, 0, 0, -1, -1, -1, -24, -72, -72, -24, -64, -64, -8, -16, -24, -8, -24, -24, -16, -24, -32, -1, -8, -8, 48, 72, -72, -24, -80, -80, 72, 96, -40, -24, -24, -8, 56, 88, -56, -24, -40, -48, -24, -48, -64, 56, 80, -64, 64, 88, -48, -56, -64, -64, -16, -24, -24, -32, -40, -40, -32, -88, -96, -72, -72, -72, -48, -56, -56, -24, -32, -32, -8, -8, -1, -24, -40, -56, -64, -72, -72, -16, -32, -40, 48, 80, -72, -40, -96, -104, -40, -96, -96, -56, -104, -104, 120, 88, -104, -40, -64, -80, -32, -88, -88, -32, -56, -72, -72, -80, -80, -32, -80, -88, 104, -96, -1, -40, -40, -40, -64, -104, -104, -32, -56, -64, -112, 104, 112, -48, -104, -112, -128, -112, -24, -72, -80, -88, -8, -8, -8, -64, -112, -120, 72, 104, -40, 120, 96, -96, -112, -96, -24, -112, -120, -72, -40, -88, -88, -48, -64, -72, -32, -72, -80, -48, -72, -88, -88, -72, -24, 64, 88, -56, -120, 96, 104, 88, -128, -72, 48, 56, 56, 104, 104, 120, 112, -120, -16, -128, 104, -88, -40, -48, -48, 88, -120, -24, 104, 88, -104, -40, -56, -72, -128, 112, -88, -128, 96, -88, -104, -88, -24, -96, -120, 120, -88, -128, -80, -56, -56, -64, 96, 120, -8, -96, -128, -88, -80, -96, -104, -32, -72, -72, 96, 104, 112, 96, -104, -8, -72, -112, -112, -64, -72, -80, 64, 64, 72, -128, -120, -96, -128, 88, 88, -56, -72, -80, 88, 96, 120, -72, -128, 112, 72, 112, -40, 96, 120, -56, 88, -112, -16, 64, 104, -48, -64, -80, -88, -88, -120, -80, 88, 88, 96, -56, -96, -120, -40, -56, -64, 96, 104, 120, -120, -80, -24, -104, -88, -40, -48, -72, -80, -64, -56, -16, -88, -112, -128, -32, -48, -56, -24, -16, -8, -64, -120, 120, -96, -96, -88, 80, -128, -24, -56, -72, -88, -96, 120, 88, -72, -112, 120, -64, -104, 120, -48, -56, -64, -120, -104, -32, -104, 120, -80, -96, -112, -120, 56, 88, -64, -128, 96, 64, 88, 120, -40, -80, -104, -120, -104, -128, 104, 96, -104, -24, -72, -120, -128, 56, 96, -56, -128, 112, 104, -48, -88, -112, 96, 96, 104, -104, -88, -72, -40, -88, -96, -72, -88, -96, -120, 120, 104, -80, -88, -96, 72, 72, 80, -120, 88, 96, 120, -120, -24, 96, -104, -16, 104, 80, 48, -56, -80, -96, -56, -88, -104, -104, 120, -88, -88, 120, 104, -72, -120, -120, -24, -32, -40, 112, 88, -104, 120, 96, -104, -32, -32, -32, -96, 96, 96, 80, 80, 88, 64, 88, 120, 72, 120, -40, 72, 88, 112, -88, -96, -104, -56, -80, -88, -72, -88, -104, -56, -64, -72, -80, -120, 104, -80, -120, -80, -112, 112, -88, 120, 112, 112, 112, -96, -24, -120, -120, -64, -120, 120, -80, 64, 96, -128, 96, 64, 64, 96, -128, -32, 80, 112, -24, 112, -120, -24, 104, -96, -8, 96, 120, -16, -88, 120, 120, -72, -56, -16, -128, -128, -128, -104, -120, -72, -64, -96, -120, -32, -64, -64, -40, -48, -56, -64, -88, -96, -64, -104, -72, -96, -88, -24, -104, -96, -40, -96, -128, 96, -128, -128, -96, 104, 88, 80, 112, -88, -8, -64, -104, -80, -96, -120, 112, 96, 120, -32, 56, 80, -72, -104, -88, -32, 104, -128, -24, -56, -88, -120, -80, -72, -8, -96, -128, -128, -64, -128, 96, -72, -96, -120, 72, 104, -32, -96, 96, 64, -72, -96, -112, -32, -40, -48, -64, -88, -112, -88, -128, 96, -88, -128, -88, -64, -64, -32, -128, -96, -32, -88, -104, -112, 32, 32, 64, -120, 104, -88, 120, -120, -16, -104, 120, -72, -24, -48, -56, -96, -96, -96, -64, 96, 96, 96, 64, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0, 0, 50, 0, 50, 0, 0, 8, -1, 0, 1, 8, 28, 72, -80, -96, -63, -125, 8, 19, 42, 92, -120, 112, 0, 3, 6, 12, 23, 6, -104, 72, -79, -94, -59, -117, 19, 39, -124, 64, -128, -128, 3, -121, 9, 19, 48, -118, -92, 24, 81, 33, -118, 8, 40, 7, -88, 84, -55, -64, 12, 6, 6, 45, 74, -54, 52, 8, 73, -60, 24, 22, 25, 92, 73, 40, 64, -96, -64, 74, -121, 24, 94, -58, -100, 25, -79, -59, 47, 17, 3, 52, -120, 88, -125, 105, 73, 6, 42, -102, -68, 96, -16, -71, 18, 3, -118, 6, 13, 14, -114, -36, 26, -64, 69, 7, 18, 28, -61, -110, -32, -32, -62, -54, -94, 72, -61, -48, -88, -40, 72, 34, -60, 4, 21, 23, -119, 14, -92, 80, -58, 6, -108, 10, 18, 44, 68, -8, 57, -96, -128, 16, 98, 70, -24, -48, 97, -45, 6, 4, 6, 16, 67, -27, 18, 52, -79, -52, -89, -46, 49, -105, -74, -32, 109, -45, -85, -63, -49, 2, 13, 88, -51, -62, 5, 40, 80, 31, 91, 103, 20, 11, -116, 32, -124, -81, -54, 2, 40, -58, -40, -103, -59, -122, 13, 43, 51, 12, 122, 106, 96, -48, 0, -105, 40, 29, 106, 32, 17, 20, -64, -69, -73, -17, -33, -68, 25, 113, 13, 80, -125, 44, -102, 72, 108, -84, -88, 80, 49, -127, -61, -94, 28, -97, -108, -4, -98, -103, 102, 9, -127, -21, -40, -81, 23, -32, 35, -126, 39, -10, 2, 32, -116, 29, -1, 27, -74, 37, -40, 29, 60, 90, -60, -120, -90, 0, -122, -118, -23, -107, 54, -36, -72, -15, 2, 66, -61, -23, -39, 24, -8, -36, -7, -108, -27, -128, 44, -59, -112, -16, -64, 67, 3, -39, 21, 72, 0, 6, 34, 120, -31, -123, 124, 124, 52, 16, 84, 3, -119, -88, 82, -62, 28, -2, 21, 4, -36, -123, -83, -92, -96, 97, 13, 20, 117, 112, 2, -121, 24, 77, -128, 6, 48, -64, 72, -93, -62, 31, 104, -56, 48, 68, 16, 65, 112, 49, 29, 67, 82, 8, 24, 72, 118, 18, 84, 48, 66, 6, 63, 72, 96, 96, 1, 26, -128, 64, -97, 8, 50, 24, 114, -64, -112, -22, -51, -28, 7, 24, 77, 116, -15, 75, 1, 123, 53, 2, -63, 15, 22, 88, 0, 1, 5, 44, 72, 32, -127, 74, -78, -47, -122, -62, 27, -90, -24, 49, -28, 1, 69, -106, -108, 76, 21, -99, 8, -127, -119, 29, -81, 60, 41, -63, 15, 16, -116, 80, 65, -114, 22, -44, 40, 72, 6, 111, 60, 4, 77, 3, 34, -124, 1, -60, -105, 7, 40, 96, -31, -123, -68, 49, -111, 66, 30, 32, 102, -92, 66, 30, 86, 60, -47, -63, 12, 30, 42, 58, 67, 13, 51, 120, -32, 1, 35, 30, 112, 112, -62, 39, -114, -80, 24, -124, 116, 47, 30, 116, 6, 15, -120, 24, -104, 93, 3, -105, 44, -79, 12, 11, -103, -116, 112, 35, 20, 52, -96, 64, 3, 32, 91, -40, -1, 114, 5, -97, 126, -106, 36, 5, 24, -106, -67, 103, 26, 3, 32, -68, -14, 10, 20, 44, 88, -78, -124, 37, 91, -124, -47, -33, -105, 112, -56, -28, 7, -103, -70, -86, 116, -57, 29, 52, 80, 37, -101, 8, 54, 24, 99, -121, 17, 82, -108, -80, 0, -83, 7, 93, 56, 70, 14, 41, -96, -78, -107, 11, -117, -48, 97, -42, 12, 127, 32, 64, 66, 91, 19, -96, -88, -94, 35, -16, 110, 10, -88, 65, 103, 76, -62, 67, 19, 114, -120, -102, 93, 49, 107, -108, 65, -121, 29, -121, -36, 65, -116, 16, 24, -32, 121, -125, 33, -70, 108, -96, 112, -97, 37, 5, -127, 100, 23, -128, -4, 68, 65, 5, 123, -103, 102, -63, 24, 101, -20, 49, -51, 33, -121, -40, 80, 65, 9, 122, 40, -84, 112, -78, 17, 73, 81, 69, -110, -110, -28, -38, -105, 9, 84, -30, 69, 21, -106, 60, 106, 32, 68, 25, -127, -96, -96, -25, 6, 14, 56, -96, 112, -83, 90, 81, 116, 2, -72, 57, 16, 66, 8, 88, 28, 49, 26, 66, 8, 51, 60, -15, -60, 9, 51, -128, -75, -82, 91, 19, 116, 96, -87, 12, 31, 84, 93, -75, 18, 91, 13, 100, -126, -67, 125, 72, 50, 72, 45, 63, 89, -112, 1, 5, 20, -104, 96, 65, 1, 38, -4, 48, 49, 4, -82, 60, 84, 48, 13, -90, 92, -111, -13, -36, 60, 39, -44, 66, 40, 96, -12, -47, -59, 32, 81, -20, -1, -15, 19, 4, 18, 68, 80, 64, 5, 72, -80, 0, -127, 9, 17, 72, -112, 9, 20, -106, -48, -48, -86, -79, 56, -49, 77, -14, 66, -76, -100, -68, 119, 20, 59, 44, -15, 19, -53, 20, 0, 30, 103, -101, 110, -66, 97, -122, 25, 52, 44, 33, -125, -74, 11, -92, -98, 115, -35, 90, -55, 1, 52, 33, 83, 76, 33, -118, 10, 97, 73, -70, 81, 7, 29, 44, -35, 1, -46, 29, 76, -22, 2, 7, 30, -84, 50, -60, 7, 48, 60, 114, -11, 112, 0, -124, -95, 67, 21, -110, 96, -66, -61, 14, 12, -84, 36, -27, 8, -99, -101, 80, -128, 5, 72, -36, -104, -55, 23, -92, 83, -95, -116, 19, 14, -92, 46, 62, -21, 8, 21, 1, 68, 9, -93, -124, -78, 3, 51, 59, -68, -84, 82, -30, 72, 84, 64, 1, 18, 121, 85, 0, -123, 32, -126, -80, -112, 6, -56, 11, -32, 32, -2, -28, 10, -71, -64, 5, -80, 48, 7, 74, 56, -63, 16, 58, -40, 65, 45, -28, -16, 5, -108, 56, 16, 37, -112, -80, 17, 5, 70, -16, 6, 87, 124, -127, 5, -98, 0, -126, 3, 30, -128, -125, 14, -30, 64, 1, 2, 12, -95, 8, 67, 8, 0, -118, 108, -126, 8, 31, -16, 1, 40, 100, -96, -120, 20, 76, 33, 18, 121, -104, 64, 88, 102, 24, 2, -78, 48, 66, 5, -101, -96, 26, 12, 118, -72, 67, 100, 12, 103, 34, 4, 89, 65, 18, -1, 72, -127, -125, 2, 30, 80, 7, -107, -24, -37, 22, 26, -15, -66, 2, 20, -96, 17, 12, 64, 65, 52, -30, -74, -128, 7, 88, -47, -118, -28, 99, -120, 2, 122, -112, -124, 36, -100, 34, 1, 14, -48, -126, 26, 74, -128, -121, 80, 68, 33, 10, -127, -80, -127, 6, 98, -122, 1, 42, 120, 34, 11, 27, -72, -94, 21, 1, 56, 19, 50, 116, -47, -117, -89, 32, -59, 3, 28, 112, 5, 39, -108, 0, -119, 81, 16, -123, 17, 108, 96, 6, 42, -8, 65, 91, 15, 72, -128, 28, -77, -120, 16, -116, -64, -30, 25, 113, -120, 100, 36, -101, -15, 8, 24, -84, 80, 6, 46, -116, 93, 36, -124, -9, 1, 34, 120, -46, -109, 71, -8, 33, 73, 16, 66, -122, 21, -12, -32, -108, 61, 40, 5, 47, 18, 48, -121, 62, -2, 113, 18, 58, 112, -62, 6, 18, 64, -53, 90, 50, 82, 49, 10, 40, -62, 41, 11, -63, 75, 94, -68, 32, 117, 106, -16, -93, 30, 18, 89, -53, 4, -60, 64, 52, 10, 81, -128, 47, 86, -64, 76, 102, -106, 34, 23, 47, -48, -126, 22, 28, 80, 76, 90, -34, 82, 32, 6, -56, -90, 54, 69, 25, 0, 38, -64, -126, 11, 71, 8, -89, 56, -107, -96, 8, 31, -104, -45, 7, 68, -32, 2, 55, -127, 72, -108, 11, -112, -95, 8, 49, -120, -89, 60, 71, -15, -126, 122, 38, -32, -102, -56, 60, -120, 2, 110, 80, 51, -124, 126, -58, -94, 8, -62, -88, -25, 49, -13, 41, 23, 5, -112, -31, 6, 8, 93, 65, 64, -15, -39, -56, 117, 98, -124, 9, 51, -72, -59, 45, 56, -95, 78, -121, 6, -128, -96, 5, -39, 39, 67, 49, -54, -47, -114, 122, -44, 32, 1, 1, 0, 59 }; </code></pre>
[ { "answer_id": 116184, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 3, "selected": true, "text": "class MyClass\n{\n private String[] s = { \"a\", \"b\", \"c\"}\n\n public MyClass()\n {\n }\n class MyClass\n{\n private String[] s;\n\n private void FunnyName$Method()\n {\n s[0] = \"a\";\n s[1] = \"b\";\n s[2] = \"c\";\n }\n public MyClass()\n {\n FunnyName$Method();\n }\n public class Icons\n{\n public static final byte[] compileIcon;\n static\n {\n compileIcon = readFileToBytes(\"compileIcon.gif\");\n }\n //... (I assume there are several other icons)\n private static byte[] readFileToBytes(String filename)\n {\n try {\n File file = new File(filename);\n byte[] bytes = new byte[(int)file.length()];\n FileInputStream fin = new FileInputStream(file);\n fin.read(bytes);\n fin.close();\n }\n catch (Exception e) {\n e.printStackTrace();\n System.exit(1);\n }\n }\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9425/" ]
115,692
<p>For example I have such query:</p> <pre><code>Query q = sess.createQuery("from Cat cat"); List cats = q.list(); </code></pre> <p>If I try to make something like this it shows the following warning </p> <pre><code>Type safety: The expression of type List needs unchecked conversion to conform to List&lt;Cat&gt; List&lt;Cat&gt; cats = q.list(); </code></pre> <p>Is there a way to avoid it?</p>
[ { "answer_id": 115719, "author": "Dave L.", "author_id": 3093, "author_profile": "https://Stackoverflow.com/users/3093", "pm_score": 2, "selected": false, "text": "@SuppressWarnings(\"unchecked\")" }, { "answer_id": 115952, "author": "Joe Dean", "author_id": 5917, "author_profile": "https://Stackoverflow.com/users/5917", "pm_score": -1, "selected": false, "text": " Query q = sess.createQuery(\"from Cat cat\");\n List<?> results =(List<?>) q.list();\n List<Cat> cats = new ArrayList<Cat>();\n for(Object result:results) {\n Cat cat = (Cat) result;\n cats.add(cat);\n }\n" }, { "answer_id": 116071, "author": "cretzel", "author_id": 18722, "author_profile": "https://Stackoverflow.com/users/18722", "pm_score": 4, "selected": false, "text": "@SuppressWarnings(\"unchecked\") public List<Cat> findAll() {\n Query q = sess.createQuery(\"from Cat cat\");\n @SuppressWarnings(\"unchecked\")\n List<Cat> cats = q.list();\n return cats;\n}\n" }, { "answer_id": 118976, "author": "Matt Quail", "author_id": 15790, "author_profile": "https://Stackoverflow.com/users/15790", "pm_score": 8, "selected": true, "text": "@SuppressWarnings q.list() @SuppressWarnings List<Cat> cats = MyHibernateUtils.listAndCast(q);\n\n...\n\npublic static <T> List<T> listAndCast(Query q) {\n @SuppressWarnings(\"unchecked\")\n List list = q.list();\n return list;\n}\n Ignore unavoidable generic type problems due to raw APIs Query q.list() List .iterate()" }, { "answer_id": 9969062, "author": "Tony Shih", "author_id": 1161713, "author_profile": "https://Stackoverflow.com/users/1161713", "pm_score": 0, "selected": false, "text": "List<Cat> cats = Collections.checkedList(Cat.class, q.list());\n List<Cat> cats = Collections.checkedList(q.list(), Cat.class);\n List list = q.list();\n List<T> list = q.list();\n" }, { "answer_id": 13729284, "author": "Paulo Merson", "author_id": 317522, "author_profile": "https://Stackoverflow.com/users/317522", "pm_score": 3, "selected": false, "text": "Query q = sess.createQuery(\"from Cat cat\");\nArrayList cats = q.list();\n Query q = sess.createQuery(\"from Cat cat\");\nArrayList<Cat> cats = MyHibernateUtils.listAndCast(q);\n" }, { "answer_id": 24768836, "author": "Brian Ngure", "author_id": 3842765, "author_profile": "https://Stackoverflow.com/users/3842765", "pm_score": -1, "selected": false, "text": "Query q = sess.createQuery(\"from Cat cat\");\nList<?> results = q.list();\nfor (Object obj : results) {\n Cat cat = (Cat) obj;\n}\n" }, { "answer_id": 30268139, "author": "antonpp", "author_id": 3008684, "author_profile": "https://Stackoverflow.com/users/3008684", "pm_score": 5, "selected": false, "text": "Java Persistence 2.0 createQuery(String, Class<T>) TypedQuery<T> TypedQuery Query Query q = sess.createQuery(\"from Cat cat\", Cat.class);\nList<Cat> cats = q.list();\n" }, { "answer_id": 33657790, "author": "xjodoin", "author_id": 1022974, "author_profile": "https://Stackoverflow.com/users/1022974", "pm_score": -1, "selected": false, "text": "Cat cat = from(Cat.class);\norg.torpedoquery.jpa.Query<Entity> select = select(cat);\nList<Cat> cats = select.list(entityManager);\n" }, { "answer_id": 36424573, "author": "shivam oberoi", "author_id": 1155906, "author_profile": "https://Stackoverflow.com/users/1155906", "pm_score": 4, "selected": false, "text": "TypedQuery Query Query q = sess.createQuery(\"from Cat cat\", Cat.class);\nList<Cat> cats = q.list();\n TypedQuery<Cat> q1 = sess.createQuery(\"from Cat cat\", Cat.class);\nList<Cat> cats = q1.list();\n" }, { "answer_id": 48717730, "author": "David DeMar", "author_id": 1236018, "author_profile": "https://Stackoverflow.com/users/1236018", "pm_score": 2, "selected": false, "text": "Query<T> @SuppressWarnings Session.createQuery Query<T> Query<Cat> query = session.createQuery(\"FROM Cat\", Cat.class);\nList<Cat> cats = query.list();\n public Integer count() {\n Query<Integer> query = sessionFactory.getCurrentSession().createQuery(\"SELECT COUNT(id) FROM Cat\", Integer.class);\n return query.getSingleResult();\n}\n public List<Object[]> String getName() {\n Query<Object[]> query = sessionFactory.getCurrentSession().createQuery(\"SELECT id, name FROM Cat\", Object[].class);\n return query.list();\n}\n" }, { "answer_id": 52361208, "author": "Rakesh Singh Balhara", "author_id": 3855723, "author_profile": "https://Stackoverflow.com/users/3855723", "pm_score": -1, "selected": false, "text": "TypedQuery<EntityName> createQuery = entityManager.createQuery(\"from EntityName\", EntityName.class);\nList<EntityName> resultList = createQuery.getResultList();\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20128/" ]
115,694
<p>Anyone know how to turn off code folding in visual studio 2008? Some of my colleagues love it, but I personally always want to see all the code, and never want code folded out of sight. I'd like a setting that means my copy of Visual Studio never folds <code>#regions</code>or function bodies. </p>
[ { "answer_id": 16943723, "author": "xks", "author_id": 1012881, "author_profile": "https://Stackoverflow.com/users/1012881", "pm_score": 0, "selected": false, "text": "\n Private Sub DocumentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened\n If (Not Document Is Nothing) Then\n If (Document.FullName.ToLower().EndsWith(\".cs\")) Then\n Try\n DTE.ExecuteCommand(\"Edit.ExpandAllOutlining\")\n Catch ex As Exception\n End Try\n End If\n End If\n End Sub\n\n Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated\n If (Not GotFocus Is Nothing) Then\n If (Not GotFocus.Document Is Nothing) Then\n If (GotFocus.Document.FullName.ToLower().EndsWith(\".cs\")) Then\n Try\n DTE.ExecuteCommand(\"Edit.ExpandAllOutlining\")\n Catch ex As Exception\n End Try\n End If\n End If\n End If\n End Sub\n\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115694", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6722/" ]
115,703
<p>I have some template code that I would prefer to have stored in a CPP file instead of inline in the header. I know this can be done as long as you know which template types will be used. For example:</p> <p><strong>.h file</strong></p> <pre><code>class foo { public: template &lt;typename T&gt; void do(const T&amp; t); }; </code></pre> <p><strong>.cpp file</strong></p> <pre><code>template &lt;typename T&gt; void foo::do(const T&amp; t) { // Do something with t } template void foo::do&lt;int&gt;(const int&amp;); template void foo::do&lt;std::string&gt;(const std::string&amp;); </code></pre> <p>Note the last two lines - the foo::do template function is only used with ints and std::strings, so those definitions mean the app will link.</p> <p>My question is - is this a nasty hack or will this work with other compilers/linkers? I am only using this code with VS2008 at the moment but will be wanting to port to other environments.</p>
[ { "answer_id": 115792, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 2, "selected": false, "text": "export" }, { "answer_id": 13952386, "author": "namespace sid", "author_id": 708995, "author_profile": "https://Stackoverflow.com/users/708995", "pm_score": 7, "selected": false, "text": "template<typename T>\nclass foo\n{\npublic:\n void bar(const T &t);\n};\n template <class T>\nvoid foo<T>::bar(const T &t)\n{ }\n\n// Explicit template instantiation\ntemplate class foo<int>;\n" }, { "answer_id": 15561347, "author": "Didii", "author_id": 2158015, "author_profile": "https://Stackoverflow.com/users/2158015", "pm_score": 1, "selected": false, "text": "template <typename T, ...> #include \"file.inl\"" }, { "answer_id": 41292751, "author": "Cameron Tacklind", "author_id": 4612476, "author_profile": "https://Stackoverflow.com/users/4612476", "pm_score": 5, "selected": false, "text": "lib/foo.hpp #pragma once\n\ntemplate <typename T>\nclass foo {\npublic:\n void bar(const T&);\n};\n lib/foo.cpp // Include guard here, just in case\n#pragma once\n\n#include \"foo.hpp\"\n\ntemplate <typename T>\nvoid foo::bar(const T& arg) {\n // Do something with `arg`\n}\n foo.MyType.cpp foo<MyType> // Consider adding \"anti-guard\" to make sure it's not included in other translation units\n#if __INCLUDE_LEVEL__\n #error \"Don't include this file\"\n#endif\n\n// Yes, we include the .cpp file\n#include <lib/foo.cpp>\n#include \"MyType.hpp\"\n\ntemplate class foo<MyType>;\n foo.MyType.hpp foo<MyType> .cpp #pragma once\n\n#include <lib/foo.hpp>\n#include \"MyType.hpp\"\n\n// Declare `temp`. Doesn't need to include `foo.cpp`\nextern foo<MyType> temp;\n examples.cpp foo<MyType> #include \"foo.MyType.hpp\"\n\nMyType instance;\n\n// Define `temp`. Doesn't need to include `foo.cpp`\nfoo<MyType> temp;\n\nvoid example_1() {\n // Use `temp`\n temp.bar(instance);\n}\n\nvoid example_2() {\n // Function local instance\n foo<MyType> temp2;\n\n // Use templated library function\n temp2.bar(instance);\n}\n error.cpp #include <lib/foo.hpp>\n\n// Causes compilation errors at link time since we never had the explicit instantiation:\n// template class foo<int>;\n// GCC linker gives an error: \"undefined reference to `foo<int>::bar()'\"\nfoo<int> nonExplicitlyInstantiatedTemplate;\nvoid linkerError() {\n nonExplicitlyInstantiatedTemplate.bar();\n}\n foo<int>" }, { "answer_id": 56801030, "author": "TarmoPikaro", "author_id": 2338477, "author_profile": "https://Stackoverflow.com/users/2338477", "pm_score": 3, "selected": false, "text": "//test_template.h:\n#pragma once\n#include <cstdio>\n\ntemplate <class T>\nclass DemoT\n{\npublic:\n void test()\n {\n printf(\"ok\\n\");\n }\n};\n\ntemplate <>\nvoid DemoT<int>::test()\n{\n printf(\"int test (int)\\n\");\n}\n\n\ntemplate <>\nvoid DemoT<bool>::test()\n{\n printf(\"int test (bool)\\n\");\n}\n error : multiple definition of `DemoT<int>::test()'; your.o: .../test_template.h:16: first defined here\n //test_template.h:\n#pragma once\n#include <cstdio>\n\ntemplate <class T>\nclass DemoT\n{\npublic:\n void test()\n {\n printf(\"ok\\n\");\n }\n};\n\ntemplate <>\nvoid DemoT<int>::test();\n\ntemplate <>\nvoid DemoT<bool>::test();\n\n// Instantiate parametrized template classes, implementation resides on .cpp side.\ntemplate class DemoT<bool>;\ntemplate class DemoT<int>;\n //test_template.cpp:\n#include \"test_template.h\"\n\ntemplate <>\nvoid DemoT<int>::test()\n{\n printf(\"int test (int)\\n\");\n}\n\n\ntemplate <>\nvoid DemoT<bool>::test()\n{\n printf(\"int test (bool)\\n\");\n}\n error LNK2019: unresolved external symbol \"public: void __cdecl DemoT<int>::test(void)\" (?test@?$DemoT@H@@QEAAXXZ) referenced in function\n //test_template.h:\n#pragma once\n#include <cstdio>\n\ntemplate <class T>\nclass DemoT\n{\npublic:\n void test()\n {\n printf(\"ok\\n\");\n }\n};\n\n#ifdef _WIN32\n #define DLL_EXPORT __declspec(dllexport) \n#else\n #define DLL_EXPORT\n#endif\n\ntemplate <>\nvoid DLL_EXPORT DemoT<int>::test();\n\ntemplate <>\nvoid DLL_EXPORT DemoT<bool>::test();\n" }, { "answer_id": 61783715, "author": "KronuZ", "author_id": 3165824, "author_profile": "https://Stackoverflow.com/users/3165824", "pm_score": 2, "selected": false, "text": "class Model\n{\n template <class T>\n void build(T* b, uint32_t number);\n};\n #include \"Model.h\"\ntemplate <class T>\nvoid Model::build(T* b, uint32_t number)\n{\n //implementation\n}\n\nvoid TemporaryFunction()\n{\n Model m;\n m.build<B1>(new B1(),1);\n m.build<B2>(new B2(), 1);\n m.build<B3>(new B3(), 1);\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
115,720
<p>Is there a command in classic ASP I can use to tell the browser not to pull the page from it's cache, or, to not cache, or clear the cache of my page?</p>
[ { "answer_id": 115734, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 0, "selected": false, "text": "Response.Expires = -1\n" }, { "answer_id": 115756, "author": "Forgotten Semicolon", "author_id": 1960, "author_profile": "https://Stackoverflow.com/users/1960", "pm_score": 4, "selected": true, "text": "<meta http-equiv=\"Pragma\" content=\"no-cache\" />\n<meta http-equiv=\"Expires\" content=\"Fri, 01 Jan 1999 1:00:00 GMT\" />\n<meta http-equiv=\"Last-Modified\" content=\"0\" />\n<meta http-equiv=\"Cache-Control\" content=\"no-cache, must-revalidate\" />\n <% \n Response.CacheControl = \"no-cache\"\n Response.AddHeader \"Pragma\", \"no-cache\"\n Response.Expires = -1\n%>\n" }, { "answer_id": 115937, "author": "Jim", "author_id": 8427, "author_profile": "https://Stackoverflow.com/users/8427", "pm_score": 2, "selected": false, "text": "<meta> Pragma Cache-Control: no-cache" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5836/" ]
115,764
<p>I have some Python code that creates a Calendar object based on parsed VEvent objects from and iCalendar file.</p> <p>The calendar object just has a method that adds events as they get parsed.</p> <p>Now I want to create a factory function that creates a calendar from a file object, path, or URL.</p> <p>I've been using the <a href="http://codespeak.net/icalendar/" rel="nofollow noreferrer">iCalendar python module</a>, which implements a factory function as a class method directly on the Class that it returns an instance of:</p> <pre><code>cal = icalendar.Calendar.from_string(data) </code></pre> <p>From what little I know about Java, this is a common pattern in Java code, though I seem to find more references to a factory method being on a different class than the class you actually want to instantiate instances from.</p> <p>The question is, is this also considered Pythonic ? Or is it considered more pythonic to just create a module-level method as the factory function ?</p>
[ { "answer_id": 115853, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 4, "selected": false, "text": "from_string from_xml from_JSON from_YAML" }, { "answer_id": 115933, "author": "Thomas Wouters", "author_id": 17624, "author_profile": "https://Stackoverflow.com/users/17624", "pm_score": 0, "selected": false, "text": "class dict_with_fromkeys(dict):\n @classmethod\n def fromkeys(cls, keys, value=None):\n self = cls()\n for key in keys:\n self[key] = value\n return self\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2900/" ]
115,773
<p>I'm using python and CherryPy to create a simple internal website that about 2 people use. I use the built in webserver with CherryPy.quickstart and never messed with the config files. I recently changed machines so I installed the latest Python and cherrypy and when I run the site I can access it from localhost:8080 but not through the IP or the windows machine name. It could be a machine configuration difference or a newer version of CherryPy or Python. Any ideas how I can bind to the correct IP address?</p> <p>Edit: to make it clear, I currently don't have a config file at all.</p>
[ { "answer_id": 115826, "author": "nosklo", "author_id": 17160, "author_profile": "https://Stackoverflow.com/users/17160", "pm_score": 5, "selected": true, "text": "cherrypy.server.socket_host = 'www.machinename.com'\ncherrypy.engine.start()\ncherrypy.engine.block()\n" }, { "answer_id": 152012, "author": "fumanchu", "author_id": 23692, "author_profile": "https://Stackoverflow.com/users/23692", "pm_score": 5, "selected": false, "text": "server.socket_host: '0.0.0.0'\n [global]\nserver.socket_host: '0.0.0.0'\n cherrypy.server.socket_host = '0.0.0.0'\n" }, { "answer_id": 41367529, "author": "mzobe", "author_id": 7351049, "author_profile": "https://Stackoverflow.com/users/7351049", "pm_score": 3, "selected": false, "text": "import cherrypy\n\nclass HelloWorld(object):\n def index(self):\n return \"Hello World!\"\n index.exposed = True\n\ncherrypy.server.socket_host = '0.0.0.0' # put it here \ncherrypy.quickstart(HelloWorld())\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115773", "https://Stackoverflow.com", "https://Stackoverflow.com/users/852/" ]
115,809
<p>Many beginning programmers write code like this:</p> <pre><code>sub copy_file ($$) { my $from = shift; my $to = shift; `cp $from $to`; } </code></pre> <p>Is this bad, and why? Should backticks ever be used? If so, how?</p>
[ { "answer_id": 115810, "author": "raldi", "author_id": 7598, "author_profile": "https://Stackoverflow.com/users/7598", "pm_score": 3, "selected": false, "text": "my $cmd = \"./do_something.sh foo bar\";\nmy $output = `$cmd`;\n\nif ($?) {\n die \"Error running [$cmd]\";\n}\n" }, { "answer_id": 115817, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 3, "selected": false, "text": "system() system('cp', 'foo', 'bar')" }, { "answer_id": 115846, "author": "Commodore Jaeger", "author_id": 4659, "author_profile": "https://Stackoverflow.com/users/4659", "pm_score": 2, "selected": false, "text": "system(\"cp $from $to\") == 0\n or die \"Unable to copy $from to $to!\";\n my $user = `whoami`;\nchomp $user;\nprint \"Hello, $user!\\n\";\n open WHO, \"who|\"\n or die \"who failed\";\nwhile(<WHO>) {\n # Do something with each line\n}\nclose WHO;\n" }, { "answer_id": 116114, "author": "Jon Ericson", "author_id": 1438, "author_profile": "https://Stackoverflow.com/users/1438", "pm_score": 1, "selected": false, "text": "my $cmd = 'command > /dev/null';\nsystem($cmd) == 0 or die \"system $cmd failed: $?\"\n my $cmd = 'command 2> error_file.txt > /dev/null';\n" }, { "answer_id": 117306, "author": "Sam Kington", "author_id": 6832, "author_profile": "https://Stackoverflow.com/users/6832", "pm_score": 2, "selected": false, "text": "my $user = `/bin/whoami`;\n my $result = `/bin/cp $from $to`;\n" }, { "answer_id": 118904, "author": "pjf", "author_id": 19422, "author_profile": "https://Stackoverflow.com/users/19422", "pm_score": 6, "selected": true, "text": "$? capture() system() capture() system() perldoc #!/usr/bin/perl -w\nuse strict;\nuse IPC::System::Simple qw(capture);\n\n# Make sure we're called with command-line arguments.\n@ARGV or die \"Usage: $0 arguments\\n\";\n\nmy $documentation = capture('perldoc', @ARGV);\n" }, { "answer_id": 123033, "author": "user21308", "author_id": 21308, "author_profile": "https://Stackoverflow.com/users/21308", "pm_score": 0, "selected": false, "text": "\nsub run_cmd {\n my $cmd = shift @_;\n my @args = @_;\n\n my $fh; # file handle\n my $pid = open($fh, '-|');\n defined($pid) or die \"Could not fork\";\n if ($pid == 0) {\n open STDERR, '>/dev/null';\n # setuid() if necessary\n exec ($cmd, @args) or exit 1;\n }\n wait; # may want to time out here?\n if ($? >> 8) { die \"Error running $cmd: [$?]\"; }\n while (<$fh>) {\n # Have fun with the output of $cmd\n }\n close $fh;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7598/" ]
115,813
<p>I have been trying to produce a statically linked "single binary" version of my game for windows. I want to link with sdl, sdl_image and sdl_mixer which in turn pull in a few support libraries. Unfortunately I haven't found a way to get them all to compile and link using cygwin/mingw/gcc. As far as I can tell all existing public versions are only shared libraries / dlls.</p> <p>Please note that I'm not talking about licencing here. The source will be open thus the GPL/LGPLness of sdl is not relevant.</p>
[ { "answer_id": 525124, "author": "Alex Lyman", "author_id": 5897, "author_profile": "https://Stackoverflow.com/users/5897", "pm_score": 6, "selected": true, "text": "sdl-config --libs sdl-config --static-libs sdl-config --static-libs -Wl,-Bstatic -Wl,-Bdynamic SDLLIBS=`sdl-config --libs`\n SDLLIBS=-Wl,-Bstatic `sdl-config --static-libs` -Wl,-Bdynamic\n -static" }, { "answer_id": 1416421, "author": "singpolyma", "author_id": 8611, "author_profile": "https://Stackoverflow.com/users/8611", "pm_score": 0, "selected": false, "text": "-Wl,Bstatic -lSDL_image `sdl-config --libs` -lpng12 -lz -ltiff -ljpeg -lasound -laudio -lesd -Wl,-Bdynamic `directfb-config --libs` -lpulse-simple -lcaca -laa -ldl\n _ _" }, { "answer_id": 23585684, "author": "Anónimo", "author_id": 3624163, "author_profile": "https://Stackoverflow.com/users/3624163", "pm_score": 1, "selected": false, "text": "D:\\prg_desa\\zsdl2>g++ bar.cpp main.cpp -o pepe1 -ID:\\SDL2-2.0.3\\i686-w64-mingw32\\include\\SDL2 -LD:\\SDL2-2.0.3\\i686-w64-mingw32\\lib -lmingw32 -lSDL2main -lSDL2 -mwindow" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20555/" ]
115,819
<p>My machine is seriously underpowered, and I think I need to start conserving every spare cycle. I know that my Gnome environment seems to underperform compared to my coworkers' KDE setups. But if I'm going to make that big of a switch, I might as well consider running something even lighter.</p> <p>Is it possible to survive on a lightweight window manager and still run modern apps (Firefox, Eclipse, OpenOffice)? What's a good candidate window manager for me to try, and what do I need to know?</p>
[ { "answer_id": 20819825, "author": "gavenkoa", "author_id": 173149, "author_profile": "https://Stackoverflow.com/users/173149", "pm_score": 1, "selected": false, "text": "Xlib ~/.fvwm/config" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18103/" ]
115,835
<p>I am looking into an image processing problem for semi-real time detection of certain scenarios. My goal is to have the live video arrive as Motion JPEG frames in my Java code <em>somehow</em>. </p> <p>I am familiar with the <a href="http://java.sun.com/javase/technologies/desktop/media/jmf/" rel="noreferrer">Java Media Framework</a> and, sadly, I think we can consider that an effectively dead API. I am also familiar with <a href="http://www.axis.com/" rel="noreferrer">Axis boxes</a> and, while I really like their solution, I would appreciate any critical feedback on my specific points of interest. </p> <p>This is how I define "best" for the purpose of this discussion:</p> <ul> <li>Latency - if I'm controlling the camera using this video stream, I would like to keep my round-trip latency at less than 100 milliseconds if possible. That's measured as the time between my control input to the time when I see the visible change. EDIT some time later: another thing to keep in mind is that camera control is likely to be a combination of manual and automatic (event triggers). We need to see those pictures right away, even if the high quality feed is archived separately.</li> <li>Cost - free / open source is better than not free.</li> <li>Adjustable codec parameters - I need to be able to tune the codec for certain situations. Sometimes a high-speed low-resolution stream is actually easier to process.</li> <li>"Integration" with Java - how much trouble is it to hook this solution to my code? Am I sending packets over a socket? Hitting URLs? Installing Direct3D / JNI combinations?</li> <li>Windows / Linux / both? - I would prefer an operating system agnostic solution because I have to deliver to several flavors of OS but there may be a solution that is optimal for one but not the other.</li> </ul> <p>NOTE: I am aware of other image / video capture codecs and that is not the focus of this question. I am specifically <em>not</em> interested in streaming APIs (e.g., MPEG4) due to the loss of frame accuracy. However, if there is a solution to my question that delivers another frame-accurate data stream, please chime in.</p> <p>Follow-up to this question: at this point, I am strongly inclined to buy appliances such as the <a href="http://www.axis.com/products/video/video_server/index.htm" rel="noreferrer">Axis video encoders</a> rather than trying to capture the video in software or on the PC directly. However, if someone has alternatives, I'd love to hear them.</p>
[ { "answer_id": 9046373, "author": "gtiwari333", "author_id": 607637, "author_profile": "https://Stackoverflow.com/users/607637", "pm_score": 3, "selected": false, "text": "import com.googlecode.javacv.OpenCVFrameGrabber;\n\nimport com.googlecode.javacv.cpp.opencv_core.IplImage;\nimport static com.googlecode.javacv.cpp.opencv_highgui.*;\n\npublic class CaptureImage {\n private static void captureFrame() {\n // 0-default camera, 1 - next...so on\n final OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);\n try {\n grabber.start();\n IplImage img = grabber.grab();\n if (img != null) {\n cvSaveImage(\"capture.jpg\", img);\n }\n } catch (Exception e) {\n e.printStackTrace();\n }\n }\n public static void main(String[] args) {\n captureFrame();\n }\n}\n" }, { "answer_id": 15982439, "author": "syb0rg", "author_id": 1937270, "author_profile": "https://Stackoverflow.com/users/1937270", "pm_score": 0, "selected": false, "text": "import java.awt.image.BufferedImage;\nimport java.io.File;\n\nimport javax.swing.JFrame;\n\nimport com.googlecode.javacv.CanvasFrame;\nimport com.googlecode.javacv.OpenCVFrameGrabber;\nimport com.googlecode.javacv.OpenCVFrameRecorder;\nimport com.googlecode.javacv.cpp.opencv_core.IplImage;\n\npublic class Webcam implements Runnable {\n\n IplImage image;\n static CanvasFrame frame = new CanvasFrame(\"Web Cam\");\n public static boolean running = false;\n\n public Webcam()\n {\n frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n }\n\n @Override\n public void run()\n {\n try\n {\n grabber.setImageWidth(800);\n grabber.setImageHeight(600);\n grabber.start();\n while (running)\n {\n IplImage cvimg = grabber.grab();\n BufferedImage image;\n if (cvimg != null)\n {\n // opencv_core.cvFlip(cvimg, cvimg, 1); // mirror\n // show image on window\n image = cvimg.getBufferedImage();\n frame.showImage(image);\n }\n }\n grabber.stop();\n frame.dispose();\n } catch (Exception e)\n {\n e.printStackTrace();\n }\n }\n\n public static void main(String... args)\n {\n Webcam webcam = new Webcam();\n webcam.start();\n }\n\n public void start()\n {\n new Thread(this).start();\n running = true;\n }\n\n public void stop()\n {\n running = false;\n }\n}\n" }, { "answer_id": 17839510, "author": "Gabriel Ambrósio Archanjo", "author_id": 2420599, "author_profile": "https://Stackoverflow.com/users/2420599", "pm_score": 1, "selected": false, "text": "import javax.swing.JFrame;\nimport marvin.gui.MarvinImagePanel;\nimport marvin.image.MarvinImage;\nimport marvin.video.MarvinJavaCVAdapter;\nimport marvin.video.MarvinVideoInterface;\n\npublic class SimpleVideoTest extends JFrame implements Runnable{\n\n private MarvinVideoInterface videoAdapter;\n private MarvinImage image;\n private MarvinImagePanel videoPanel;\n\n public SimpleVideoTest(){\n super(\"Simple Video Test\");\n\n // Create the VideoAdapter and connect to the camera\n videoAdapter = new MarvinJavaCVAdapter();\n videoAdapter.connect(0);\n\n // Create VideoPanel\n videoPanel = new MarvinImagePanel();\n add(videoPanel);\n\n // Start the thread for requesting the video frames \n new Thread(this).start();\n\n setSize(800,600);\n setVisible(true);\n }\n\n public static void main(String[] args) {\n SimpleVideoTest t = new SimpleVideoTest();\n t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n }\n\n @Override\n public void run() {\n while(true){\n // Request a video frame and set into the VideoPanel\n image = videoAdapter.getFrame();\n videoPanel.setImage(image);\n }\n }\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5812/" ]
115,836
<p>A friend of mine brought up this questiont he other day, he's recently bought a garmin heart rate moniter device which keeps track of his heart rate and allows him to upload his heart rate stats for a day to his computer.</p> <p>The only problem is there are no linux drivers for the garmin USB device, he's managed to interpret some of the data, such as the model number and his user details and has identified that there are some binary datatables essentially which we assume represent a series of recordings of his heart rate and the time the recording was taken.</p> <p>Where does one start when reverse engineering data when you know nothing about the structure? </p>
[ { "answer_id": 115920, "author": "freespace", "author_id": 8297, "author_profile": "https://Stackoverflow.com/users/8297", "pm_score": 0, "selected": false, "text": "strings" }, { "answer_id": 2389469, "author": "TMN", "author_id": 69471, "author_profile": "https://Stackoverflow.com/users/69471", "pm_score": 0, "selected": false, "text": "ctime()" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20400/" ]
115,844
<p>From <a href="http://pypi.python.org/pypi/PyPubSub/" rel="noreferrer">PyPubSub</a>:</p> <blockquote> <p>Pypubsub provides a simple way for your Python application to decouple its components: parts of your application can publish messages (with or without data) and other parts can subscribe/receive them. This allows message "senders" and message "listeners" to be unaware of each other:</p> <ul> <li>one doesn't need to import the other</li> <li>a sender doesn't need to know <ul> <li>"who" gets the messages, </li> <li>what the listeners will do with the data, </li> <li>or even if any listener will get the message data.</li> </ul></li> <li>similarly, listeners don't need to worry about where messages come from.</li> </ul> <p>This is a great tool for implementing a Model-View-Controller architecture or any similar architecture that promotes decoupling of its components.</p> </blockquote> <p>There seem to be quite a few Python modules for publishing/subscribing floating around the web, from PyPubSub, to <a href="http://pydispatcher.sourceforge.net/" rel="noreferrer">PyDispatcher</a> to simple "home-cooked" classes.</p> <p>Are there specific advantages and disadvantages when comparing different different modules? Which sets of modules have been benchmarked and compared?</p> <p>Thanks in advance</p>
[ { "answer_id": 16918220, "author": "Jabba", "author_id": 232485, "author_profile": "https://Stackoverflow.com/users/232485", "pm_score": 2, "selected": false, "text": "from time import sleep\nimport smokesignal\n\n@smokesignal.on('debug')\ndef verbose(val):\n print \"#\", val\n\n\ndef main():\n for i in range(100):\n if i and i%10==0:\n smokesignal.emit('debug', i)\n sleep(.1)\n\nmain()\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115844", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8206/" ]
115,850
<p>I'd like to implement a way to display a list of stored addresses sorted by proximity to a given address.</p> <p>Addresses in the list will be stored in a database table. Separate parts have separate fields (we have fields for postal code, city name, etc.) so it is not just a giant <code>varchar</code>. These are user-entered and due to the nature of the system may not always be complete (some may be missing postal code and others may have little more than city and state).</p> <p>Though this is for an intranet application I have no problems using outside resources including accessing internet web services and such. I'd actually prefer that over rolling my own unless it would be trivial to do myself. If Google or Yahoo! already provides a free service, I'm more than willing to check it out. The keyword is it must be free, as I'm not at liberty to introduce any additional cost onto this project for this feature as it is already a bonus "perk" so to speak.</p> <p>I'm thinking of this much like many brick &amp; mortar shops do their "Find a Location" feature. Showing it in a simple table sorted appropriately and displaying distance (in, say, miles) is great. Showing a map mash-up is even cooler, but I can definitely live with just getting the distance back and me handling all of the subsequent display and sorting.</p> <p>The problem with simple distance algorithms is the nature of the data. Since all or part of the address can be undefined, I don't have anything convenient like lat/long coords. Also, even if I make postal codes required, 90% of the addresses will probably have the same five postal codes.</p> <p>While it need not be blisteringly fast, anything that takes more than seven seconds to show up on the page due to latency might be too long for the average user to wait, as we know. If such a hypothetical service supports sending a batch of addresses at once instead of querying one at a time, that'd be great. Still, I should not think the list of addresses would exceed 50 total, if that many.</p>
[ { "answer_id": 115957, "author": "Rahul", "author_id": 16308, "author_profile": "https://Stackoverflow.com/users/16308", "pm_score": 2, "selected": false, "text": "public static double distance(double lat1, double lon1, double lat2, double lon2, char unit)\n{\n double theta = lon1 - lon2;\n double dist = Math.Sin(deg2rad(lat1)) * Math.Sin(deg2rad(lat2)) +\n Math.Cos(deg2rad(lat1)) * Math.Cos(deg2rad(lat2)) * Math.Cos(deg2rad(theta));\n dist = Math.Acos(dist);\n dist = rad2deg(dist);\n dist = dist * 60 * 1.1515;\n if (unit == 'K')\n {\n dist = dist * 1.609344;\n }\n else if (unit == 'N')\n {\n dist = dist * 0.8684;\n }\n return (dist);\n}\n\nprivate static double deg2rad(double deg)\n{\n return (deg * Math.PI / 180.0);\n}\n\nprivate static double rad2deg(double rad)\n{\n return (rad / Math.PI * 180.0);\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7290/" ]
115,862
<p>I'm not sure about what's the difference between opening a JS script with </p> <pre><code>&lt;SCRIPT language='JavaScript'&gt; </code></pre> <p>or with:</p> <pre><code>&lt;SCRIPT type="text/JavaScript"&gt; </code></pre> <p>Should JavaScript always be quoted (either with " " or with ' ') or that's not really important?</p> <p>Thank you for any clarification on this topic!</p>
[ { "answer_id": 115871, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": -1, "selected": false, "text": "<script language=\"javascript\" type=\"text/javascript\">\n" }, { "answer_id": 115911, "author": "Quentin", "author_id": 19068, "author_profile": "https://Stackoverflow.com/users/19068", "pm_score": 4, "selected": false, "text": "<style>" }, { "answer_id": 115917, "author": "Rich Bradshaw", "author_id": 16511, "author_profile": "https://Stackoverflow.com/users/16511", "pm_score": 1, "selected": false, "text": "<script language=\"javascript\" type=\"text/javascript\">\n <style type=\"text/css\">\n" }, { "answer_id": 120608, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 1, "selected": false, "text": "<script src=\"script.js\" />\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19159/" ]
115,866
<p>Convert mysql timestamp to epoch time in python - is there an easy way to do this?</p>
[ { "answer_id": 115903, "author": "David Singer", "author_id": 4618, "author_profile": "https://Stackoverflow.com/users/4618", "pm_score": 5, "selected": false, "text": "select unix_timestamp(fieldname) from tablename;\n" }, { "answer_id": 118236, "author": "Tony Meyer", "author_id": 4966, "author_profile": "https://Stackoverflow.com/users/4966", "pm_score": 3, "selected": false, "text": "import time\n# Connecting to database skipped (also closing connection later)\nc.execute(\"SELECT my_datetime_field FROM my_table\")\nd = c.fetchone()[0]\nprint time.mktime(d.timetuple())\n" }, { "answer_id": 126034, "author": "Tom", "author_id": 3715, "author_profile": "https://Stackoverflow.com/users/3715", "pm_score": 1, "selected": false, "text": "calendar.timegm(\n time.gmtime(\n time.mktime(\n time.strptime(t, \n \"%Y-%m-%d %H:%M:%S\"))))\n" }, { "answer_id": 2407400, "author": "bigredbob", "author_id": 252091, "author_profile": "https://Stackoverflow.com/users/252091", "pm_score": 3, "selected": false, "text": ">>> import time\n>>> import calendar\n>>> mysql_time = \"2010-01-02 03:04:05\"\n>>> mysql_time_struct = time.strptime(mysql_time, '%Y-%m-%d %H:%M:%S')\n>>> print mysql_time_struct\n(2010, 1, 2, 3, 4, 5, 5, 2, -1)\n>>> mysql_time_epoch = calendar.timegm(mysql_time_struct)\n>>> print mysql_time_epoch\n1262401445\n >>> import time\n>>> time_epoch = time.time()\n>>> print time_epoch\n1268121070.7\n>>> time_struct = time.gmtime(time_epoch)\n>>> print time_struct\n(2010, 3, 9, 7, 51, 10, 1, 68, 0)\n>>> time_formatted = time.strftime('%Y-%m-%d %H:%M:%S', time_struct)\n>>> print time_formatted\n2010-03-09 07:51:10\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
115,868
<p>I'd like to know how to grab the Window title of the current active window (i.e. the one that has focus) using C#. </p>
[ { "answer_id": 115891, "author": "ine", "author_id": 4965, "author_profile": "https://Stackoverflow.com/users/4965", "pm_score": 2, "selected": false, "text": "GetForegroundWindow() GetForegroundWindow() hWnd" }, { "answer_id": 115905, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 9, "selected": true, "text": "[DllImport(\"user32.dll\")]\nstatic extern IntPtr GetForegroundWindow();\n\n[DllImport(\"user32.dll\")]\nstatic extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);\n\nprivate string GetActiveWindowTitle()\n{\n const int nChars = 256;\n StringBuilder Buff = new StringBuilder(nChars);\n IntPtr handle = GetForegroundWindow();\n\n if (GetWindowText(handle, Buff, nChars) > 0)\n {\n return Buff.ToString();\n }\n return null;\n}\n" }, { "answer_id": 1342675, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "Application.Current.Windows[] IsActive == true" }, { "answer_id": 2652249, "author": "Skvettn", "author_id": 170655, "author_profile": "https://Stackoverflow.com/users/170655", "pm_score": 4, "selected": false, "text": " Application.Current.Windows.OfType<Window>().SingleOrDefault(w => w.IsActive);\n" }, { "answer_id": 32558071, "author": "Beshoy Nabeih", "author_id": 5282703, "author_profile": "https://Stackoverflow.com/users/5282703", "pm_score": -1, "selected": false, "text": "using System.Diagnostics;\n private void button1_Click(object sender, EventArgs e)\n { \n Process currentp = Process.GetCurrentProcess();\n TextBox1.Text = currentp.MainWindowTitle; //this textbox will be filled with active window.\n }\n" }, { "answer_id": 40220805, "author": "Arthur Zennig", "author_id": 1326106, "author_profile": "https://Stackoverflow.com/users/1326106", "pm_score": 0, "selected": false, "text": "Form activForm;\nactivForm = Form.ActiveForm.ActiveMdiChild;\n" }, { "answer_id": 47466273, "author": "Mohammad Dayyan", "author_id": 191647, "author_profile": "https://Stackoverflow.com/users/191647", "pm_score": 3, "selected": false, "text": "[DllImport(\"user32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\nstatic extern IntPtr GetForegroundWindow();\n\n[DllImport(\"user32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\nstatic extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);\n\n[DllImport(\"user32.dll\", CharSet = CharSet.Auto, SetLastError = true)]\nstatic extern int GetWindowTextLength(IntPtr hWnd);\n\nprivate string GetCaptionOfActiveWindow()\n{\n var strTitle = string.Empty;\n var handle = GetForegroundWindow();\n // Obtain the length of the text \n var intLength = GetWindowTextLength(handle) + 1;\n var stringBuilder = new StringBuilder(intLength);\n if (GetWindowText(handle, stringBuilder, intLength) > 0)\n {\n strTitle = stringBuilder.ToString();\n }\n return strTitle;\n}\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1039/" ]
115,873
<p>Our organization has a lot of its essential data in a mainframe Adabas database. We have ODBC access to this data and from C# have queried/updated it successfully using ODBC/Natural "stored procedures".</p> <p>What we'd like to be able to do now is to query a mainframe table from within SQL Server 2005 stored procs, dump the results into a table variable, massage it, and join the result with native SQL data as a result set.</p> <p>The execution of the Natural proc from SQL works fine when we're just selecting it; however, when we insert the result into a table variable SQL seems to be starting a distributed transaction that in turn seems to be wreaking havoc with our connections.</p> <p>Given that we're not performing updates, is it possible to turn off this DTC-escalation behavior? </p> <p>Any tips on getting DTC set up properly to talk to DataDirect's (formerly Neon Systems) Shadow ODBC driver?</p>
[ { "answer_id": 366535, "author": "gbn", "author_id": 27535, "author_profile": "https://Stackoverflow.com/users/27535", "pm_score": 2, "selected": false, "text": "SET REMOTE_PROC_TRANSACTIONS OFF sp_serveroption" }, { "answer_id": 2705986, "author": "Registered User", "author_id": 38332, "author_profile": "https://Stackoverflow.com/users/38332", "pm_score": 2, "selected": false, "text": "USE [master]\nGO\nEXEC master.dbo.sp_serveroption @server=N'REMOTE_SERVER', @optname=N'remote proc transaction promotion', @optvalue=N'false'\nGO\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12260/" ]
115,882
<p>A product that I am working on collects several thousand readings a day and stores them as 64k binary files on a NTFS partition (Windows XP). After a year in production there is over 300000 files in a single directory and the number keeps growing. This has made accessing the parent/ancestor directories from windows explorer very time consuming. </p> <p>I have tried turning off the indexing service but that made no difference. I have also contemplated moving the file content into a database/zip files/tarballs but it is beneficial for us to access the files individually; basically, the files are still needed for research purposes and the researchers are not willing to deal with anything else. </p> <p>Is there a way to optimize NTFS or Windows so that it can work with all these small files? </p>
[ { "answer_id": 115946, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 3, "selected": false, "text": "ABC\\\n DEF\\\n ABCDEFGHI.db\n EFG\\\n ABCEFGHIJ.db\n" }, { "answer_id": 115986, "author": "finalman", "author_id": 20522, "author_profile": "https://Stackoverflow.com/users/20522", "pm_score": 2, "selected": false, "text": "1.xml\n24.xml\n12331.xml\n2304252.xml\n data/1.xml\ndata/24.xml\ndata/1/3/3/12331.xml\ndata/2/5/2/4/0/2304252.xml\n" }, { "answer_id": 21975377, "author": "John Rees", "author_id": 37572, "author_profile": "https://Stackoverflow.com/users/37572", "pm_score": 1, "selected": false, "text": "12.jpg -> 12.jpg\n123.jpg -> 12\\123.jpg\n123456.jpg -> 12\\34\\123456.jpg\n $s = '123456'\n\n-join (( $s -replace '(..)(?!$)', '$1\\' -replace '[^\\\\]*$','' ), $s )\n" } ]
2008/09/22
[ "https://Stackoverflow.com/questions/115882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13054/" ]