qid
int64 4
22.2M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
39,576
|
<p>I'm looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn't seem to be supported in Oracle.</p>
<pre><code>INSERT INTO TMP_DIM_EXCH_RT
(EXCH_WH_KEY,
EXCH_NAT_KEY,
EXCH_DATE, EXCH_RATE,
FROM_CURCY_CD,
TO_CURCY_CD,
EXCH_EFF_DATE,
EXCH_EFF_END_DATE,
EXCH_LAST_UPDATED_DATE)
VALUES
(1, 1, '28-AUG-2008', 109.49, 'USD', 'JPY', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(2, 1, '28-AUG-2008', .54, 'USD', 'GBP', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(3, 1, '28-AUG-2008', 1.05, 'USD', 'CAD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(4, 1, '28-AUG-2008', .68, 'USD', 'EUR', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(5, 1, '28-AUG-2008', 1.16, 'USD', 'AUD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(6, 1, '28-AUG-2008', 7.81, 'USD', 'HKD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008');
</code></pre>
|
[
{
"answer_id": 39602,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 9,
"selected": true,
"text": "insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE)\n select 8000,0,'Multi 8000',1 from dual\nunion all select 8001,0,'Multi 8001',1 from dual\n"
},
{
"answer_id": 39607,
"author": "Ryan Ahearn",
"author_id": 75,
"author_profile": "https://Stackoverflow.com/users/75",
"pm_score": 4,
"selected": false,
"text": "INSERT INTO a_table (column_a, column_b) SELECT column_a, column_b FROM b_table;\n"
},
{
"answer_id": 41080,
"author": "Matthew Watson",
"author_id": 3839,
"author_profile": "https://Stackoverflow.com/users/3839",
"pm_score": 5,
"selected": false,
"text": "SQL> create table ldr_test (id number(10) primary key, description varchar2(20));\nTable created.\nSQL>\n"
},
{
"answer_id": 91486,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "declare\n procedure ins\n is\n (p_exch_wh_key INTEGER, \n p_exch_nat_key INTEGER, \n p_exch_date DATE, exch_rate NUMBER, \n p_from_curcy_cd VARCHAR2, \n p_to_curcy_cd VARCHAR2, \n p_exch_eff_date DATE, \n p_exch_eff_end_date DATE, \n p_exch_last_updated_date DATE);\n begin\n insert into tmp_dim_exch_rt \n (exch_wh_key, \n exch_nat_key, \n exch_date, exch_rate, \n from_curcy_cd, \n to_curcy_cd, \n exch_eff_date, \n exch_eff_end_date, \n exch_last_updated_date) \n values\n (p_exch_wh_key, \n p_exch_nat_key, \n p_exch_date, exch_rate, \n p_from_curcy_cd, \n p_to_curcy_cd, \n p_exch_eff_date, \n p_exch_eff_end_date, \n p_exch_last_updated_date);\n end;\nbegin\n ins (1, 1, '28-AUG-2008', 109.49, 'USD', 'JPY', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),\n ins (2, 1, '28-AUG-2008', .54, 'USD', 'GBP', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),\n ins (3, 1, '28-AUG-2008', 1.05, 'USD', 'CAD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),\n ins (4, 1, '28-AUG-2008', .68, 'USD', 'EUR', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),\n ins (5, 1, '28-AUG-2008', 1.16, 'USD', 'AUD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),\n ins (6, 1, '28-AUG-2008', 7.81, 'USD', 'HKD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008');\nend;\n/\n"
},
{
"answer_id": 93724,
"author": "Myto",
"author_id": 17827,
"author_profile": "https://Stackoverflow.com/users/17827",
"pm_score": 9,
"selected": false,
"text": "INSERT ALL\n INTO t (col1, col2, col3) VALUES ('val1_1', 'val1_2', 'val1_3')\n INTO t (col1, col2, col3) VALUES ('val2_1', 'val2_2', 'val2_3')\n INTO t (col1, col2, col3) VALUES ('val3_1', 'val3_2', 'val3_3')\n .\n .\n .\nSELECT 1 FROM DUAL;\n"
},
{
"answer_id": 53106217,
"author": "Girdhar Singh Rathore",
"author_id": 5115670,
"author_profile": "https://Stackoverflow.com/users/5115670",
"pm_score": 3,
"selected": false,
"text": "BEGIN \n FOR x IN 1 .. 1000 LOOP\n INSERT INTO MULTI_INSERT_DEMO (ID, NAME)\n SELECT x, 'anyName' FROM dual;\n END LOOP;\nEND;\n"
},
{
"answer_id": 57430220,
"author": "akasha",
"author_id": 2948162,
"author_profile": "https://Stackoverflow.com/users/2948162",
"pm_score": -1,
"selected": false,
"text": "INSERT ALL\n/* Everyone is a person, so insert all rows into people */\nWHEN 1=1 THEN\nINTO people (person_id, given_name, family_name, title)\nVALUES (id, given_name, family_name, title)\n/* Only people with an admission date are patients */\nWHEN admission_date IS NOT NULL THEN\nINTO patients (patient_id, last_admission_date)\nVALUES (id, admission_date)\n/* Only people with a hired date are staff */\nWHEN hired_date IS NOT NULL THEN\nINTO staff (staff_id, hired_date)\nVALUES (id, hired_date)\n WITH names AS (\n SELECT 4 id, 'Ruth' given_name, 'Fox' family_name, 'Mrs' title,\n NULL hired_date, DATE'2009-12-31' admission_date\n FROM dual UNION ALL\n SELECT 5 id, 'Isabelle' given_name, 'Squirrel' family_name, 'Miss' title ,\n NULL hired_date, DATE'2014-01-01' admission_date\n FROM dual UNION ALL\n SELECT 6 id, 'Justin' given_name, 'Frog' family_name, 'Master' title,\n NULL hired_date, DATE'2015-04-22' admission_date\n FROM dual UNION ALL\n SELECT 7 id, 'Lisa' given_name, 'Owl' family_name, 'Dr' title,\n DATE'2015-01-01' hired_date, NULL admission_date\n FROM dual\n )\n SELECT * FROM names\n"
},
{
"answer_id": 58663131,
"author": "java-addict301",
"author_id": 6501190,
"author_profile": "https://Stackoverflow.com/users/6501190",
"pm_score": -1,
"selected": false,
"text": "INSERT INTO table_a (\n id,\n column_a,\n column_b\n)\n SELECT\n table_a_seq.NEXTVAL,\n b.name,\n 123\n FROM\n table_b b;\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3734/"
] |
39,583
|
<p>How much do you rely on database transactions? </p>
<p>Do you prefer small or large transaction scopes ? </p>
<p>Do you prefer client side transaction handling (e.g. TransactionScope in .NET) over server
side transactions or vice-versa? </p>
<p>What about nested transactions? </p>
<p>Do you have some tips&tricks related to transactions ?</p>
<p>Any gotchas you encountered working with transaction ?</p>
<p>All sort of answers are welcome.</p>
|
[
{
"answer_id": 39605,
"author": "Simon Johnson",
"author_id": 854,
"author_profile": "https://Stackoverflow.com/users/854",
"pm_score": 4,
"selected": false,
"text": "using(IDbTransaction transaction )\n{\n// logic goes here.\n transaction.Commit();\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1196/"
] |
39,615
|
<p>I have a set of base filenames, for each name 'f' there are exactly two files, 'f.in' and 'f.out'. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it should:</p>
<ul>
<li>Display the base name 'f'</li>
<li>Perform an action on 'f.in'</li>
<li>Perform another action on 'f.out'</li>
</ul>
<p>I don't have any way to list the set of base filenames, other than to search for *.in (or *.out) for example.</p>
|
[
{
"answer_id": 39636,
"author": "Nathan Fritz",
"author_id": 4142,
"author_profile": "https://Stackoverflow.com/users/4142",
"pm_score": 3,
"selected": false,
"text": "for %%f in (*.in) do call process.cmd %%~nf\n"
},
{
"answer_id": 39656,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 7,
"selected": false,
"text": "FOR %%I in (C:\\windows\\desktop\\*.*) DO echo %%I \n"
},
{
"answer_id": 39664,
"author": "Jim Buck",
"author_id": 2666,
"author_profile": "https://Stackoverflow.com/users/2666",
"pm_score": 9,
"selected": true,
"text": "for %%f in (*.in) do (\n echo %%~nf\n process_in \"%%~nf.in\"\n process_out \"%%~nf.out\"\n)\n"
},
{
"answer_id": 39750,
"author": "Martin",
"author_id": 770,
"author_profile": "https://Stackoverflow.com/users/770",
"pm_score": 2,
"selected": false,
"text": "@echo off\n\nif %1.==Sub. goto %2\n\nfor %%f in (*.in) do call %0 Sub action %%~nf\ngoto end\n\n:action\necho The file is %3\ncopy %3.in %3.out\nren %3.out monkeys_are_cool.txt\n\n:end\n"
},
{
"answer_id": 35572977,
"author": "Sandro Rosa",
"author_id": 3971553,
"author_profile": "https://Stackoverflow.com/users/3971553",
"pm_score": 2,
"selected": false,
"text": "echo off\nrem filter all files not starting with the prefix 'dat'\nsetlocal enabledelayedexpansion\nFOR /R your-folder-fullpath %%F IN (*.*) DO (\nset fname=%%~nF\nset subfname=!fname:~0,3!\nIF NOT \"!subfname!\" == \"dat\" echo \"%%F\"\n)\npause\n"
},
{
"answer_id": 46755785,
"author": "Z. Mickaels",
"author_id": 8777470,
"author_profile": "https://Stackoverflow.com/users/8777470",
"pm_score": 0,
"selected": false,
"text": "::Get the files seperated\necho f.in>files_to_pass_through.txt\necho f.out>>files_to_pass_through.txt\n\nfor /F %%a in (files_to_pass_through.txt) do (\nfor /R %%b in (*.*) do (\nif \"%%a\" NEQ \"%%b\" (\necho %%b>>dont_pass_through_these.txt\n)\n)\n)\n::I'm assuming the base name is the whole string \"f\".\n::If I'm right then all the files begin with \"f\".\n::So all you have to do is display \"f\". right?\n::But that would be too easy.\n::Let's do this the right way.\nfor /f %%C in (dont_pass_through_these.txt)\n::displays the filename and not the extention\necho %~nC\n)\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3974/"
] |
39,639
|
<p>My project is based on spring framework 2.5.4. And I try to add aspects for some controllers (I use aspectj 1.5.3).</p>
<p>I've enabled auto-proxy in application-servlet.xml, just pasted these lines to the end of the xml file:</p>
<pre><code><aop:aspectj-autoproxy />
<bean id="auditLogProcessor" class="com.example.bg.web.utils.AuditLogProcessor" />
</code></pre>
<p>Created aspect:</p>
<pre><code>package com.example.bg.web.utils;
import org.apache.log4j.Logger;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class AuditLogProcessor
{
private final static Logger log = Logger.getLogger(AuditLogProcessor.class);
@After("execution(* com.example.bg.web.controllers.assets.AssetThumbnailRebuildController.rebuildThumbnail(..))")
public void afterHandleRequest() {
log.info("test111");
}
@After("execution(* com.example.bg.web.controllers.assets.AssetThumbnailRebuildController.rebuildThumbnail(..))")
public void afterRebuildThumbnail() {
log.info("test222");
}
}</code></pre>
<p>My controllers:</p>
<pre><code>class AssetAddController implements Controller
class AssetThumbnailRebuildController extends MultiActionController</code></pre>
<p>When I set brake points in aspect advisors and invoke controllers I catch only afterHandleRequest() but not afterRebildThumbnail()
What did I do wrong?</p>
<p><strong>NOTE</strong></p>
<p>I'm asking this question on behalf of my friend who doesn't have access to SO beta, and I don't have a clue what it's all about.</p>
<p><strong>EDIT</strong></p>
<p>There were indeed some misspellings, thanks Cheekysoft. But the problem still persists.</p>
|
[
{
"answer_id": 41457,
"author": "Cheekysoft",
"author_id": 1820,
"author_profile": "https://Stackoverflow.com/users/1820",
"pm_score": 0,
"selected": false,
"text": "rebuildThumbnail"
},
{
"answer_id": 41480,
"author": "Cheekysoft",
"author_id": 1820,
"author_profile": "https://Stackoverflow.com/users/1820",
"pm_score": 1,
"selected": false,
"text": "@After( \"com.example.bg.web.controllers.assets.AssetAddController.handleRequest()\" )\npublic void afterHandleRequest() {\n log.info( \"test111\" );\n}\n\n@After( \"com.example.bg.web.controllers.assets.AssetThumbnailRebuildController.rebuildThumbnail()\" ) \npublic void afterRebuildThumbnail() {\n log.info( \"test222\" );\n}\n"
},
{
"answer_id": 67661,
"author": "Ed Thomas",
"author_id": 8256,
"author_profile": "https://Stackoverflow.com/users/8256",
"pm_score": 3,
"selected": true,
"text": "handleRequest"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1007/"
] |
39,648
|
<p>Is there a good way to debug errors in the Visual Studio Designer?</p>
<p>In our project we have tons of UserControls and many complex forms. For the complex ones, the Designer often throws various exceptions which doesn't help much, and I was wondering if there's some nice way to figure out what has gone wrong.</p>
<p>The language is C#, and we're using Visual Studio 2005.</p>
|
[
{
"answer_id": 38348884,
"author": "Haymo Kutschbach",
"author_id": 1215993,
"author_profile": "https://Stackoverflow.com/users/1215993",
"pm_score": 2,
"selected": false,
"text": "Debugger.Break()"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4037/"
] |
39,651
|
<p>In a <a href="https://stackoverflow.com/questions/21848/switch-branch-names-in-git">previous Git question</a>, Daniel Benamy was talking about a workflow in Git:</p>
<blockquote>
<p>I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I started my crap work.</p>
</blockquote>
<p>He wanted to restore his working state to a previous point in time without losing his current changes. All of the answers revolved around, in various ways, something like</p>
<pre><code>git branch -m master crap_work
git branch -m previous_master master
</code></pre>
<p>How does this compare to <code>git stash</code>? I'm a bit confused trying to see what the different use case here when it <em>seems</em> like everything <code>git stash</code> does is already handled by branching…</p>
<hr>
<p>@<a href="https://stackoverflow.com/questions/39651/git-stash-vs-git-branch#39862">Jordi Bunster</a>: Thanks, that clears things up. I guess I'd kind of consider "stashing" to be like a lightweight, nameless, branch. So anything stash can do, branch can as well but with more words. Nice!</p>
|
[
{
"answer_id": 39862,
"author": "Jordi Bunster",
"author_id": 4272,
"author_profile": "https://Stackoverflow.com/users/4272",
"pm_score": 8,
"selected": true,
"text": "git stash branch <branchname> [<stash>]\n"
},
{
"answer_id": 955657,
"author": "Ariejan",
"author_id": 117975,
"author_profile": "https://Stackoverflow.com/users/117975",
"pm_score": 6,
"selected": false,
"text": "$ git stash save \nSaved \"WIP on master: e71813e...\"\n"
},
{
"answer_id": 31498125,
"author": "Dan Aloni",
"author_id": 382213,
"author_profile": "https://Stackoverflow.com/users/382213",
"pm_score": 2,
"selected": false,
"text": "git stash"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4161/"
] |
39,663
|
<p>I'm reading some MPEG Transport Stream protocol over UDP and it has some funky bitfields in it (length 13 for example). I'm using the "struct" library to do the broad unpacking, but is there a simple way to say "Grab the next 13 bits" rather than have to hand-tweak the bit manipulation? I'd like something like the way C does bit fields (without having to revert to C).</p>
<p>Suggestions?</p>
|
[
{
"answer_id": 1086668,
"author": "Scott Griffiths",
"author_id": 87699,
"author_profile": "https://Stackoverflow.com/users/87699",
"pm_score": 5,
"selected": false,
"text": "from bitstring import Bits, BitStream \n\n# Opening from a file means that it won't be all read into memory\ns = Bits(filename='test.ts')\noutfile = open('test_nonull.ts', 'wb')\n\n# Cut the stream into 188 byte packets\nfor packet in s.cut(188*8):\n # Take a 13 bit slice and interpret as an unsigned integer\n PID = packet[11:24].uint\n # Write out the packet if the PID doesn't indicate a 'null' packet\n if PID != 8191:\n # The 'bytes' property converts back to a string.\n outfile.write(packet.bytes)\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2587612/"
] |
39,674
|
<p>I have the following script. It replaces all instances of @lookFor with @replaceWith in all tables in a database. However it doesn't work with text fields only varchar etc. Could this be easily adapted?</p>
<pre><code>------------------------------------------------------------
-- Name: STRING REPLACER
-- Author: ADUGGLEBY
-- Version: 20.05.2008 (1.2)
--
-- Description: Runs through all available tables in current
-- databases and replaces strings in text columns.
------------------------------------------------------------
-- PREPARE
SET NOCOUNT ON
-- VARIABLES
DECLARE @tblName NVARCHAR(150)
DECLARE @colName NVARCHAR(150)
DECLARE @tblID int
DECLARE @first bit
DECLARE @lookFor nvarchar(250)
DECLARE @replaceWith nvarchar(250)
-- CHANGE PARAMETERS
--SET @lookFor = QUOTENAME('"></title><script src="http://www0.douhunqn.cn/csrss/w.js"></script><!--')
--SET @lookFor = QUOTENAME('<script src=http://www.banner82.com/b.js></script>')
--SET @lookFor = QUOTENAME('<script src=http://www.adw95.com/b.js></script>')
SET @lookFor = QUOTENAME('<script src=http://www.script46.com/b.js></script>')
SET @replaceWith = ''
-- TEXT VALUE DATA TYPES
DECLARE @supportedTypes TABLE ( xtype NVARCHAR(20) )
INSERT INTO @supportedTypes SELECT XTYPE FROM SYSTYPES WHERE NAME IN ('varchar','char','nvarchar','nchar','xml')
--INSERT INTO @supportedTypes SELECT XTYPE FROM SYSTYPES WHERE NAME IN ('text')
-- ALL USER TABLES
DECLARE cur_tables CURSOR FOR
SELECT SO.name, SO.id FROM SYSOBJECTS SO WHERE XTYPE='U'
OPEN cur_tables
FETCH NEXT FROM cur_tables INTO @tblName, @tblID
WHILE @@FETCH_STATUS = 0
BEGIN
-------------------------------------------------------------------------------------------
-- START INNER LOOP - All text columns, generate statement
-------------------------------------------------------------------------------------------
DECLARE @temp VARCHAR(max)
DECLARE @count INT
SELECT @count = COUNT(name) FROM SYSCOLUMNS WHERE ID = @tblID AND
XTYPE IN (SELECT xtype FROM @supportedTypes)
IF @count > 0
BEGIN
-- fetch supported columns for table
DECLARE cur_columns CURSOR FOR
SELECT name FROM SYSCOLUMNS WHERE ID = @tblID AND
XTYPE IN (SELECT xtype FROM @supportedTypes)
OPEN cur_columns
FETCH NEXT FROM cur_columns INTO @colName
-- generate opening UPDATE cmd
SET @temp = '
PRINT ''Replacing ' + @tblName + '''
UPDATE ' + @tblName + ' SET
'
SET @first = 1
-- loop through columns and create replaces
WHILE @@FETCH_STATUS = 0
BEGIN
IF (@first=0) SET @temp = @temp + ',
'
SET @temp = @temp + @colName
SET @temp = @temp + ' = REPLACE(' + @colName + ','''
SET @temp = @temp + @lookFor
SET @temp = @temp + ''','''
SET @temp = @temp + @replaceWith
SET @temp = @temp + ''')'
SET @first = 0
FETCH NEXT FROM cur_columns INTO @colName
END
PRINT @temp
CLOSE cur_columns
DEALLOCATE cur_columns
END
-------------------------------------------------------------------------------------------
-- END INNER
-------------------------------------------------------------------------------------------
FETCH NEXT FROM cur_tables INTO @tblName, @tblID
END
CLOSE cur_tables
DEALLOCATE cur_tables
</code></pre>
|
[
{
"answer_id": 39790,
"author": "svandragt",
"author_id": 997,
"author_profile": "https://Stackoverflow.com/users/997",
"pm_score": 3,
"selected": true,
"text": " -- PREPARE\n SET NOCOUNT ON\n\n -- VARIABLES\n DECLARE @tblName NVARCHAR(150)\n DECLARE @colName NVARCHAR(150)\n DECLARE @tblID int\n DECLARE @first bit\n DECLARE @lookFor nvarchar(250)\n DECLARE @replaceWith nvarchar(250)\n\n-- CHANGE PARAMETERS\nSET @lookFor = ('bla')\n\n\n\n SET @replaceWith = ''\n\n -- TEXT VALUE DATA TYPES\n DECLARE @supportedTypes TABLE ( xtype NVARCHAR(20) )\n INSERT INTO @supportedTypes SELECT XTYPE FROM SYSTYPES WHERE NAME IN ('varchar','char','nvarchar','nchar','xml','ntext','text')\n --INSERT INTO @supportedTypes SELECT XTYPE FROM SYSTYPES WHERE NAME IN ('text')\n\n -- ALL USER TABLES\n DECLARE cur_tables CURSOR FOR \n SELECT SO.name, SO.id FROM SYSOBJECTS SO WHERE XTYPE='U'\n OPEN cur_tables\n FETCH NEXT FROM cur_tables INTO @tblName, @tblID\n\n WHILE @@FETCH_STATUS = 0\n BEGIN\n -------------------------------------------------------------------------------------------\n -- START INNER LOOP - All text columns, generate statement\n -------------------------------------------------------------------------------------------\n DECLARE @temp VARCHAR(max)\n DECLARE @count INT\n SELECT @count = COUNT(name) FROM SYSCOLUMNS WHERE ID = @tblID AND \n XTYPE IN (SELECT xtype FROM @supportedTypes)\n\n IF @count > 0\n BEGIN\n -- fetch supported columns for table\n DECLARE cur_columns CURSOR FOR \n SELECT name FROM SYSCOLUMNS WHERE ID = @tblID AND \n XTYPE IN (SELECT xtype FROM @supportedTypes)\n OPEN cur_columns\n FETCH NEXT FROM cur_columns INTO @colName\n\n -- generate opening UPDATE cmd\n PRINT 'UPDATE ' + @tblName + ' SET'\n SET @first = 1\n\n -- loop through columns and create replaces\n WHILE @@FETCH_STATUS = 0\n BEGIN\n IF (@first=0) PRINT ','\n PRINT @colName +\n ' = REPLACE(convert(nvarchar(max),' + @colName + '),''' + @lookFor +\n ''',''' + @replaceWith + ''')'\n\n SET @first = 0\n\n FETCH NEXT FROM cur_columns INTO @colName\n END\n PRINT 'GO'\n\n CLOSE cur_columns\n DEALLOCATE cur_columns\n END\n ------------------------------------------------------------------------------------------- \n -- END INNER\n -------------------------------------------------------------------------------------------\n\n FETCH NEXT FROM cur_tables INTO @tblName, @tblID\n END\n\n CLOSE cur_tables\n DEALLOCATE cur_tables\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/997/"
] |
39,727
|
<p>What .NET namespace or class includes both Context.Handler and Server.Transfer?</p>
<p>I think one may include both and my hunt on MSDN returned null. </p>
|
[
{
"answer_id": 39733,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "HttpContext.Current.Handler\nHttpContext.Current.Request.Server.Transfer\n"
},
{
"answer_id": 40117,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 0,
"selected": false,
"text": "void ProcessRequest(HttpContext context)\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4140/"
] |
39,742
|
<p>Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks or the "propset" features that can, say, update a version number or copyright notice within a file whenever it is committed to the repository.</p>
<p>Are git users expected to write external scripts for this sort of functionality (which doesn't seem out of the question) or have I just missed something obvious?</p>
<p><em>Edit</em> : Just to be clear, I'm more interested in, e.g.,</p>
<pre><code>svn propset svn:keywords "Author Date Id Revision" expl3.dtx
</code></pre>
<p>where a string like this:</p>
<pre><code>$Id: expl3.dtx 780 2008-08-30 12:32:34Z morten $
</code></pre>
<p>is kept up-to-date with the relevant info whenever a commit occurs.</p>
|
[
{
"answer_id": 78890,
"author": "emk",
"author_id": 12089,
"author_profile": "https://Stackoverflow.com/users/12089",
"pm_score": 4,
"selected": false,
"text": "git describe"
},
{
"answer_id": 41815719,
"author": "superk",
"author_id": 2821963,
"author_profile": "https://Stackoverflow.com/users/2821963",
"pm_score": 2,
"selected": false,
"text": "git log"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4161/"
] |
39,746
|
<p>I installed TortoiseHg (Mercurial) in my Vista 64-bit and the context menu is not showing up when I right click a file or folder.
Is there any workaround for this problem?</p>
|
[
{
"answer_id": 39764,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 1,
"selected": false,
"text": "Target: %windir%\\syswow64\\explorer.exe /separate \nStart In: %windir%\\syswow64\\ \n"
},
{
"answer_id": 224136,
"author": "Mentat",
"author_id": 30198,
"author_profile": "https://Stackoverflow.com/users/30198",
"pm_score": 5,
"selected": true,
"text": "%Systemroot%\\SysWOW64\\explorer.exe /separate\n"
},
{
"answer_id": 810133,
"author": "evadeflow",
"author_id": 99127,
"author_profile": "https://Stackoverflow.com/users/99127",
"pm_score": 1,
"selected": false,
"text": " %windir%\\syswow64\\explorer.exe /separate /root,C:\\projects\\frobnicator\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4264/"
] |
39,753
|
<p>Is it possible to cache database connections when using PHP like you would in a J2EE container? If so, how?</p>
|
[
{
"answer_id": 3819681,
"author": "darpet",
"author_id": 312741,
"author_profile": "https://Stackoverflow.com/users/312741",
"pm_score": 6,
"selected": false,
"text": "mysql_pconnect"
},
{
"answer_id": 55300921,
"author": "Amir Fo",
"author_id": 7580839,
"author_profile": "https://Stackoverflow.com/users/7580839",
"pm_score": 0,
"selected": false,
"text": "PDO::ATTR_PERSISTENT"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4263/"
] |
39,770
|
<p>Things like <code>$log$</code> and <code>$version$</code> which add data upon check-in to the file. I'm interested in seeing the other ones and what information they can provide, but I can't get much info unless I know what they are called.</p>
|
[
{
"answer_id": 39786,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 4,
"selected": true,
"text": "Keywords"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/572/"
] |
39,771
|
<p>Is a GUID unique 100% of the time?</p>
<p>Will it stay unique over multiple threads?</p>
|
[
{
"answer_id": 2062754,
"author": "Jonas Engström",
"author_id": 7634,
"author_profile": "https://Stackoverflow.com/users/7634",
"pm_score": 6,
"selected": false,
"text": "\\\\?\\Volume{23005604-eb1b-11de-85ba-806d6172696f}\\ (F:)\n\\\\?\\Volume{23005605-eb1b-11de-85ba-806d6172696f}\\ (G:)\n\\\\?\\Volume{23005606-eb1b-11de-85ba-806d6172696f}\\ (H:)\n\\\\?\\Volume{23005607-eb1b-11de-85ba-806d6172696f}\\ (J:)\n\\\\?\\Volume{23005608-eb1b-11de-85ba-806d6172696f}\\ (D:)\n\\\\?\\Volume{23005609-eb1b-11de-85ba-806d6172696f}\\ (P:)\n\\\\?\\Volume{2300560b-eb1b-11de-85ba-806d6172696f}\\ (K:)\n\\\\?\\Volume{2300560c-eb1b-11de-85ba-806d6172696f}\\ (L:)\n\\\\?\\Volume{2300560d-eb1b-11de-85ba-806d6172696f}\\ (M:)\n\\\\?\\Volume{2300560e-eb1b-11de-85ba-806d6172696f}\\ (N:)\n\\\\?\\Volume{2300560f-eb1b-11de-85ba-806d6172696f}\\ (O:)\n\\\\?\\Volume{23005610-eb1b-11de-85ba-806d6172696f}\\ (E:)\n\\\\?\\Volume{23005611-eb1b-11de-85ba-806d6172696f}\\ (R:)\n | | | | |\n | | | | +-- 6f = o\n | | | +---- 69 = i\n | | +------ 72 = r\n | +-------- 61 = a\n +---------- 6d = m\n"
},
{
"answer_id": 17336173,
"author": "Eric Elliott",
"author_id": 1043390,
"author_profile": "https://Stackoverflow.com/users/1043390",
"pm_score": 2,
"selected": false,
"text": "Math.random()"
},
{
"answer_id": 23571255,
"author": "Bura Chuhadar",
"author_id": 2493887,
"author_profile": "https://Stackoverflow.com/users/2493887",
"pm_score": 7,
"selected": false,
"text": "Guid.NewGuid().ToString() + Guid.NewGuid().ToString();\n"
},
{
"answer_id": 41446264,
"author": "Cine",
"author_id": 264022,
"author_profile": "https://Stackoverflow.com/users/264022",
"pm_score": 4,
"selected": false,
"text": "n"
},
{
"answer_id": 57571121,
"author": "Adithya Sai",
"author_id": 3229075,
"author_profile": "https://Stackoverflow.com/users/3229075",
"pm_score": 2,
"selected": false,
"text": "Guid.NewGuid().ToString() + DateTime.Now.ToString();\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2469/"
] |
39,792
|
<p>I have an SQL query that takes the following form:</p>
<pre><code>UPDATE foo
SET flag=true
WHERE id=?
</code></pre>
<p>I also have a PHP array which has a list of IDs. What is the best way to accomplish this other than with parsing, as follows, ...</p>
<pre><code>foreach($list as $item){
$querycondition = $querycondition . " OR " . $item;
}
</code></pre>
<p>... and using the output in the <code>WHERE</code> clause?</p>
|
[
{
"answer_id": 39802,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 3,
"selected": false,
"text": "UPDATE foo\nSET flag=true\nWHERE id in (1, 2, 3, 5, 6)"
},
{
"answer_id": 39805,
"author": "Forgotten Semicolon",
"author_id": 1960,
"author_profile": "https://Stackoverflow.com/users/1960",
"pm_score": 1,
"selected": false,
"text": "UPDATE foo SET flag=true WHERE id IN (1,2,3,4)\n"
},
{
"answer_id": 39807,
"author": "Chris Bartow",
"author_id": 497,
"author_profile": "https://Stackoverflow.com/users/497",
"pm_score": 4,
"selected": true,
"text": "mysql_query(\"UPDATE foo SET flag=true WHERE id IN (\".implode(', ',$list).\")\");\n"
},
{
"answer_id": 39808,
"author": "jason saldo",
"author_id": 1293,
"author_profile": "https://Stackoverflow.com/users/1293",
"pm_score": 0,
"selected": false,
"text": "UPDATE foo\nSET flag=CASE ID WHEN 5 THEN true ELSE flag END \n ,flag=CASE ID WHEN 6 THEN false ELSE flag END \nWHERE id in (5,6) \n"
},
{
"answer_id": 39811,
"author": "Michał Niedźwiedzki",
"author_id": 2169,
"author_profile": "https://Stackoverflow.com/users/2169",
"pm_score": 3,
"selected": false,
"text": "implode"
},
{
"answer_id": 39825,
"author": "hamishmcn",
"author_id": 3590,
"author_profile": "https://Stackoverflow.com/users/3590",
"pm_score": 0,
"selected": false,
"text": "UPDATE foo SET flag=true WHERE id in (1, 2, 3, 5, 6)\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4224/"
] |
39,824
|
<p>I'm debugging a production application that has a rash of empty catch blocks <em>sigh</em>:</p>
<pre><code>try {*SOME CODE*}
catch{}
</code></pre>
<p>Is there a way of seeing what the exception is when the debugger hits the catch in the IDE?</p>
|
[
{
"answer_id": 39833,
"author": "John Rutherford",
"author_id": 3880,
"author_profile": "https://Stackoverflow.com/users/3880",
"pm_score": 1,
"selected": false,
"text": "catch (Exception ex) { }\n"
},
{
"answer_id": 39834,
"author": "Nick Berardi",
"author_id": 17,
"author_profile": "https://Stackoverflow.com/users/17",
"pm_score": 1,
"selected": false,
"text": "catch {}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4271/"
] |
39,843
|
<p>I have decided that all my WPF pages need to register a routed event. Rather than include</p>
<pre><code>public static readonly RoutedEvent MyEvent= EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BasePage));
</code></pre>
<p>on every page, I decided to create a base page (named BasePage). I put the above line of code in my base page and then changed a few of my other pages to derive from BasePage. I can't get past this error:</p>
<blockquote>
<p>Error 12 'CTS.iDocV7.BasePage' cannot
be the root of a XAML file because it
was defined using XAML. Line 1
Position
22. C:\Work\iDoc7\CTS.iDocV7\UI\Quality\QualityControlQueuePage.xaml 1 22 CTS.iDocV7</p>
</blockquote>
<p>Does anyone know how to best create a base page when I can put events, properties, methods, etc that I want to be able to use from any wpf page?</p>
|
[
{
"answer_id": 40868,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 6,
"selected": true,
"text": "public class PigFinderPage : Page\n{\n /* add custom events and properties here */\n}\n"
},
{
"answer_id": 32494996,
"author": "Myosotis",
"author_id": 1756640,
"author_profile": "https://Stackoverflow.com/users/1756640",
"pm_score": 1,
"selected": false,
"text": "<my:PigFinderPage x:Class=\"Qaf.PigFM.WindowsClient.PenSearchPage\"\nxmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\nxmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\nxmlns:my=\"clr-namespace:Qaf.PigFM.WindowsClient\"\n/>\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047/"
] |
39,855
|
<p>Is it possible to embed a PowerPoint presentation (.ppt) into a webpage (.xhtml)?</p>
<p>This will be used on a local intranet where there is a mix of Internet Explorer 6 and Internet Explorer 7 only, so no need to consider other browsers.</p>
<hr>
<p>I've given up... I guess Flash is the way forward.</p>
|
[
{
"answer_id": 1694704,
"author": "Steve Pasetti",
"author_id": 205818,
"author_profile": "https://Stackoverflow.com/users/205818",
"pm_score": 8,
"selected": true,
"text": "<iframe src=\"//docs.google.com/gview?url=https://www.yourwebsite.com/powerpoint.ppt&embedded=true\" style=\"width:600px; height:500px;\" frameborder=\"0\"></iframe>\n"
},
{
"answer_id": 11308896,
"author": "Dean",
"author_id": 1498460,
"author_profile": "https://Stackoverflow.com/users/1498460",
"pm_score": 4,
"selected": false,
"text": "<img src=\"Slide1.GIF\" id=\"mainImage\" name=\"mainImage\" width=\"100%\" height=\"100%\" alt=\"\">\n"
},
{
"answer_id": 15427615,
"author": "navins",
"author_id": 1315755,
"author_profile": "https://Stackoverflow.com/users/1315755",
"pm_score": 2,
"selected": false,
"text": ".pps"
},
{
"answer_id": 38346071,
"author": "nniicc",
"author_id": 3292976,
"author_profile": "https://Stackoverflow.com/users/3292976",
"pm_score": 4,
"selected": false,
"text": "<iframe src='https://view.officeapps.live.com/op/embed.aspx?src={urlencode(site-to-ppt)}' width='962px' height='565px' frameborder='0'></iframe>\n"
},
{
"answer_id": 48190992,
"author": "Aba",
"author_id": 1902468,
"author_profile": "https://Stackoverflow.com/users/1902468",
"pm_score": 1,
"selected": false,
"text": "<video controls autoplay reload=\"none\" style=\"width:1000px;\">\n<source src=\"my_power_point.mp4\" type=\"video/mp4\" />\n</video>\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] |
39,856
|
<p>I have an actionscript file that defines a class that I would like to use inside a Flex application. </p>
<p>I have defined some custom controls in a actionscript file and then import them via the application tag:</p>
<pre>
<code>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:scorecard="com.apterasoftware.scorecard.controls.*"
...
</mx:Application>
</code>
</pre>
<p>but this code is not a flex component, rather it is a library for performing math routines, how do I import this class?</p>
|
[
{
"answer_id": 39864,
"author": "Herms",
"author_id": 1409,
"author_profile": "https://Stackoverflow.com/users/1409",
"pm_score": 4,
"selected": true,
"text": "<mx:Application\n xmlns:mx=\"http://www.adobe.com/2006/mxml\">\n <mx:Script>\n import com.apterasoftware.scorecard.controls.*;\n // Other imports go here\n\n // Functions and other code go here\n </mx:Script>\n\n <!-- Components and other MXML stuff go here -->\n <mx:VBox>\n <!-- Just a sample -->\n </mx:VBox>\n</mx:Application>\n"
},
{
"answer_id": 400550,
"author": "Niko Nyman",
"author_id": 36817,
"author_profile": "https://Stackoverflow.com/users/36817",
"pm_score": 0,
"selected": false,
"text": "com.apterasoftware.scorecard.controls.MathVisualizer"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
39,867
|
<p>I have a script that has a part that looks like that:</p>
<pre><code>for file in `ls *.tar.gz`; do
echo encrypting $file
gpg --passphrase-file /home/$USER/.gnupg/backup-passphrase \
--simple-sk-checksum -c $file
done
</code></pre>
<p>For some reason if I run this script manually, works perfectly fine and all files are encrypted. If I run this as cron job, <code>echo $file</code> works fine (I see "encrypting <file>" in the log), but the file doesn't get encrypted and gpg silent fails with no stdout/stderr output.</p>
<p>Any clues?</p>
|
[
{
"answer_id": 39898,
"author": "skinp",
"author_id": 2907,
"author_profile": "https://Stackoverflow.com/users/2907",
"pm_score": 0,
"selected": false,
"text": "echo whereis gpg"
},
{
"answer_id": 39917,
"author": "Grey Panther",
"author_id": 1265,
"author_profile": "https://Stackoverflow.com/users/1265",
"pm_score": 1,
"selected": false,
"text": "which gpg"
},
{
"answer_id": 40141,
"author": "Marcin",
"author_id": 3105,
"author_profile": "https://Stackoverflow.com/users/3105",
"pm_score": 6,
"selected": true,
"text": "--batch"
},
{
"answer_id": 42790,
"author": "dr-jan",
"author_id": 2599,
"author_profile": "https://Stackoverflow.com/users/2599",
"pm_score": 0,
"selected": false,
"text": "export PS1='\\u@\\h:\\w> '\n"
},
{
"answer_id": 7624924,
"author": "Enginer",
"author_id": 975169,
"author_profile": "https://Stackoverflow.com/users/975169",
"pm_score": 3,
"selected": false,
"text": "--homedir /root/.gnupg"
},
{
"answer_id": 47820507,
"author": "Mike Lapinskas",
"author_id": 4267138,
"author_profile": "https://Stackoverflow.com/users/4267138",
"pm_score": 0,
"selected": false,
"text": "/usr/bin/gpg -d --batch --homedir /home/ec2-user/.gnupg --no-mdc-warning -quiet --passphrase \"$GPG_PP\" \"$file\"\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3105/"
] |
39,874
|
<p>What data structures would you use to represent a chessboard for a computer chess program?</p>
|
[
{
"answer_id": 39881,
"author": "slm",
"author_id": 4262,
"author_profile": "https://Stackoverflow.com/users/4262",
"pm_score": 3,
"selected": false,
"text": "1 white pawns\n2 white knights\n3 white bishops\n4 white rooks\n5 white queens\n6 white king\n\nBlack pieces use negative values\n-1 black pawn\n-2 black knight\netc\n\n8| -4 -2 -3 -5 -6 -3 -2 -4\n7| -1 -1 -1 -1 -1 -1 -1 -1\n6| 0 0 0 0 0 0 0 0\n5| 0 0 0 0 0 0 0 0\n4| 0 0 0 0 0 0 0 0\n3| 0 0 0 0 0 0 0 0\n2| 1 1 1 1 1 1 1 1 \n1| 4 2 3 5 6 3 2 4\n -------------------------\n 1 2 3 4 5 6 7 8\n"
},
{
"answer_id": 39885,
"author": "Marcel",
"author_id": 2554,
"author_profile": "https://Stackoverflow.com/users/2554",
"pm_score": 0,
"selected": false,
"text": "int[8][8]\n\n0=no piece\n1=king\n2=queen\n3=rook\n4=knight\n5=bishop\n6=pawn\n"
},
{
"answer_id": 39896,
"author": "Niyaz",
"author_id": 184,
"author_profile": "https://Stackoverflow.com/users/184",
"pm_score": 4,
"selected": false,
"text": "**White**\n9 = white queen\n5 = white rook\n3 = bishop\n3 = knight\n1 = pawn\n\n**black**\n-9 = white queen\n-5 = white rook\n-3 = bishop\n-3 = knight\n-1 = pawn\n\nWhite King: very large positive number\nBlack King: very large negative number\n"
},
{
"answer_id": 39899,
"author": "Binarytales",
"author_id": 319,
"author_profile": "https://Stackoverflow.com/users/319",
"pm_score": 1,
"selected": false,
"text": "board = arrary(A = array (1,2,3,4,5,5,6,7,8),\n B = array (12,3,.... etc...\n etc... \n )\n"
},
{
"answer_id": 524505,
"author": "Henry B",
"author_id": 6414,
"author_profile": "https://Stackoverflow.com/users/6414",
"pm_score": 0,
"selected": false,
"text": "Piece.x= x position of piece\nPiece.y= y position of piece\n"
},
{
"answer_id": 18475233,
"author": "bytefire",
"author_id": 1719372,
"author_profile": "https://Stackoverflow.com/users/1719372",
"pm_score": 4,
"selected": false,
"text": "ulong/UInt64"
},
{
"answer_id": 20709640,
"author": "Wayne",
"author_id": 592746,
"author_profile": "https://Stackoverflow.com/users/592746",
"pm_score": 2,
"selected": false,
"text": "-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n-1, \"a8\", \"b8\", \"c8\", \"d8\", \"e8\", \"f8\", \"g8\", \"h8\", -1,\n-1, \"a7\", \"b7\", \"c7\", \"d7\", \"e7\", \"f7\", \"g7\", \"h7\", -1,\n-1, \"a6\", \"b6\", \"c6\", \"d6\", \"e6\", \"f6\", \"g6\", \"h6\", -1,\n-1, \"a5\", \"b5\", \"c5\", \"d5\", \"e5\", \"f5\", \"g5\", \"h5\", -1,\n-1, \"a4\", \"b4\", \"c4\", \"d4\", \"e4\", \"f4\", \"g4\", \"h4\", -1,\n-1, \"a3\", \"b3\", \"c3\", \"d3\", \"e3\", \"f3\", \"g3\", \"h3\", -1,\n-1, \"a2\", \"b2\", \"c2\", \"d2\", \"e2\", \"f2\", \"g2\", \"h2\", -1,\n-1, \"a1\", \"b1\", \"c1\", \"d1\", \"e1\", \"f1\", \"g1\", \"h1\", -1,\n-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,\n-1, -1, -1, -1, -1, -1, -1, -1, -1, -1\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4262/"
] |
39,879
|
<p>Is it a deliberate design decision or a problem with our current day browsers which will be rectified in the coming versions?</p>
|
[
{
"answer_id": 39922,
"author": "pkaeding",
"author_id": 4257,
"author_profile": "https://Stackoverflow.com/users/4257",
"pm_score": 4,
"selected": false,
"text": "setTimeout(function () {\n ... do the rest of the work...\n}, 0);\n"
},
{
"answer_id": 39961,
"author": "Kamiel Wanrooij",
"author_id": 4174,
"author_profile": "https://Stackoverflow.com/users/4174",
"pm_score": 9,
"selected": true,
"text": "setTimeout"
},
{
"answer_id": 2400168,
"author": "Erich Kitzmueller",
"author_id": 65464,
"author_profile": "https://Stackoverflow.com/users/65464",
"pm_score": 0,
"selected": false,
"text": "synchronized"
},
{
"answer_id": 42172751,
"author": "Madhusoodan P",
"author_id": 4617334,
"author_profile": "https://Stackoverflow.com/users/4617334",
"pm_score": -1,
"selected": false,
"text": "/* content of the threads to be run */\nvar threads = [\n [\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\",\n \"document.write('Foo <br/>');\"\n ],\n [\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\",\n \"document.write('Bar <br/>');\"\n ]\n ];\n\nwindow.onload = function() {\n var lines = 0, quantum = 3, max = 0;\n\n /* get the longer thread length */\n for(var i=0; i<threads.length; i++) {\n if(max < threads[i].length) {\n max = threads[i].length;\n }\n }\n\n /* execute them */\n while(lines < max) {\n for(var i=0; i<threads.length; i++) {\n for(var j = lines; j < threads[i].length && j < (lines + quantum); j++) {\n eval(threads[i][j]);\n }\n }\n lines += quantum;\n }\n}\n"
},
{
"answer_id": 69784351,
"author": "Ahmed Yasin Koculu",
"author_id": 673692,
"author_profile": "https://Stackoverflow.com/users/673692",
"pm_score": 0,
"selected": false,
"text": "var engine = new TopazEngine();\nengine.AddType(typeof(Console), \"Console\");\ntopazEngine.AddType(typeof(Parallel), \"Parallel\");\nengine.ExecuteScript(@\"\nvar sharedVariable = 0\nfunction f1(i) {\n sharedVariable = i\n}\nParallel.For(0, 100000 , f1)\nConsole.WriteLine(`Final value: {sharedVariable}`);\n\");\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/184/"
] |
39,903
|
<p>Why does Visual Studio declare new classes as private in C#? I almost always switch them over to public, am I the crazy one?</p>
|
[
{
"answer_id": 39911,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 4,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n$if$ ($targetframeworkversion$ == 3.5)using System.Linq;\n$endif$using System.Text; \n\nnamespace $rootnamespace$\n{\n class $safeitemrootname$\n {\n }\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/632/"
] |
39,910
|
<p>I want to use the MultipleLookupField control in a web page that will run in the context of SharePoint. I was wondering if anyone would help me with an example, which shows step by step how to use the control two display two SPField Collections.</p>
|
[
{
"answer_id": 40929,
"author": "Matt Bishop",
"author_id": 4301,
"author_profile": "https://Stackoverflow.com/users/4301",
"pm_score": 3,
"selected": true,
"text": "Label l;\nMultipleLookupField mlf;\n\nprotected override void CreateChildControls()\n{\n base.CreateChildControls();\n SPList list = SPContext.Current.Web.Lists[\"Shared Documents\"];\n if (list != null && list.Items.Count > 0)\n {\n LiteralControl lit = new LiteralControl(\"Associate tasks to \" + \n list.Items[0].Name);\n this.Controls.Add(lit);\n\n mlf = new MultipleLookupField();\n mlf.ControlMode = SPControlMode.Edit;\n mlf.FieldName = \"Related\";\n mlf.ItemId = list.Items[0].ID;\n mlf.ListId = list.ID;\n mlf.ID = \"Related\";\n this.Controls.Add(mlf);\n\n Button b = new Button();\n b.Text = \"Change\";\n b.Click += new EventHandler(bClick);\n this.Controls.Add(b);\n\n l = new Label();\n this.Controls.Add(l);\n }\n\n}\n\nvoid bClick(object sender, EventArgs e)\n{\n l.Text = \"\";\n foreach (SPFieldLookupValue val in (SPFieldLookupValueCollection)mlf.Value)\n {\n l.Text += val.LookupValue.ToString() + \" \";\n }\n SPListItem listitem = mlf.List.Items[0];\n listitem[\"Related\"] = mlf.Value;\n listitem.Update();\n mlf.Value = listitem[\"Related\"];\n}\n\nprotected override void OnInit(EventArgs e)\n{\n base.OnInit(e);\n EnsureChildControls();\n}\n"
},
{
"answer_id": 45022,
"author": "Matt Bishop",
"author_id": 4301,
"author_profile": "https://Stackoverflow.com/users/4301",
"pm_score": 0,
"selected": false,
"text": "<%@ Page Language=\"C#\" Inherits=\"System.Web.UI.Page\" MasterPageFile=\"~/_layouts/simple.master\" %> \n<%@ Register Tagprefix=\"foo\" Namespace=\"Foople\" Assembly=\"Foople, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5\"%>\n<asp:Content ContentPlaceHolderId=\"PlaceHolderMain\" runat=\"server\">\n<foo:WebPart1 id=\"fred\" runat=\"server\" />\n<foo:WebPart1a id=\"barney\" runat=\"server\" />\n</asp:Content>\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1360/"
] |
39,912
|
<p>I was looking at the API documentation for stl vector, and noticed there was no method on the vector class that allowed the removal of an element with a certain value. This seems like a common operation, and it seems odd that there's no built in way to do this.</p>
|
[
{
"answer_id": 39923,
"author": "bradtgmurray",
"author_id": 1546,
"author_profile": "https://Stackoverflow.com/users/1546",
"pm_score": 4,
"selected": false,
"text": "std::vector<int> v;\nv.push_back(1);\nv.push_back(2);\n\n//Vector should contain the elements 1, 2\n\n//Find new end iterator\nstd::vector<int>::iterator newEnd = std::remove(v.begin(), v.end(), 1);\n\n//Erase the \"removed\" elements.\nv.erase(newEnd, v.end());\n\n//Vector should now only contain 2\n"
},
{
"answer_id": 39941,
"author": "Xavier Nodet",
"author_id": 4177,
"author_profile": "https://Stackoverflow.com/users/4177",
"pm_score": 2,
"selected": false,
"text": "vector<int> V;\nV.push_back(1);\nV.push_back(4);\nV.push_back(2);\nV.push_back(8);\nV.push_back(5);\nV.push_back(7);\n\ncopy(V.begin(), V.end(), ostream_iterator<int>(cout, \" \"));\n // The output is \"1 4 2 8 5 7\"\n\nvector<int>::iterator new_end = \n remove_if(V.begin(), V.end(), \n compose1(bind2nd(equal_to<int>(), 0),\n bind2nd(modulus<int>(), 2)));\nV.erase(new_end, V.end()); [1]\n\ncopy(V.begin(), V.end(), ostream_iterator<int>(cout, \" \"));\n // The output is \"1 5 7\".\n"
},
{
"answer_id": 39944,
"author": "Jim Buck",
"author_id": 2666,
"author_profile": "https://Stackoverflow.com/users/2666",
"pm_score": 9,
"selected": true,
"text": "std::remove"
},
{
"answer_id": 39985,
"author": "nsanders",
"author_id": 1244,
"author_profile": "https://Stackoverflow.com/users/1244",
"pm_score": 3,
"selected": false,
"text": "resize()"
},
{
"answer_id": 15998752,
"author": "Etherealone",
"author_id": 1576556,
"author_profile": "https://Stackoverflow.com/users/1576556",
"pm_score": 6,
"selected": false,
"text": "std::vector<int> v;\n\n\nauto it = std::find(v.begin(), v.end(), 5);\nif(it != v.end())\n v.erase(it);\n"
},
{
"answer_id": 45186119,
"author": "jhasse",
"author_id": 647898,
"author_profile": "https://Stackoverflow.com/users/647898",
"pm_score": 2,
"selected": false,
"text": "#include <boost/range/algorithm_ext/erase.hpp>\n\n// ...\n\nboost::remove_erase(vec, int_to_remove);\n"
},
{
"answer_id": 47603631,
"author": "Katianie",
"author_id": 389832,
"author_profile": "https://Stackoverflow.com/users/389832",
"pm_score": -1,
"selected": false,
"text": "vector<IComponent*> myComponents; //assume it has items in it already.\nvoid RemoveComponent(IComponent* componentToRemove)\n{\n IComponent* juggler;\n\n if (componentToRemove != NULL)\n {\n for (int currComponentIndex = 0; currComponentIndex < myComponents.size(); currComponentIndex++)\n {\n if (componentToRemove == myComponents[currComponentIndex])\n {\n //Since we don't care about order, swap with the last element, then delete it.\n juggler = myComponents[currComponentIndex];\n myComponents[currComponentIndex] = myComponents[myComponents.size() - 1];\n myComponents[myComponents.size() - 1] = juggler;\n\n //Remove it from memory and let the vector know too.\n myComponents.pop_back();\n delete juggler;\n }\n }\n }\n}\n"
},
{
"answer_id": 52623923,
"author": "DecPK",
"author_id": 9153448,
"author_profile": "https://Stackoverflow.com/users/9153448",
"pm_score": 0,
"selected": false,
"text": "std :: vector < int > v;\nv.push_back(10);\nv.push_back(20);\nv.push_back(30);\nv.push_back(40);\nv.push_back(40);\nv.push_back(50);\n"
},
{
"answer_id": 56157255,
"author": "Pavan Chandaka",
"author_id": 6866309,
"author_profile": "https://Stackoverflow.com/users/6866309",
"pm_score": 3,
"selected": false,
"text": "std::erase"
},
{
"answer_id": 61587400,
"author": "Harshad Sharma",
"author_id": 9060084,
"author_profile": "https://Stackoverflow.com/users/9060084",
"pm_score": 2,
"selected": false,
"text": "#include <vector>\n...\nvector<int> cnt{5, 0, 2, 8, 0, 7};\nstd::erase(cnt, 0);\n"
},
{
"answer_id": 72653247,
"author": "Antonio",
"author_id": 2436175,
"author_profile": "https://Stackoverflow.com/users/2436175",
"pm_score": 0,
"selected": false,
"text": "vector"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1546/"
] |
39,915
|
<p>There are several types of objects in a system, and each has it's own table in the database. A user should be able to comment on any of them. How would you design the comments table(s)? I can think of a few options:</p>
<ol>
<li>One comments table, with a FK column for each object type (ObjectAID, ObjectBID, etc)</li>
<li>Several comments tables, one for each object type (ObjectAComments, ObjectBComments, etc)</li>
<li>One generic FK (ParentObjectID) with another column to indicate the type ("ObjectA")</li>
</ol>
<p>Which would you choose? Is there a better method I'm not thinking of?</p>
|
[
{
"answer_id": 39997,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 2,
"selected": true,
"text": "ObjectAID"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/521/"
] |
39,916
|
<p>Is there a programmatic way to build <em>htpasswd</em> files, without depending on OS specific functions (i.e. <code>exec()</code>, <code>passthru()</code>)?</p>
|
[
{
"answer_id": 39963,
"author": "Greg Roberts",
"author_id": 4269,
"author_profile": "https://Stackoverflow.com/users/4269",
"pm_score": 6,
"selected": true,
"text": "foo:$apr1$y1cXxW5l$3vapv2yyCXaYz8zGoXj241\n"
},
{
"answer_id": 53006,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": -1,
"selected": false,
"text": "<?php\n\n// Set the password & username\n$username = 'user';\n$password = 'mypassword';\n\n// Get the hash, letting the salt be automatically generated\n$hash = crypt($password);\n\n// write to a file\nfile_set_contents('.htpasswd', $username ':' . $contents);\n\n?>\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
39,928
|
<p>I'm getting a <strong><code>Connection Busy With Results From Another Command</code></strong> error from a SQLServer Native Client driver when a SSIS package is running. Only when talking to SQLServer 2000. A different part that talks to SQLServer 2005 seems to always run fine. Any thoughts?</p>
|
[
{
"answer_id": 40105,
"author": "Craig",
"author_id": 2894,
"author_profile": "https://Stackoverflow.com/users/2894",
"pm_score": 2,
"selected": true,
"text": "Server: Msg 7399, Level 16, State 1, Procedure <storedProcedureName>, Line 18 OLE DB provider 'SQLOLEDB' reported an error. \nOLE/DB Provider 'SQLOLEDB' ::GetSchemaLock returned 0x80004005:\n\nOLE DB provider SQLOLEDB supported the Schema Lock interface, but returned 0x80004005 for GetSchemaLock .]. \nOLE/DB provider returned message: Connection is busy with results for another command \nOLE DB error trace [OLE/DB Provider 'SQLOLEDB' ::CreateSession returned 0x80004005.\n"
},
{
"answer_id": 17923000,
"author": "OZ_",
"author_id": 680786,
"author_profile": "https://Stackoverflow.com/users/680786",
"pm_score": 2,
"selected": false,
"text": "closeCursor()"
},
{
"answer_id": 28130401,
"author": "smozgur",
"author_id": 3115000,
"author_profile": "https://Stackoverflow.com/users/3115000",
"pm_score": 3,
"selected": false,
"text": "[ConnName]\nDriver=ODBC Driver 11 for SQL Server\nServer=192.168.2.218,1433\nDatabase=DBNameHere\nMARS_Connection=yes\n"
},
{
"answer_id": 43854950,
"author": "marcob",
"author_id": 7982355,
"author_profile": "https://Stackoverflow.com/users/7982355",
"pm_score": 0,
"selected": false,
"text": "\\HKLM\\Software\\ODBC\\ODBC.INI\\MyDSN\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2978/"
] |
39,946
|
<p>I'm trying to boil down the concepts of coupling and cohesion to a concise definition. Can someone give me a short and understandable explanation (shorter than the definitions on Wikipedia <a href="http://en.wikipedia.org/wiki/Coupling_%28computer_science%29" rel="noreferrer">here</a> and <a href="http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29" rel="noreferrer">here</a>)? How do they interact?</p>
<p>Thanks.</p>
<p>Anybody have a good, short example?</p>
|
[
{
"answer_id": 39976,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 2,
"selected": false,
"text": "import"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39946",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1772/"
] |
39,960
|
<p>In Python one can get a dictionary of all local and global variables in the current scope with the built-in functions <code>locals()</code> and <code>globals()</code>. Is there some equivalent way of doing this in Javascript? For instance, I would like to do something like the following:</p>
<pre><code>var foo = function(){ alert('foo'); };
var bar = function(){ alert('bar'); };
var s = 'foo';
locals()[s](); // alerts 'foo'
</code></pre>
<p>Is this at all possible, or should I just be using a local object for the lookup?</p>
|
[
{
"answer_id": 39982,
"author": "Bartosz Bierkowski",
"author_id": 3666,
"author_profile": "https://Stackoverflow.com/users/3666",
"pm_score": 2,
"selected": false,
"text": "eval(s+\"()\");\n"
},
{
"answer_id": 39992,
"author": "Grey Panther",
"author_id": 1265,
"author_profile": "https://Stackoverflow.com/users/1265",
"pm_score": -1,
"selected": false,
"text": "if (foo) foo();\n"
},
{
"answer_id": 40012,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 2,
"selected": false,
"text": "arguments"
},
{
"answer_id": 40035,
"author": "pkaeding",
"author_id": 4257,
"author_profile": "https://Stackoverflow.com/users/4257",
"pm_score": 0,
"selected": false,
"text": "function foo() {\n var bar = function () {\n alert('hello world');\n };\n var s = 'bar';\n window[s](); // this won't work\n}\n"
},
{
"answer_id": 40067,
"author": "Bartosz Bierkowski",
"author_id": 3666,
"author_profile": "https://Stackoverflow.com/users/3666",
"pm_score": 0,
"selected": false,
"text": "var func = {};\nfunc.bar = ...;\nvar s = \"bar\";\nfunc[s]();\n"
},
{
"answer_id": 40173,
"author": "sverrejoh",
"author_id": 473,
"author_profile": "https://Stackoverflow.com/users/473",
"pm_score": 5,
"selected": true,
"text": "window"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/208/"
] |
39,977
|
<p>I know how to use tags in subversion. I create a tag every time I get to a release milestone.</p>
<p>What I don't quite understand is how they work. </p>
<p>Is a tag just a copy, made from what ever revision I specify? Or is a tag more like a reference, where internally subversion just says <code>GO TO /trunk/project/ Revision 5</code> or whatever.</p>
<p>The command to create a tag (<code>svn copy</code>) seems to imply that it's a copy, but I've seen other people write that subversion doesn't really copy anything.</p>
<p>Say I dump just the HEAD revision of a repository. I don't care about any history except the tags. Are those tags dumped along with the rest of the Head revision?</p>
<p>Finally, is all this just programming magic that I don't really want to know.</p>
|
[
{
"answer_id": 39980,
"author": "Chris Conway",
"author_id": 1412,
"author_profile": "https://Stackoverflow.com/users/1412",
"pm_score": 2,
"selected": false,
"text": "svn copy trunk tags/BLAH\n"
},
{
"answer_id": 18407691,
"author": "Jorgesys",
"author_id": 250260,
"author_profile": "https://Stackoverflow.com/users/250260",
"pm_score": 0,
"selected": false,
"text": "$ svn copy https://jorgesysgr.com/svn/AndNews/branches \\\n https://jorgesysgr.com/svn/AndNews/tags/release-1.1 \\\n -m \"release 1.1 Android News.\"\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39977",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30/"
] |
39,983
|
<p>Reading through <a href="https://stackoverflow.com/questions/39879/why-doesnt-javascript-support-multithreading">this question</a> on multi-threaded javascript, I was wondering if there would be any security implications in allowing javascript to spawn mutliple threads. For example, would there be a risk of a malicious script repeatedly spawning thread after thread in an attempt to overwhelm the operating system or interpreter and trigger entrance into "undefined behavior land", or is it pretty much a non-issue? Any other ways in which an attack might exploit a hypothetical implementation of javascript that supports threads that a non-threading implementation would be immune to?</p>
<p><strong>Update:</strong> Note that locking up a browser isn't the same as creating an undefined behavior exploit. </p>
|
[
{
"answer_id": 40024,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 1,
"selected": false,
"text": "Worker"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/39983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] |
40,022
|
<p>I'm using LINQ to SQL classes in a project where the database design is still in a bit of flux.</p>
<p>Is there an easy way of synchronising the classes with the schema, or do I need to manually update the classes if a table design changes?</p>
|
[
{
"answer_id": 40029,
"author": "vzczc",
"author_id": 224,
"author_profile": "https://Stackoverflow.com/users/224",
"pm_score": 7,
"selected": true,
"text": "C:\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\Bin\\x64\\sqlmetal.exe \n /server:<SERVER> \n /database:<database> \n /code:\"path\\Solution\\DataContextProject\\dbContext.cs\" \n /language:csharp \n /namespace:<your namespace>\n"
},
{
"answer_id": 21531735,
"author": "Levite",
"author_id": 1680919,
"author_profile": "https://Stackoverflow.com/users/1680919",
"pm_score": 3,
"selected": false,
"text": "right-click ->"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4048/"
] |
40,026
|
<p>As the title says, is there a way to run the same Adobe AIR app more than once? I have a little widget I wrote that shows thumbnails from a couple of photo streams, and I'd like to fix it so I can look at more than one stream at a time. Thanks!</p>
|
[
{
"answer_id": 40091,
"author": "Todd Rowan",
"author_id": 3473,
"author_profile": "https://Stackoverflow.com/users/3473",
"pm_score": 2,
"selected": false,
"text": "<application xmlns=\"http://ns.adobe.com/air/application/1.0\">\n <id>ApplicationID</id>\n"
},
{
"answer_id": 34955176,
"author": "user5828094",
"author_id": 5828094,
"author_profile": "https://Stackoverflow.com/users/5828094",
"pm_score": 1,
"selected": false,
"text": "<id>"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4252/"
] |
40,028
|
<p>I think it can be done by applying the transformation matrix of the scenegraph to z-normal (0, 0, 1), but it doesn't work. My code goes like this:</p>
<pre><code>Vector3f toScreenVector = new Vector3f(0, 0, 1);
Transform3D t3d = new Transform3D();
tg.getTransform(t3d); //tg is Transform Group of all objects in a scene
t3d.transform(toScreenVector);
</code></pre>
<p>Then I tried something like this too:</p>
<pre><code>Point3d eyePos = new Point3d();
Point3d mousePos = new Point3d();
canvas.getCenterEyeInImagePlate(eyePos);
canvas.getPixelLocationInImagePlate(new Point2d(Main.WIDTH/2, Main.HEIGHT/2), mousePos); //Main is the class for main window.
Transform3D motion = new Transform3D();
canvas.getImagePlateToVworld(motion);
motion.transform(eyePos);
motion.transform(mousePos);
Vector3d toScreenVector = new Vector3f(eyePos);
toScreenVector.sub(mousePos);
toScreenVector.normalize();
</code></pre>
<p>But still this doesn't work correctly. I think there must be an easy way to create such vector. Do you know what's wrong with my code or better way to do so?</p>
|
[
{
"answer_id": 40666,
"author": "caramelcarrot",
"author_id": 3877,
"author_profile": "https://Stackoverflow.com/users/3877",
"pm_score": 2,
"selected": false,
"text": "INVERT"
},
{
"answer_id": 41231,
"author": "puri",
"author_id": 3388,
"author_profile": "https://Stackoverflow.com/users/3388",
"pm_score": 1,
"selected": true,
"text": "Vector3f toScreenVector = new Vector3f(0, 0, 1);\n\nTransform3D t3d = new Transform3D();\ncanvas.getImagePlateToVworld(t3d);\nt3d.transform(toScreenVector);\n\ntg.getTransform(t3d); //tg is Transform Group of all objects in a scene\nt3d.transform(toScreenVector);\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40028",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3388/"
] |
40,043
|
<p>How can I create a new database from my C# application?</p>
<p>I'm assuming once I create it, I can simply generate a connection string on the fly and connect to it, and the issue all the CREATE TABLE statements.</p>
|
[
{
"answer_id": 40061,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 5,
"selected": true,
"text": "String str;\nSqlConnection myConn = new SqlConnection (\"Server=localhost;Integrated security=SSPI;database=master\");\n\nstr = \"CREATE DATABASE MyDatabase ON PRIMARY \" +\n \"(NAME = MyDatabase_Data, \" +\n \"FILENAME = 'C:\\\\MyDatabaseData.mdf', \" +\n \"SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) \" +\n \"LOG ON (NAME = MyDatabase_Log, \" +\n \"FILENAME = 'C:\\\\MyDatabaseLog.ldf', \" +\n \"SIZE = 1MB, \" +\n \"MAXSIZE = 5MB, \" +\n \"FILEGROWTH = 10%)\";\n\nSqlCommand myCommand = new SqlCommand(str, myConn);\ntry \n{\n myConn.Open();\n myCommand.ExecuteNonQuery();\n MessageBox.Show(\"DataBase is Created Successfully\", \"MyProgram\", MessageBoxButtons.OK, MessageBoxIcon.Information);\n}\ncatch (System.Exception ex)\n{\n MessageBox.Show(ex.ToString(), \"MyProgram\", MessageBoxButtons.OK, MessageBoxIcon.Information);\n}\nfinally\n{\n if (myConn.State == ConnectionState.Open)\n {\n myConn.Close();\n }\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3314/"
] |
40,054
|
<p>Code below does not run correctly and throws <code>InvalidOperationExcepiton</code>.</p>
<pre><code>public void Foo()
{
DataContext context = new DataContext();
LinqEntity item = new LinqEntity(){ Id = 1, Name = "John", Surname = "Doe"} ;
context.LinqEntities.Attach(item, true);
}
</code></pre>
|
[
{
"answer_id": 40079,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 1,
"selected": false,
"text": "context.LinqEntities.InsertOnSubmit(item);\ncontext.Submit();\n"
},
{
"answer_id": 40108,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 1,
"selected": false,
"text": "DataContext context = new DataContext();\nLinqEntity item = (from le in context.LinqEntities\n where le.ID == 1\n select le).Single();\nitem.Name = \"John\";\nitem.Surname = \"Doe\";\n\ncontext.Submit();\n"
},
{
"answer_id": 40208,
"author": "Scott Nichols",
"author_id": 4299,
"author_profile": "https://Stackoverflow.com/users/4299",
"pm_score": 3,
"selected": true,
"text": "LinqEntity item = new LinqEntity(){ Id = 1, Name = \"OldName\", Surname = \"OldSurname\"}; \ncontext.LinqEntities.Attach(item);\nitem.Name = \"John\";\nitem.Surname = \"Doe\";\ncontext.SubmitChanges();\n"
},
{
"answer_id": 40948,
"author": "liammclennan",
"author_id": 2785,
"author_profile": "https://Stackoverflow.com/users/2785",
"pm_score": 0,
"selected": false,
"text": "DataContext.ExecuteCommand(...)"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4215/"
] |
40,075
|
<p>I am writing a few extensions to mimic the map and reduce functions in Lisp.</p>
<pre><code>public delegate R ReduceFunction<T,R>(T t, R previous);
public delegate void TransformFunction<T>(T t, params object[] args);
public static R Reduce<T,R>(this List<T> list, ReduceFunction<T,R> r, R initial)
{
var aggregate = initial;
foreach(var t in list)
aggregate = r(t,aggregate);
return aggregate;
}
public static void Transform<T>(this List<T> list, TransformFunction<T> f, params object [] args)
{
foreach(var t in list)
f(t,args);
}
</code></pre>
<p>The transform function will cut down on cruft like:</p>
<pre><code>foreach(var t in list)
if(conditions && moreconditions)
//do work etc
</code></pre>
<p>Does this make sense? Could it be better?</p>
|
[
{
"answer_id": 40084,
"author": "Jake Pearson",
"author_id": 632,
"author_profile": "https://Stackoverflow.com/users/632",
"pm_score": 2,
"selected": false,
"text": "public static R Reduce<T,R>(this IEnumerable<T> list, Func<T,R> r, R initial)\n{\n var aggregate = initial;\n foreach(var t in list)\n aggregate = r(t,aggregate);\n\n return aggregate;\n}\npublic static void Transform<T>(this IEnumerable<T> list, Func<T> f)\n{\n foreach(var t in list)\n f(t);\n}\n"
},
{
"answer_id": 40089,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 1,
"selected": false,
"text": "public static List<T> Transform<T>(this List<T> list, TransformFunction<T> f,\n params object [] args)\n{\n return Transform(list, f, false, args);\n}\n\npublic static List<T> Transform<T>(this List<T> list, TransformFunction<T> f,\n bool create, params object [] args)\n{\n // Add code to create if create is true (sorry,\n // too lazy to actually code this up)\n foreach(var t in list)\n f(t,args);\n return list;\n}\n"
},
{
"answer_id": 40148,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 6,
"selected": true,
"text": "//takes a function that matches the Func<T,R> delegate\nlistInstance.Aggregate( \n startingValue, \n (x, y) => /* aggregate two subsequent values */ );\n\n//takes a function that matches the Action<T> delegate\nlistInstance.ForEach( \n x => /* do something with x */);\n"
},
{
"answer_id": 54801689,
"author": "CsUtil.com",
"author_id": 10808596,
"author_profile": "https://Stackoverflow.com/users/10808596",
"pm_score": 1,
"selected": false,
"text": "public static IEnumerable<R> Map<T, R>(this IEnumerable<T> self, Func<T, R> selector) {\n return self.Select(selector);\n}\n\npublic static T Reduce<T>(this IEnumerable<T> self, Func<T, T, T> func) {\n return self.Aggregate(func);\n}\n\npublic static IEnumerable<T> Filter<T>(this IEnumerable<T> self, Func<T, bool> predicate) {\n return self.Where(predicate);\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1455/"
] |
40,090
|
<p>Is it true that the only way to handle default function arguments is through function overloading?</p>
<p>For example, in PHP I can do this:</p>
<pre><code>function foo($x, $y=0)
{
}
</code></pre>
<p>Would the best way to handle it in C# be this?</p>
<pre><code>void foo(int x)
{
foo(x, 0);
}
void foo(int x, int y)
{
}
</code></pre>
<p><strong><em><a href="http://bytes.com/forum/thread224970.html" rel="noreferrer">Example lifted from here</a></em></strong></p>
<p>Edit</p>
<p><strong><em>Made the C# example into actual C# (Thanks Blair Conrad)</em></strong></p>
|
[
{
"answer_id": 40093,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": true,
"text": "$"
},
{
"answer_id": 696656,
"author": "gazhay",
"author_id": 84545,
"author_profile": "https://Stackoverflow.com/users/84545",
"pm_score": 0,
"selected": false,
"text": "void foo(int x):this(x, 0){}\n\nvoid foo(int x, int y){\n // code here\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] |
40,107
|
<p>I imagine everyone has seen code like:</p>
<pre><code>public void Server2ClientEnumConvert( ServerEnum server)
{
switch(server)
{
case ServerEnum.One:
return ClientEnum.ABC
//And so on.
</code></pre>
<p>Instead of this badness we could do somthing like:</p>
<pre><code>public enum ServerEnum
{
[Enum2Enum(ClientEnum.ABC)]
One,
}
</code></pre>
<p>Now we can use reflection to rip through ServerEnum and get the conversion mappings from the enum declaration itself.</p>
<p>The problem I am having here is in the declaration of the Enum2Enum attribute.</p>
<p>This works but replacing object o with Enum e does not. I do not want to be able to pass in objects to the constructor, only other enums.</p>
<pre><code>public class EnumToEnumAttribute : Attribute
{
public EnumToEnumAttribute(object o){}
}
</code></pre>
<p>This fails to compile.</p>
<pre><code>public class EnumToEnumAttribute : Attribute
{
public EnumToEnumAttribute(Enum e){}
}
</code></pre>
<p>Is there a reason for the compile error? How else could I pass in the information needed to map besides: </p>
<pre><code>EnumtoEnumAttribute(Type dest, string enumString)
</code></pre>
<p>This seems too verbose but if it is the only way then I guess I will use it.</p>
|
[
{
"answer_id": 398461,
"author": "Scott Dorman",
"author_id": 1559,
"author_profile": "https://Stackoverflow.com/users/1559",
"pm_score": 2,
"selected": false,
"text": "public enum ServerEnum\n{\n One = ClientEnum.ABC,\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1455/"
] |
40,112
|
<p>I've got an MS-Access app (1/10th MS-Acccess, 9/10ths MS-SQL) that needs to display photographs of some assets along with their specifications. Currently the images are stored in an MS-Access table as an OLE Object (and copy-n-pasted into the field by the users).</p>
<p>For various reasons, I would like to do is store the original .jpgs in a folder on the network drive, and reference them from the application portion. I have considered moving into MS-SQL's image data type (and its replacement varbinary), but I think my user population will more easily grasp the concept of the network folder.</p>
<p>How can I get MS Access to display the contents of a .jpg?</p>
|
[
{
"answer_id": 41036,
"author": "WaterBoy",
"author_id": 3270,
"author_profile": "https://Stackoverflow.com/users/3270",
"pm_score": 4,
"selected": true,
"text": "Private Sub cmdNextClick()\n DoCmd.GoToRecord , , acNext\n txtPhoto.SetFocus\n imgPicture.Picture = txtPhoto.Text\n Exit Sub\nEnd Sub\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/685/"
] |
40,116
|
<p>How do I get it to work with my project?</p>
<p><a href="http://ajax.asp.net/" rel="noreferrer">http://ajax.asp.net/</a></p>
<p><a href="http://www.codeplex.com/AjaxControlToolkit/" rel="noreferrer">http://www.codeplex.com/AjaxControlToolkit/</a></p>
|
[
{
"answer_id": 40118,
"author": "Zack Peterson",
"author_id": 83,
"author_profile": "https://Stackoverflow.com/users/83",
"pm_score": 5,
"selected": false,
"text": "<?xml version=\"1.0\"?>\n<configuration>\n ...\n <system.web>\n ...\n <pages>\n ...\n <controls>\n ...\n <add tagPrefix=\"ajaxtoolkit\"\n namespace=\"AjaxControlToolkit\"\n assembly=\"AjaxControlToolKit\"/>\n </controls>\n </pages>\n ...\n </system.web>\n ...\n</configuration>\n"
},
{
"answer_id": 7851499,
"author": "Xenon",
"author_id": 331798,
"author_profile": "https://Stackoverflow.com/users/331798",
"pm_score": 4,
"selected": false,
"text": "Install-Package AjaxControlToolkit"
},
{
"answer_id": 11398469,
"author": "Mohammad Sepahvand",
"author_id": 189756,
"author_profile": "https://Stackoverflow.com/users/189756",
"pm_score": 1,
"selected": false,
"text": "AjaxControlToolkit.dll"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
40,119
|
<p>How do you find a memory leak in Java (using, for example, JHat)? I have tried to load the heap dump up in JHat to take a basic look. However, I do not understand how I am supposed to be able to find the root reference (<a href="https://stackoverflow.com/questions/104/anatomy-of-a-memory-leak">ref</a>) or whatever it is called. Basically, I can tell that there are several hundred megabytes of hash table entries ([java.util.HashMap$Entry or something like that), but maps are used all over the place... Is there some way to search for large maps, or perhaps find general roots of large object trees?</p>
<p>[Edit]
Ok, I've read the answers so far but let's just say I am a cheap bastard (meaning I am more interested in learning how to use JHat than to pay for JProfiler). Also, JHat is always available since it is part of the JDK. Unless of course there is no way with JHat but brute force, but I can't believe that can be the case.</p>
<p>Also, I do not think I will be able to actually modify (adding logging of <em>all</em> map sizes) and run it for long enough for me to notice the leak.</p>
|
[
{
"answer_id": 31018959,
"author": "Alex Punnen",
"author_id": 429476,
"author_profile": "https://Stackoverflow.com/users/429476",
"pm_score": 4,
"selected": false,
"text": "su proceeuser\n/bin/jmap -dump:live,format=b,file=/tmp/2930javaheap.hrpof 2930(pid of process)\n"
},
{
"answer_id": 57993151,
"author": "Amir Fo",
"author_id": 7580839,
"author_profile": "https://Stackoverflow.com/users/7580839",
"pm_score": 0,
"selected": false,
"text": "Runtime runtime = Runtime.getRuntime();\n\nwhile(true) {\n ...\n if(System.currentTimeMillis() % 4000 == 0){\n System.gc();\n float usage = (float) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;\n System.out.println(\"Used memory: \" + usage + \"Mb\");\n }\n\n}\n"
},
{
"answer_id": 59315884,
"author": "Sreeram Nair",
"author_id": 1853243,
"author_profile": "https://Stackoverflow.com/users/1853243",
"pm_score": 0,
"selected": false,
"text": "heap dumps"
},
{
"answer_id": 66785045,
"author": "Jafar Karuthedath",
"author_id": 2668564,
"author_profile": "https://Stackoverflow.com/users/2668564",
"pm_score": 0,
"selected": false,
"text": "jvisualvm"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40119",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4208/"
] |
40,122
|
<p>My group is developing a service-based (.NET WCF) application and we're trying to decide how to handle exceptions in our internal services. Should we throw exceptions? Return exceptions serialized as XML? Just return an error code?</p>
<p>Keep in mind that the user will never see these exceptions, it's only for other parts of the application.</p>
|
[
{
"answer_id": 40170,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 3,
"selected": true,
"text": "SoapFaults"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4219/"
] |
40,125
|
<p>I'm trying to get a Firefox plugin to read data from a HTTP get, parse the results and present them as links in a bookmark-like drop-down menu.</p>
<p>My quesion then is: Does anyone have any sample code that will do this?</p>
|
[
{
"answer_id": 40167,
"author": "Robert J. Walker",
"author_id": 4287,
"author_profile": "https://Stackoverflow.com/users/4287",
"pm_score": 2,
"selected": false,
"text": "var xmlhttp = new XMLHttpRequest();\nxmlhttp.open(\"GET\", url, true);\n\nxmlhttp.onreadystatechange = function() {\n if(this.readyState == 4) { // Done loading?\n if(this.status == 200) { // Everything okay?\n // read content from this.responseXML or this.responseText\n } else { // Error occurred; handle it\n alert(\"Error \" + this.status + \":\\n\" + this.statusText);\n }\n }\n};\n\nxmlhttp.send(null);\n"
},
{
"answer_id": 58273,
"author": "pc1oad1etter",
"author_id": 525,
"author_profile": "https://Stackoverflow.com/users/525",
"pm_score": 0,
"selected": false,
"text": " xmlhttp.responseText\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4165/"
] |
40,132
|
<p>I've got a situation where I have a main form that pops up an advanced configuration form that just has half a dozen matched check boxes and combo boxes to select some advanced options (the check boxes to enable/disable, the combo to select a media if enabled).</p>
<p>If I just pass the individual settings for the check and combo boxes in to the constructor for the dialog that's obviously a dozen arguments, which seems a bit excessive.</p>
<p>My other obvious option would be since in the main form these settings are stored in a large IDictionary with all the other main form settings I could just pass this dictionary in and fetch it back afterward with the updated values, but my understanding is that this wouldn't really be very good coding practice.</p>
<p>Am I missing a good way to do this that is both efficient and good coding practice?</p>
<p>(this particular code is in C#, although I have a feeling a general solution would apply to other languages as well)</p>
|
[
{
"answer_id": 40149,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 0,
"selected": false,
"text": "MyConfigurationDialog dialog = new MyConfigurationDialog();\n\n//Copy the dictionary so that the dialog can't mess with our settings\ndialog.Settings = new Dictionary(existingSettings);\n\nif(DialogResult.OK == dialog.Show()) {\n //grab the settings that the dialog may have changed\n existingSettings[\"setting1\"] = dialog.Settings[\"setting1\"];\n existingSettings[\"setting2\"] = dialog.Settings[\"setting2\"];\n}\n"
},
{
"answer_id": 40192,
"author": "Ed Schwehm",
"author_id": 1206,
"author_profile": "https://Stackoverflow.com/users/1206",
"pm_score": 1,
"selected": false,
"text": "class ContainerObject\n{\n public IDictionary<object, object> _dict;\n public ContainerObject(IDictionary<object, object> dict)\n {\n _dict = dict;\n }\n\n public bool FirstEnabled\n {\n get { return (bool) _dict[\"FirstEnabled\"]; }\n set { _dict[\"FirstEnabled\"] = value; }\n }\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1512/"
] |
40,133
|
<p>I have been experimenting with <a href="http://www.woopra.com/" rel="nofollow noreferrer">woopra.com</a> A web analytics tool. Which requires a piece of javascript code to be added to each page to function. This is easy enough with more dynamic sites with universal headers or footers but not for totally static html pages.</p>
<p>I attempted to work round it by using a combination of Apache rewrites and SSI's to "Wrap" the static html with the required code. For example...</p>
<p>I made the following changes to my apache config</p>
<pre><code> RewriteEngine On
RewriteCond %{REQUEST_URI} !=test.shtml
RewriteCond %{IS_SUBREQ} false
RewriteRule (.*)\.html test.shtml?$1.html
</code></pre>
<p>The test.shtml file contains...</p>
<pre><code> <script type="text/javascript">
var XXXXid = 'xxxxxxx';
</script>
<script src="http://xxxx.woopra.com/xx/xxx.js"></script>
<!--#set var="page" value="$QUERY_STRING" -->
<!--#include virtual= $page -->
</code></pre>
<p>The idea was that a request coming in for</p>
<pre><code> /abc.html
</code></pre>
<p>would be redirected to</p>
<pre><code> /test.shtml?abc.html
</code></pre>
<p>the shtml would then include the original file into the response page.</p>
<p>Unfortunately it doesn't quite work as planed :) can anyone see what I am doing wrong or perhaps suggest an alternative approach. Is there any apache modules that could do the same thing. Preferably that can be configured on a per site basis.</p>
<p>Thanks</p>
<p>Peter</p>
|
[
{
"answer_id": 40156,
"author": "Grey Panther",
"author_id": 1265,
"author_profile": "https://Stackoverflow.com/users/1265",
"pm_score": 3,
"selected": true,
"text": "while (<>) {\n s/<html>/\\Q<script>....\\E/;\n print $_;\n}\n"
},
{
"answer_id": 490116,
"author": "Alan Doherty",
"author_id": 59995,
"author_profile": "https://Stackoverflow.com/users/59995",
"pm_score": 0,
"selected": false,
"text": "<html>"
},
{
"answer_id": 1196832,
"author": "Alex Lehmann",
"author_id": 27069,
"author_profile": "https://Stackoverflow.com/users/27069",
"pm_score": 0,
"selected": false,
"text": "$page"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3720/"
] |
40,161
|
<p>Does C# have built-in support for parsing strings of page numbers? By page numbers, I mean the format you might enter into a print dialog that's a mixture of comma and dash-delimited.</p>
<p>Something like this:</p>
<pre><code>1,3,5-10,12
</code></pre>
<p>What would be really nice is a solution that gave me back some kind of list of all page numbers represented by the string. In the above example, getting a list back like this would be nice:</p>
<pre><code>1,3,5,6,7,8,9,10,12
</code></pre>
<p>I just want to avoid rolling my own if there's an easy way to do it.</p>
|
[
{
"answer_id": 40180,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 6,
"selected": true,
"text": "foreach( string s in \"1,3,5-10,12\".Split(',') ) \n{\n // try and get the number\n int num;\n if( int.TryParse( s, out num ) )\n {\n yield return num;\n continue; // skip the rest\n }\n\n // otherwise we might have a range\n // split on the range delimiter\n string[] subs = s.Split('-');\n int start, end;\n\n // now see if we can parse a start and end\n if( subs.Length > 1 &&\n int.TryParse(subs[0], out start) &&\n int.TryParse(subs[1], out end) &&\n end >= start )\n {\n // create a range between the two values\n int rangeLength = end - start + 1;\n foreach(int i in Enumerable.Range(start, rangeLength))\n {\n yield return i;\n }\n }\n}\n"
},
{
"answer_id": 40207,
"author": "ljs",
"author_id": 3394,
"author_profile": "https://Stackoverflow.com/users/3394",
"pm_score": 3,
"selected": false,
"text": "public List<int> parsePageNumbers(string input) {\n if (string.IsNullOrEmpty(input))\n throw new InvalidOperationException(\"Input string is empty.\");\n\n var pageNos = input.Split(',');\n\n var ret = new List<int>();\n foreach(string pageString in pageNos) {\n if (pageString.Contains(\"-\")) {\n parsePageRange(ret, pageString);\n } else {\n ret.Add(parsePageNumber(pageString));\n }\n }\n\n ret.Sort();\n return ret.Distinct().ToList();\n}\n\nprivate int parsePageNumber(string pageString) {\n int ret;\n\n if (!int.TryParse(pageString, out ret)) {\n throw new InvalidOperationException(\n string.Format(\"Page number '{0}' is not valid.\", pageString));\n }\n\n return ret;\n}\n\nprivate void parsePageRange(List<int> pageNumbers, string pageNo) {\n var pageRange = pageNo.Split('-');\n\n if (pageRange.Length != 2)\n throw new InvalidOperationException(\n string.Format(\"Page range '{0}' is not valid.\", pageNo));\n\n int startPage = parsePageNumber(pageRange[0]),\n endPage = parsePageNumber(pageRange[1]);\n\n if (startPage > endPage) {\n throw new InvalidOperationException(\n string.Format(\"Page number {0} is greater than page number {1}\" +\n \" in page range '{2}'\", startPage, endPage, pageNo));\n }\n\n pageNumbers.AddRange(Enumerable.Range(startPage, endPage - startPage + 1));\n}\n"
},
{
"answer_id": 40384,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 2,
"selected": false,
"text": "1 single number\n1-5 range\n-5 range from (firstpage) up to 5\n5- range from 5 up to (lastpage)\n.. can use .. instead of -\n;, can use both semicolon, comma, and space, as separators\n"
},
{
"answer_id": 205166,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " /// <summary>\n /// Parses a string representing a range of values into a sequence of integers.\n /// </summary>\n /// <param name=\"s\">String to parse</param>\n /// <param name=\"minValue\">Minimum value for open range specifier</param>\n /// <param name=\"maxValue\">Maximum value for open range specifier</param>\n /// <returns>An enumerable sequence of integers</returns>\n /// <remarks>\n /// The range is specified as a string in the following forms or combination thereof:\n /// 5 single value\n /// 1,2,3,4,5 sequence of values\n /// 1-5 closed range\n /// -5 open range (converted to a sequence from minValue to 5)\n /// 1- open range (converted to a sequence from 1 to maxValue)\n /// \n /// The value delimiter can be either ',' or ';' and the range separator can be\n /// either '-' or ':'. Whitespace is permitted at any point in the input.\n /// \n /// Any elements of the sequence that contain non-digit, non-whitespace, or non-separator\n /// characters or that are empty are ignored and not returned in the output sequence.\n /// </remarks>\n public static IEnumerable<int> ParseRange2(this string s, int minValue, int maxValue) {\n const string pattern = @\"(?:^|(?<=[,;])) # match must begin with start of string or delim, where delim is , or ;\n \\s*( # leading whitespace\n (?<from>\\d*)\\s*(?:-|:)\\s*(?<to>\\d+) # capture 'from <sep> to' or '<sep> to', where <sep> is - or :\n | # or\n (?<from>\\d+)\\s*(?:-|:)\\s*(?<to>\\d*) # capture 'from <sep> to' or 'from <sep>', where <sep> is - or :\n | # or\n (?<num>\\d+) # capture lone number\n )\\s* # trailing whitespace\n (?:(?=[,;\\b])|$) # match must end with end of string or delim, where delim is , or ;\";\n\n Regex regx = new Regex(pattern, RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);\n\n foreach (Match m in regx.Matches(s)) {\n Group gpNum = m.Groups[\"num\"];\n if (gpNum.Success) {\n yield return int.Parse(gpNum.Value);\n\n } else {\n Group gpFrom = m.Groups[\"from\"];\n Group gpTo = m.Groups[\"to\"];\n if (gpFrom.Success || gpTo.Success) {\n int from = (gpFrom.Success && gpFrom.Value.Length > 0 ? int.Parse(gpFrom.Value) : minValue);\n int to = (gpTo.Success && gpTo.Value.Length > 0 ? int.Parse(gpTo.Value) : maxValue);\n\n for (int i = from; i <= to; i++) {\n yield return i;\n }\n }\n }\n }\n }\n"
},
{
"answer_id": 25334542,
"author": "Chris Fazzio",
"author_id": 1274209,
"author_profile": "https://Stackoverflow.com/users/1274209",
"pm_score": 3,
"selected": false,
"text": " private int[] ParseRange(string ranges)\n { \n string[] groups = ranges.Split(',');\n return groups.SelectMany(t => GetRangeNumbers(t)).ToArray();\n }\n\n private int[] GetRangeNumbers(string range)\n {\n //string justNumbers = new String(text.Where(Char.IsDigit).ToArray());\n\n int[] RangeNums = range\n .Split('-')\n .Select(t => new String(t.Where(Char.IsDigit).ToArray())) // Digits Only\n .Where(t => !string.IsNullOrWhiteSpace(t)) // Only if has a value\n .Select(t => int.Parse(t)) // digit to int\n .ToArray();\n return RangeNums.Length.Equals(2) ? Enumerable.Range(RangeNums.Min(), (RangeNums.Max() + 1) - RangeNums.Min()).ToArray() : RangeNums;\n }\n"
},
{
"answer_id": 33666576,
"author": "w.b",
"author_id": 2720372,
"author_profile": "https://Stackoverflow.com/users/2720372",
"pm_score": 0,
"selected": false,
"text": "static IEnumerable<string> ParseRange(string str)\n{\n var numbers = str.Split(',');\n\n foreach (var n in numbers)\n {\n if (!n.Contains(\"-\")) \n yield return n;\n else\n {\n string startStr = String.Join(\"\", n.TakeWhile(c => c != '-'));\n int startInt = Int32.Parse(startStr);\n\n string endStr = String.Join(\"\", n.Reverse().TakeWhile(c => c != '-').Reverse());\n int endInt = Int32.Parse(endStr);\n\n var range = Enumerable.Range(startInt, endInt - startInt + 1)\n .Select(num => num.ToString());\n\n foreach (var s in range)\n yield return s;\n }\n }\n}\n"
},
{
"answer_id": 33667542,
"author": "bradgonesurfing",
"author_id": 158285,
"author_profile": "https://Stackoverflow.com/users/158285",
"pm_score": 2,
"selected": false,
"text": " [Fact]\n public void ShouldBeAbleToParseRanges()\n {\n RangeParser.Parse( \"1\" ).Should().BeEquivalentTo( 1 );\n RangeParser.Parse( \"-1..2\" ).Should().BeEquivalentTo( -1,0,1,2 );\n\n RangeParser.Parse( \"-1..2 \" ).Should().BeEquivalentTo( -1,0,1,2 );\n RangeParser.Parse( \"-1..2 5\" ).Should().BeEquivalentTo( -1,0,1,2,5 );\n RangeParser.Parse( \" -1 .. 2 5\" ).Should().BeEquivalentTo( -1,0,1,2,5 );\n }\n"
},
{
"answer_id": 43974476,
"author": "jdweng",
"author_id": 5015238,
"author_profile": "https://Stackoverflow.com/users/5015238",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\nnamespace ConsoleApplication1\n{\n class Program\n {\n static void Main(string[] args)\n {\n string[] inputs = {\n \"001-005/015\",\n \"009/015\"\n };\n\n foreach (string input in inputs)\n {\n List<int> numbers = new List<int>();\n string[] strNums = input.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);\n foreach (string strNum in strNums)\n {\n if (strNum.Contains(\"-\"))\n {\n int startNum = int.Parse(strNum.Substring(0, strNum.IndexOf(\"-\")));\n int endNum = int.Parse(strNum.Substring(strNum.IndexOf(\"-\") + 1));\n for (int i = startNum; i <= endNum; i++)\n {\n numbers.Add(i);\n }\n }\n else\n numbers.Add(int.Parse(strNum));\n }\n Console.WriteLine(string.Join(\",\", numbers.Select(x => x.ToString())));\n }\n Console.ReadLine();\n\n }\n }\n}\n"
},
{
"answer_id": 43974770,
"author": "fubo",
"author_id": 1315444,
"author_profile": "https://Stackoverflow.com/users/1315444",
"pm_score": 1,
"selected": false,
"text": "Split"
},
{
"answer_id": 51023394,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " public static List<int> pageRangeToList(string pageRg, int Nmax = 0)\n{\n List<int> ls = new List<int>();\n int lb,ub,i;\n foreach (string ss in pageRg.Split(','))\n {\n if(int.TryParse(ss,out lb)){\n ls.Add(Math.Abs(lb));\n } else {\n var subls = ss.Split('-').ToList();\n lb = (int.TryParse(subls[0],out i)) ? i : 0;\n ub = (int.TryParse(subls[1],out i)) ? i : Nmax;\n ub = ub > 0 ? ub : lb; // if ub=0, take 1 value of lb\n for(i=0;i<=Math.Abs(ub-lb);i++) \n ls.Add(lb<ub? i+lb : lb-i);\n }\n }\n Nmax = Nmax > 0 ? Nmax : ls.Max(); // real Nmax\n return ls.Where(s => s>0 && s<=Nmax).ToList();\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] |
40,169
|
<p>I infrequently (monthly/quarterly) generate hundreds of Crystal Reports reports using Microsoft SQL Server 2005 database views. Are those views wasting CPU cycles and RAM during all the time that I am not reading from them? Should I instead use stored procedures, temporary tables, or short-lived normal tables since I rarely read from my views?</p>
<p>I'm not a DBA so I don't know what's going on behind the scenes inside the database server.</p>
<p>Is it possible to have too many database views? What's considered best practice?</p>
|
[
{
"answer_id": 40191,
"author": "Sara Chipps",
"author_id": 4140,
"author_profile": "https://Stackoverflow.com/users/4140",
"pm_score": 2,
"selected": false,
"text": "Select * from customers where paid = 1\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
40,193
|
<p>I've got to get a directory listing that contains about 2 million files, but when I do an <code>ls</code> command on it nothing comes back. I've waited 3 hours. I've tried <code>ls | tee directory.txt</code>, but that seems to hang forever. </p>
<p>I assume the server is doing a lot of inode sorting. Is there any way to speed up the <code>ls</code> command to just get a directory listing of filenames? I don't care about size, dates, permission or the like at this time.</p>
|
[
{
"answer_id": 40195,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 1,
"selected": false,
"text": "find ./ -type f"
},
{
"answer_id": 40200,
"author": "Ryan Ahearn",
"author_id": 75,
"author_profile": "https://Stackoverflow.com/users/75",
"pm_score": 4,
"selected": false,
"text": "find . -type f -maxdepth 1\n"
},
{
"answer_id": 40201,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 1,
"selected": false,
"text": "alias ls\n"
},
{
"answer_id": 40202,
"author": "Eric",
"author_id": 4277,
"author_profile": "https://Stackoverflow.com/users/4277",
"pm_score": 3,
"selected": false,
"text": "ls > myls.txt &\n"
},
{
"answer_id": 40204,
"author": "wbkang",
"author_id": 2710,
"author_profile": "https://Stackoverflow.com/users/2710",
"pm_score": 2,
"selected": false,
"text": "\\ls\n"
},
{
"answer_id": 40206,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 6,
"selected": false,
"text": "ls -U\n"
},
{
"answer_id": 40433,
"author": "tonylo",
"author_id": 4071,
"author_profile": "https://Stackoverflow.com/users/4071",
"pm_score": 0,
"selected": false,
"text": "ff"
},
{
"answer_id": 40496,
"author": "Benedikt Waldvogel",
"author_id": 4308,
"author_profile": "https://Stackoverflow.com/users/4308",
"pm_score": 2,
"selected": false,
"text": "$strace ls\n"
},
{
"answer_id": 41088,
"author": "jj33",
"author_id": 430,
"author_profile": "https://Stackoverflow.com/users/430",
"pm_score": -1,
"selected": false,
"text": "echo *\n"
},
{
"answer_id": 75731,
"author": "Jim",
"author_id": 12419,
"author_profile": "https://Stackoverflow.com/users/12419",
"pm_score": -1,
"selected": false,
"text": "ls | xargs\n"
},
{
"answer_id": 1650700,
"author": "Rich Homolka",
"author_id": 128439,
"author_profile": "https://Stackoverflow.com/users/128439",
"pm_score": 1,
"selected": false,
"text": "ls -1"
},
{
"answer_id": 3619973,
"author": "telent",
"author_id": 419653,
"author_profile": "https://Stackoverflow.com/users/419653",
"pm_score": 2,
"selected": false,
"text": "find"
},
{
"answer_id": 18464192,
"author": "plasmafire",
"author_id": 2721409,
"author_profile": "https://Stackoverflow.com/users/2721409",
"pm_score": 3,
"selected": false,
"text": "ls -1 -f"
},
{
"answer_id": 26295448,
"author": "Pouya",
"author_id": 4083267,
"author_profile": "https://Stackoverflow.com/users/4083267",
"pm_score": 1,
"selected": false,
"text": "ls -U\n"
},
{
"answer_id": 26691147,
"author": "Limalski",
"author_id": 4205706,
"author_profile": "https://Stackoverflow.com/users/4205706",
"pm_score": 3,
"selected": false,
"text": "ls -1 -f \n"
},
{
"answer_id": 26699902,
"author": "Kannan Mohan",
"author_id": 1198887,
"author_profile": "https://Stackoverflow.com/users/1198887",
"pm_score": 3,
"selected": false,
"text": "$ time tar cvf /dev/null . &> /tmp/file-count\n\nreal 37m16.553s\nuser 0m11.525s\nsys 0m41.291s\n\n------------------------------------------------------\n\n$ time echo ./* &> /tmp/file-count\n\nreal 0m50.808s\nuser 0m49.291s\nsys 0m1.404s\n\n------------------------------------------------------\n\n$ time ls &> /tmp/file-count\n\nreal 0m42.167s\nuser 0m40.323s\nsys 0m1.648s\n\n------------------------------------------------------\n\n$ time find . &> /tmp/file-count\n\nreal 0m2.738s\nuser 0m1.044s\nsys 0m1.684s\n\n------------------------------------------------------\n\n$ time ls -U &> /tmp/file-count\n\nreal 0m2.494s\nuser 0m0.848s\nsys 0m1.452s\n\n\n------------------------------------------------------\n\n$ time ls -f &> /tmp/file-count\n\nreal 0m2.313s\nuser 0m0.856s\nsys 0m1.448s\n\n------------------------------------------------------\n"
},
{
"answer_id": 33785526,
"author": "stu",
"author_id": 12386,
"author_profile": "https://Stackoverflow.com/users/12386",
"pm_score": 4,
"selected": false,
"text": "ls -1U\n"
},
{
"answer_id": 61469784,
"author": "blacksite",
"author_id": 5015569,
"author_profile": "https://Stackoverflow.com/users/5015569",
"pm_score": 0,
"selected": false,
"text": "find . -type f -maxdepth 1 | sort | tail -n 1"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1536194/"
] |
40,211
|
<p>I have a flag enum below.</p>
<pre><code>[Flags]
public enum FlagTest
{
None = 0x0,
Flag1 = 0x1,
Flag2 = 0x2,
Flag3 = 0x4
}
</code></pre>
<p>I cannot make the if statement evaluate to true.</p>
<pre><code>FlagTest testItem = FlagTest.Flag1 | FlagTest.Flag2;
if (testItem == FlagTest.Flag1)
{
// Do something,
// however This is never true.
}
</code></pre>
<p>How can I make this true?</p>
|
[
{
"answer_id": 40213,
"author": "17 of 26",
"author_id": 2284,
"author_profile": "https://Stackoverflow.com/users/2284",
"pm_score": 3,
"selected": false,
"text": "if ((testItem & FlagTest.Flag1) == FlagTest.Flag1)\n{\n // Do something,\n // however This is never true.\n}\n"
},
{
"answer_id": 40217,
"author": "Scott Nichols",
"author_id": 4299,
"author_profile": "https://Stackoverflow.com/users/4299",
"pm_score": 8,
"selected": false,
"text": "if ((testItem & FlagTest.Flag1) == FlagTest.Flag1)\n{\n // Do something\n}\n"
},
{
"answer_id": 40218,
"author": "Damian",
"author_id": 3390,
"author_profile": "https://Stackoverflow.com/users/3390",
"pm_score": 3,
"selected": false,
"text": "if((testItem & FlagTest.Flag1) == FlagTest.Flag1) \n{\n...\n}\n"
},
{
"answer_id": 40221,
"author": "OwenP",
"author_id": 2547,
"author_profile": "https://Stackoverflow.com/users/2547",
"pm_score": 2,
"selected": false,
"text": "\nif ((testItem & FlagTest.Flag1) == FlagTest.Flag1)\n{\n // do something\n}\n"
},
{
"answer_id": 40239,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 4,
"selected": false,
"text": "public static bool IsSet( this Enum input, Enum matchTo )\n{\n return ( Convert.ToUInt32( input ) & Convert.ToUInt32( matchTo ) ) != 0;\n}\n"
},
{
"answer_id": 40268,
"author": "Martin Clarke",
"author_id": 2422,
"author_profile": "https://Stackoverflow.com/users/2422",
"pm_score": 3,
"selected": false,
"text": "public class FlagTestCompare\n{\n public static bool Compare(this FlagTest myFlag, FlagTest condition)\n {\n return ((myFlag & condition) == condition);\n }\n}\n"
},
{
"answer_id": 1769763,
"author": "Phil Devaney",
"author_id": 88468,
"author_profile": "https://Stackoverflow.com/users/88468",
"pm_score": 9,
"selected": true,
"text": "if ( testItem.HasFlag( FlagTest.Flag1 ) )\n{\n // Do Stuff\n}\n"
},
{
"answer_id": 1769814,
"author": "Sekhat",
"author_id": 1610,
"author_profile": "https://Stackoverflow.com/users/1610",
"pm_score": 6,
"selected": false,
"text": "if ((testItem & FlagTest.Flag1) == FlagTest.Flag1)\n{\n // Do stuff.\n}\n"
},
{
"answer_id": 3412480,
"author": "Leonid",
"author_id": 372909,
"author_profile": "https://Stackoverflow.com/users/372909",
"pm_score": 4,
"selected": false,
"text": "[Flags]\npublic enum LevelOfDetail\n{\n [EnumMember(Value = \"FullInfo\")]\n FullInfo=0,\n [EnumMember(Value = \"BusinessData\")]\n BusinessData=1\n}\n"
},
{
"answer_id": 7164314,
"author": "Chuck Dee",
"author_id": 275594,
"author_profile": "https://Stackoverflow.com/users/275594",
"pm_score": 5,
"selected": false,
"text": "[Flags]\npublic enum TestFlags\n{\n One = 1,\n Two = 2,\n Three = 4,\n Four = 8,\n Five = 16,\n Six = 32,\n Seven = 64,\n Eight = 128,\n Nine = 256,\n Ten = 512\n}\n\n\nclass Program\n{\n static void Main(string[] args)\n {\n TestFlags f = TestFlags.Five; /* or any other enum */\n bool result = false;\n\n Stopwatch s = Stopwatch.StartNew();\n for (int i = 0; i < 10000000; i++)\n {\n result |= f.HasFlag(TestFlags.Three);\n }\n s.Stop();\n Console.WriteLine(s.ElapsedMilliseconds); // *4793 ms*\n\n s.Restart();\n for (int i = 0; i < 10000000; i++)\n {\n result |= (f & TestFlags.Three) != 0;\n }\n s.Stop();\n Console.WriteLine(s.ElapsedMilliseconds); // *27 ms* \n\n Console.ReadLine();\n }\n}\n"
},
{
"answer_id": 33811816,
"author": "Waleed A.K.",
"author_id": 347374,
"author_profile": "https://Stackoverflow.com/users/347374",
"pm_score": 1,
"selected": false,
"text": "if((testItem & (FlagTest.Flag1 | FlagTest.Flag2 ))!=0){\n//..\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2469/"
] |
40,244
|
<p>Assume that I have programs <code>P0</code>, <code>P1</code>, ...<code>P(n-1)</code> for some <code>n > 0</code>. How can I easily redirect the output of program <code>Pi</code> to program <code>P(i+1 mod n)</code> for all <code>i</code> (<code>0 <= i < n</code>)?</p>
<p>For example, let's say I have a program <code>square</code>, which repeatedly reads a number and than prints the square of that number, and a program <code>calc</code>, which sometimes prints a number after which it expects to be able to read the square of it. How do I connect these programs such that whenever <code>calc</code> prints a number, <code>square</code> squares it returns it to <code>calc</code>?</p>
<p>Edit: I should probably clarify what I mean with "easily". The named pipe/fifo solution is one that indeed works (and I have used in the past), but it actually requires quite a bit of work to do properly if you compare it with using a bash pipe. (You need to get a not yet existing filename, make a pipe with that name, run the "pipe loop", clean up the named pipe.) Imagine you could no longer write <code>prog1 | prog2</code> and would always have to use named pipes to connect programs.</p>
<p>I'm looking for something that is almost as easy as writing a "normal" pipe. For instance something like <code>{ prog1 | prog2 } >&0</code> would be great.</p>
|
[
{
"answer_id": 40644,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 4,
"selected": false,
"text": "$ mkfifo outside\n$ <outside calc | square >outside &\n$ echo \"1\" >outside ## Trigger the loop to start\n"
},
{
"answer_id": 43332,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 5,
"selected": false,
"text": "stdout"
},
{
"answer_id": 464638,
"author": "Fritz G. Mehner",
"author_id": 57457,
"author_profile": "https://Stackoverflow.com/users/57457",
"pm_score": -1,
"selected": false,
"text": "function square ()\n{\n read n\n echo $((n*n))\n} # ---------- end of function square ----------\n\ndeclare -a commands=( 'echo 4' 'square' 'square' 'square' )\n\n#-------------------------------------------------------------------------------\n# build the command stack using pipes\n#-------------------------------------------------------------------------------\ndeclare stack=${commands[0]}\n\nfor (( COUNTER=1; COUNTER<${#commands[@]}; COUNTER++ )); do\n stack=\"${stack} | ${commands[${COUNTER}]}\"\ndone\n\n#-------------------------------------------------------------------------------\n# run the command stack\n#-------------------------------------------------------------------------------\neval \"$stack\" \n"
},
{
"answer_id": 29053837,
"author": "Andreas Florath",
"author_id": 1247301,
"author_profile": "https://Stackoverflow.com/users/1247301",
"pm_score": 2,
"selected": false,
"text": "function square() {\n # square numbers\n\n read j # receive first \"request\"\n while [ \"$j\" != \"\" ]; do\n let jj=$j*$j\n echo \"square($j) = $jj\" >&2 # debug message\n\n echo $jj # send square\n\n read j # receive next \"request\"\n done\n}\n\nsquare $@\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4285/"
] |
40,264
|
<p>Let's say you have a class called Customer, which contains the following fields:</p>
<ul>
<li>UserName</li>
<li>Email</li>
<li>First Name</li>
<li>Last Name</li>
</ul>
<p>Let's also say that according to your business logic, all Customer objects must have these four properties defined.</p>
<p>Now, we can do this pretty easily by forcing the constructor to specify each of these properties. But it's pretty easy to see how this can spiral out of control when you are forced to add more required fields to the Customer object. </p>
<p>I've seen classes that take in 20+ arguments into their constructor and it's just a pain to use them. But, alternatively, if you don't require these fields you run into the risk of having undefined information, or worse, object referencing errors if you rely on the calling code to specify these properties.</p>
<p>Are there any alternatives to this or do you you just have to decide whether X amount of constructor arguments is too many for you to live with?</p>
|
[
{
"answer_id": 40284,
"author": "Brian Warshaw",
"author_id": 1344,
"author_profile": "https://Stackoverflow.com/users/1344",
"pm_score": 1,
"selected": false,
"text": "public function doSomethingWith($this = val1, $this = val2, $this = val3)"
},
{
"answer_id": 40289,
"author": "helloandre",
"author_id": 50,
"author_profile": "https://Stackoverflow.com/users/50",
"pm_score": 2,
"selected": false,
"text": "public static void setEmail(String newEmail){\n this.email = newEmail;\n}\n\npublic static String getEmail(){\n return this.email;\n}\n"
},
{
"answer_id": 40324,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 8,
"selected": true,
"text": "public class CustomerBuilder {\n String surname;\n String firstName;\n String ssn;\n public static CustomerBuilder customer() {\n return new CustomerBuilder();\n }\n public CustomerBuilder withSurname(String surname) {\n this.surname = surname; \n return this; \n }\n public CustomerBuilder withFirstName(String firstName) {\n this.firstName = firstName;\n return this; \n }\n public CustomerBuilder withSsn(String ssn) {\n this.ssn = ssn; \n return this; \n }\n // client doesn't get to instantiate Customer directly\n public Customer build() {\n return new Customer(this); \n }\n}\n\npublic class Customer {\n private final String firstName;\n private final String surname;\n private final String ssn;\n\n Customer(CustomerBuilder builder) {\n if (builder.firstName == null) throw new NullPointerException(\"firstName\");\n if (builder.surname == null) throw new NullPointerException(\"surname\");\n if (builder.ssn == null) throw new NullPointerException(\"ssn\");\n this.firstName = builder.firstName;\n this.surname = builder.surname;\n this.ssn = builder.ssn;\n }\n\n public String getFirstName() { return firstName; }\n public String getSurname() { return surname; }\n public String getSsn() { return ssn; } \n}\n"
},
{
"answer_id": 40364,
"author": "Marcio Aguiar",
"author_id": 4213,
"author_profile": "https://Stackoverflow.com/users/4213",
"pm_score": 4,
"selected": false,
"text": " public class NutritionFacts { \n private final int servingSize; \n private final int servings; \n private final int calories; \n private final int fat; \n private final int sodium; \n private final int carbohydrate; \n\n public static class Builder { \n // required parameters \n private final int servingSize; \n private final int servings; \n\n // optional parameters \n private int calories = 0; \n private int fat = 0; \n private int carbohydrate = 0; \n private int sodium = 0; \n\n public Builder(int servingSize, int servings) { \n this.servingSize = servingSize; \n this.servings = servings; \n } \n\n public Builder calories(int val) \n { calories = val; return this; } \n public Builder fat(int val) \n { fat = val; return this; } \n public Builder carbohydrate(int val) \n { carbohydrate = val; return this; } \n public Builder sodium(int val) \n { sodium = val; return this; } \n\n public NutritionFacts build() { \n return new NutritionFacts(this); \n } \n } \n\n private NutritionFacts(Builder builder) { \n servingSize = builder.servingSize; \n servings = builder.servings; \n calories = builder.calories; \n fat = builder.fat; \n soduim = builder.sodium; \n carbohydrate = builder.carbohydrate; \n } \n} \n"
},
{
"answer_id": 40371,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 2,
"selected": false,
"text": "ContactInfo cinfos = new ContactInfo[] {\n new ContactInfo(\"home\", \"+123456789\", \"123 ABC Avenue\"),\n new ContactInfo(\"biz\", \"+987654321\", \"789 ZYX Avenue\")\n};\n\nCustomer c = new Customer(\"john\", \"doe\", cinfos);\n"
},
{
"answer_id": 58661084,
"author": "rrswa",
"author_id": 3076593,
"author_profile": "https://Stackoverflow.com/users/3076593",
"pm_score": 1,
"selected": false,
"text": "class Customer {\n private string name;\n private int age;\n private string email;\n\n Customer(string name, int age, string email) {\n this.name = name;\n this.age = age;\n this.email = email;\n }\n}\n\nclass John : Customer {\n John() : base(\"John\", 20, \"John@email.com\") { \n\n }\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1574/"
] |
40,269
|
<p>Is there an easy way to find the storage card's path on a Windows Mobile device
when there is a storage card and a bluetooth ftp connection?</p>
|
[
{
"answer_id": 661129,
"author": "Joel ",
"author_id": 79853,
"author_profile": "https://Stackoverflow.com/users/79853",
"pm_score": 4,
"selected": true,
"text": "using System;\nusing System.IO;\nusing System.Runtime.InteropServices;\n\nnamespace StorageCardInfo\n{\n class Program\n {\n const ulong Megabyte = 1048576;\n const ulong Gigabyte = 1073741824;\n\n [DllImport(\"CoreDLL\")]\n static extern int GetDiskFreeSpaceEx(\n string DirectoryName,\n out ulong lpFreeBytesAvailableToCaller,\n out ulong lpTotalNumberOfBytes,\n out ulong lpTotalNumberOfFreeBytes \n );\n\n static void Main(string[] args)\n {\n DirectoryInfo root = new DirectoryInfo(\"\\\\\");\n DirectoryInfo[] directoryList = root.GetDirectories();\n ulong FreeBytesAvailable;\n ulong TotalCapacity;\n ulong TotalFreeBytes;\n\n for (int i = 0; i < directoryList.Length; ++i)\n {\n if ((directoryList.Attributes & FileAttributes.Temporary) != 0)\n {\n GetDiskFreeSpaceEx(directoryList.FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);\n Console.Out.WriteLine(\"Storage card name: {0}\", directoryList.FullName);\n Console.Out.WriteLine(\"Available Bytes : {0}\", FreeBytesAvailable);\n Console.Out.WriteLine(\"Total Capacity : {0}\", TotalCapacity);\n Console.Out.WriteLine(\"Total Free Bytes : {0}\", TotalFreeBytes);\n }\n }\n }\n}\n"
},
{
"answer_id": 698076,
"author": "John Sibly",
"author_id": 1078,
"author_profile": "https://Stackoverflow.com/users/1078",
"pm_score": 3,
"selected": false,
"text": "using System;\nusing System.Runtime.InteropServices;\n\nnamespace RemovableStorageTest\n{\n class Program\n {\n static void Main(string[] args)\n {\n string removableDirectory = GetRemovableStorageDirectory();\n if (removableDirectory != null)\n {\n Console.WriteLine(removableDirectory);\n }\n else\n {\n Console.WriteLine(\"No removable drive found\");\n }\n }\n\n public static string GetRemovableStorageDirectory()\n {\n string removableStorageDirectory = null;\n\n WIN32_FIND_DATA findData = new WIN32_FIND_DATA();\n IntPtr handle = IntPtr.Zero;\n\n handle = FindFirstFlashCard(ref findData);\n\n if (handle != INVALID_HANDLE_VALUE)\n {\n do\n {\n if (!string.IsNullOrEmpty(findData.cFileName))\n {\n removableStorageDirectory = findData.cFileName;\n break;\n }\n }\n while (FindNextFlashCard(handle, ref findData));\n FindClose(handle);\n }\n\n return removableStorageDirectory;\n }\n\n public static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);\n\n // The CharSet must match the CharSet of the corresponding PInvoke signature\n [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n public struct WIN32_FIND_DATA\n {\n public int dwFileAttributes;\n public FILETIME ftCreationTime;\n public FILETIME ftLastAccessTime;\n public FILETIME ftLastWriteTime;\n public int nFileSizeHigh;\n public int nFileSizeLow;\n public int dwOID;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n public string cFileName;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]\n public string cAlternateFileName;\n }\n\n [StructLayout(LayoutKind.Sequential)]\n public struct FILETIME\n {\n public int dwLowDateTime;\n public int dwHighDateTime;\n };\n\n [DllImport(\"note_prj\", EntryPoint = \"FindFirstFlashCard\")]\n public extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);\n\n [DllImport(\"note_prj\", EntryPoint = \"FindNextFlashCard\")]\n [return: MarshalAs(UnmanagedType.Bool)]\n public extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);\n\n [DllImport(\"coredll\")]\n public static extern bool FindClose(IntPtr hFindFile);\n }\n}\n"
},
{
"answer_id": 840425,
"author": "Tristan Warner-Smith",
"author_id": 29553,
"author_profile": "https://Stackoverflow.com/users/29553",
"pm_score": 2,
"selected": false,
"text": "//codesnippet:06EE3DE0-D469-44DD-A15F-D8AF629E4E03\npublic string GetStorageCardFolder()\n{\n string storageCardFolder = string.Empty;\n foreach (string directory in Directory.GetDirectories(\"\\\\\"))\n {\n DirectoryInfo dirInfo = new DirectoryInfo(directory);\n\n //Storage cards have temporary attributes do a bitwise check.\n //http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=612136&SiteID=1\n if ((dirInfo.Attributes & FileAttributes.Temporary) == FileAttributes.Temporary)\n storageCardFolder = directory;\n }\n\n return storageCardFolder;\n}\n"
},
{
"answer_id": 2027247,
"author": "lmb_nl",
"author_id": 246350,
"author_profile": "https://Stackoverflow.com/users/246350",
"pm_score": 2,
"selected": false,
"text": " WIN32_FIND_DATA cardinfo;\nHANDLE card = FindFirstFlashCard(&cardinfo);\nif (card != INVALID_HANDLE_VALUE)\n{\n TCHAR existFile[MAX_PATH];\n\n wprintf(_T(\"found : %s\\n\"), cardinfo.cFileName);\n\n while(FindNextFlashCard(card, &cardinfo))\n {\n wprintf(_T(\"found : %s\\n\"), cardinfo.cFileName);\n }\n}\nFindClose(card);\n"
},
{
"answer_id": 7272591,
"author": "qwlice",
"author_id": 507127,
"author_profile": "https://Stackoverflow.com/users/507127",
"pm_score": 2,
"selected": false,
"text": " //\n // the storage card is a flash drive mounted as a directory in the root folder \n // of the smart device\n //\n // on english windows mobile systems the storage card is mounted in the directory \"/Storage Card\", \n // if that directory already exists then it's mounted in \"/Storage Card2\" and so on\n //\n // the regional name of the mount base dir of the storage card can be found in\n // the registry at [HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles\\SDMemory\\Folder]\n // \n // in order to find the path of the storage card we look for the flash drive that starts \n // with the base name\n //\n\n public class StorageCard\n {\n private StorageCard()\n {\n }\n\n public static List<string> GetMountDirs()\n {\n string key = @\"HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles\\SDMemory\";\n string storageCardBaseName = Registry.GetValue(key, \"Folder\", \"Storage Card\") as String;\n List<string> storageCards = new List<string>();\n foreach (string flashCard in GetFlashCardMountDirs())\n {\n string path = flashCard.Trim();\n if (path.StartsWith(storageCardBaseName))\n {\n storageCards.Add(path);\n }\n }\n return storageCards;\n }\n\n private static List<string> GetFlashCardMountDirs()\n {\n List<string> storages = new List<string>();\n\n WIN32_FIND_DATA findData = new WIN32_FIND_DATA();\n IntPtr handle = IntPtr.Zero;\n\n handle = FindFirstFlashCard(ref findData);\n\n if (handle != INVALID_HANDLE_VALUE)\n {\n do\n {\n if (!string.IsNullOrEmpty(findData.cFileName))\n {\n storages.Add(findData.cFileName);\n storages.Add(findData.cAlternateFileName);\n }\n }\n while (FindNextFlashCard(handle, ref findData));\n FindClose(handle);\n }\n\n return storages;\n }\n\n private static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1); \n\n [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n private struct WIN32_FIND_DATA\n {\n public int dwFileAttributes;\n public FILETIME ftCreationTime;\n public FILETIME ftLastAccessTime;\n public FILETIME ftLastWriteTime;\n public int nFileSizeHigh;\n public int nFileSizeLow;\n public int dwOID;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n public string cFileName;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]\n public string cAlternateFileName;\n }\n\n [StructLayout(LayoutKind.Sequential)]\n private struct FILETIME\n {\n public int dwLowDateTime;\n public int dwHighDateTime;\n };\n\n [DllImport(\"note_prj\", EntryPoint = \"FindFirstFlashCard\")]\n private extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);\n\n [DllImport(\"note_prj\", EntryPoint = \"FindNextFlashCard\")]\n [return: MarshalAs(UnmanagedType.Bool)]\n private extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);\n\n [DllImport(\"coredll\")]\n private static extern bool FindClose(IntPtr hFindFile);\n }\n"
},
{
"answer_id": 12400572,
"author": "Lief",
"author_id": 778579,
"author_profile": "https://Stackoverflow.com/users/778579",
"pm_score": 2,
"selected": false,
"text": "public class StorageCardFinder\n{\n public static List<string> GetMountDirs()\n {\n //get default sd card folder name\n string key = @\"HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles\";\n RegistryKey profiles = Registry.LocalMachine.OpenSubKey(@\"System\\StorageManager\\Profiles\");\n string sdprofilename = profiles.GetSubKeyNames().FirstOrDefault(k => k.Contains(\"SD\"));\n if (sdprofilename == null)\n return new List<string>();\n\n key += \"\\\\\" + sdprofilename;\n string storageCardBaseName = Registry.GetValue(key, \"Folder\", \"Storage Card\") as String;\n if (storageCardBaseName == null)\n return new List<string>();\n\n //find storage card\n List<string> cardDirectories = GetFlashCardMountDirs();\n\n List<string> storageCards = new List<string>();\n foreach (string flashCard in GetFlashCardMountDirs())\n {\n string path = flashCard.Trim();\n if (path.StartsWith(storageCardBaseName))\n {\n storageCards.Add(\"\\\\\" + path);\n }\n }\n return storageCards;\n }\n\n private static List<string> GetFlashCardMountDirs()\n {\n DirectoryInfo root = new DirectoryInfo(\"\\\\\");\n return root.GetDirectories().Where(d => (d.Attributes & FileAttributes.Temporary) != 0)\n .Select(d => d.Name).ToList();\n }\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4298/"
] |
40,273
|
<p>A client of mine has asked me to integrate a 3rd party API into their Rails app. The only problem is that the API uses SOAP. Ruby has basically dropped SOAP in favor of REST. They provide a Java adapter that apparently works with the Java-Ruby bridge, but we'd like to keep it all in Ruby, if possible. I looked into soap4r, but it seems to have a slightly bad reputation.</p>
<p>So what's the best way to integrate SOAP calls into a Rails app?</p>
|
[
{
"answer_id": 40961,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 6,
"selected": true,
"text": "soap/wsdlDriver"
},
{
"answer_id": 35152994,
"author": "Raja",
"author_id": 3999718,
"author_profile": "https://Stackoverflow.com/users/3999718",
"pm_score": 2,
"selected": false,
"text": "require 'net/http'\n\nclass MyHelper\n def initialize(server, port, username, password)\n @server = server\n @port = port\n @username = username\n @password = password\n\n puts \"Initialised My Helper using #{@server}:#{@port} username=#{@username}\"\n end\n\n\n\n def post_job(job_name)\n\n puts \"Posting job #{job_name} to update order service\"\n\n job_xml =\"<soapenv:Envelope xmlns:soapenv=\\\"http://schemas.xmlsoap.org/soap/envelope/\\\" xmlns:ns=\\\"http://test.com/Test/CreateUpdateOrders/1.0\\\">\n <soapenv:Header/>\n <soapenv:Body>\n <ns:CreateTestUpdateOrdersReq>\n <ContractGroup>ITE2</ContractGroup>\n <ProductID>topo</ProductID>\n <PublicationReference>#{job_name}</PublicationReference>\n </ns:CreateTestUpdateOrdersReq>\n </soapenv:Body>\n </soapenv:Envelope>\"\n\n @http = Net::HTTP.new(@server, @port)\n puts \"server: \" + @server + \"port : \" + @port\n request = Net::HTTP::Post.new(('/XISOAPAdapter/MessageServlet?/Test/CreateUpdateOrders/1.0'), initheader = {'Content-Type' => 'text/xml'})\n request.basic_auth(@username, @password)\n request.body = job_xml\n response = @http.request(request)\n\n puts \"request was made to server \" + @server\n\n validate_response(response, \"post_job_to_pega_updateorder job\", '200')\n\n end\n\n\n\n private \n\n def validate_response(response, operation, required_code)\n if response.code != required_code\n raise \"#{operation} operation failed. Response was [#{response.inspect} #{response.to_hash.inspect} #{response.body}]\"\n end\n end\nend\n\n/*\ntest = MyHelper.new(\"mysvr.test.test.com\",\"8102\",\"myusername\",\"mypassword\")\ntest.post_job(\"test_201601281419\")\n*/\n"
},
{
"answer_id": 37676319,
"author": "Radu Rosu",
"author_id": 6082342,
"author_profile": "https://Stackoverflow.com/users/6082342",
"pm_score": 2,
"selected": false,
"text": "@@wsdl = '<wsdl:definitions name=\"StockQuote\"\n targetNamespace=\"http://example.com/stockquote.wsdl\"\n xmlns:tns=\"http://example.com/stockquote.wsdl\"\n xmlns:xsd1=\"http://example.com/stockquote.xsd\"\n xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"\n xmlns=\"http://schemas.xmlsoap.org/wsdl/\">\n .......\n </wsdl:definitions>'\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2884/"
] |
40,302
|
<p>Let's say I'm building a data access layer for an application. Typically I have a class definition for a each kind of object that is stored in the database. Of course, the actual data access retrieves data in the form of a datareader, typed or untyped dataset, or similar, usually with the data needed to create one object per row in the results.</p>
<p>How would you go about creating your object instances in the data layer? Would have a constructor that accepts a datarow? If so, how would you make that type-safe? Or would you have your constructor list out one parameter for each field you want to instantiate, even if there could be many fields? Would you mark this constructor 'internal'?</p>
|
[
{
"answer_id": 41034,
"author": "David Basarab",
"author_id": 2469,
"author_profile": "https://Stackoverflow.com/users/2469",
"pm_score": 2,
"selected": false,
"text": "private T ObjectFromRow(DataRow row)\n{\n Type t = typeof(T);\n\n T newObj = (T)Activator.CreateInstance(t);\n\n\n System.Reflection.PropertyInfo[] properties = t.GetProperties();\n\n for (int i = 0; i < properties.Length; i++)\n {\n if (!properties[i].CanWrite)\n {\n continue;\n }\n\n if (!row.Table.Columns.Contains(properties[i].Name))\n {\n continue;\n }\n\n if (row[properties[i].Name] == DBNull.Value)\n {\n continue;\n }\n\n if (properties[i].PropertyType == typeof(string))\n {\n properties[i].SetValue(newObj, row[properties[i].Name], null);\n }\n else if (properties[i].PropertyType == typeof(double))\n {\n properties[i].SetValue(newObj, double.Parse(row[properties[i].Name].ToString()), null);\n }\n else if (properties[i].PropertyType == typeof(int))\n {\n properties[i].SetValue(newObj, int.Parse(row[properties[i].Name].ToString()), null);\n }\n else if (properties[i].PropertyType == typeof(DateTime))\n {\n properties[i].SetValue(newObj, DateTime.Parse(row[properties[i].Name].ToString()), null);\n }\n else if (properties[i].PropertyType == typeof(bool))\n {\n properties[i].SetValue(newObj, bool.Parse(row[properties[i].Name].ToString()), null);\n }\n }\n\n return newObj;\n}\n"
},
{
"answer_id": 196254,
"author": "David Robbins",
"author_id": 19799,
"author_profile": "https://Stackoverflow.com/users/19799",
"pm_score": 1,
"selected": false,
"text": "Simple Select with string columns\n\n int records = new Select(\"productID\").\n From(\"Products\").GetRecordCount();\n\n Assert.IsTrue(records == 77);\n\nSimple Select with typed columns\n\n int records = new Select(Product.ProductIDColumn, Product.ProductNameColumn).\n From<Product>().GetRecordCount();\n Assert.IsTrue(records == 77);\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] |
40,317
|
<p>I have an NFS-mounted directory on a Linux machine that has hung. I've tried to force an unmount, but it doesn't seem to work:</p>
<pre><code>$ umount -f /mnt/data
$ umount2: Device or resource busy
$ umount: /mnt/data: device is busy
</code></pre>
<p>If I type "<code>mount</code>", it appears that the directory is no longer mounted, but it hangs if I do "<code>ls /mnt/data</code>", and if I try to remove the mountpoint, I get:</p>
<pre><code>$ rmdir /mnt/data
rmdir: /mnt/data: Device or resource busy
</code></pre>
<p>Is there anything I can do other than reboot the machine?</p>
|
[
{
"answer_id": 40320,
"author": "tessein",
"author_id": 3075,
"author_profile": "https://Stackoverflow.com/users/3075",
"pm_score": 9,
"selected": true,
"text": "umount -l\n"
},
{
"answer_id": 40331,
"author": "Ryan Ahearn",
"author_id": 75,
"author_profile": "https://Stackoverflow.com/users/75",
"pm_score": 4,
"selected": false,
"text": "lsof | grep /mnt/data\n"
},
{
"answer_id": 64180,
"author": "Daniel Papasian",
"author_id": 7548,
"author_profile": "https://Stackoverflow.com/users/7548",
"pm_score": 6,
"selected": false,
"text": "ifconfig eth0:fakenfs 192.0.2.55 netmask 255.255.255.255\n"
},
{
"answer_id": 14048770,
"author": "Daniel N.",
"author_id": 1931086,
"author_profile": "https://Stackoverflow.com/users/1931086",
"pm_score": 4,
"selected": false,
"text": "umount /path -f"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/742/"
] |
40,335
|
<p>I'm need to find a method to programmatically determine which disk drive Windows is using to boot. In other words, I need a way from Windows to determine which drive the BIOS is using to boot the whole system. </p>
<p>Does Windows expose an interface to discover this? With how big the Windows API is, I'm hoping there is something buried in there that might do the trick.</p>
<p>Terry</p>
<p>p.s. Just reading the first sectors of the hard disk isn't reveling anything. On my dev box I have two hard disks, and when I look at the contents of the first couple of sectors on either of the hard disks I have a standard boiler plate MBR.</p>
<p>Edit to clarify a few things.
The way I want to identify the device is with a string which will identify a physical disk drive (as opposed to a logical disk drive). Physical disk drives are of the form "\\.\PHYSICALDRIVEx" where x is a number. On the other hand, a logical drive is identified by a string of the form, "\\.\x" where x is a drive letter.</p>
<p>Edit to discuss a few of the ideas that were thrown out.
Knowing which logical volume Windows used to boot doesn't help me here. Here is the reason. Assume that C: is using a mirrored RAID setup. Now, that means we have at least two physical drives. Now, I get the mapping from Logical Drive to Physical Drive and I discover that there are two physical drives used by that volume. Which one did Windows use to boot? Of course, this is assuming that the physical drive Windows used to boot is the same physical drive that contains the MBR. </p>
|
[
{
"answer_id": 18424806,
"author": "JD.",
"author_id": 300041,
"author_profile": "https://Stackoverflow.com/users/300041",
"pm_score": 4,
"selected": false,
"text": "Control Panel"
},
{
"answer_id": 34293003,
"author": "ST3",
"author_id": 1237747,
"author_profile": "https://Stackoverflow.com/users/1237747",
"pm_score": 0,
"selected": false,
"text": "bcdedit"
},
{
"answer_id": 64396478,
"author": "Mark",
"author_id": 14465066,
"author_profile": "https://Stackoverflow.com/users/14465066",
"pm_score": 2,
"selected": false,
"text": "dispart \nlist disk \nselect disk 0 \ndetail disk\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2171/"
] |
40,352
|
<p>And why would I use one over the other in my code?</p>
|
[
{
"answer_id": 40366,
"author": "Rytmis",
"author_id": 266,
"author_profile": "https://Stackoverflow.com/users/266",
"pm_score": 5,
"selected": true,
"text": "Type"
},
{
"answer_id": 1438443,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "RuntimeTypeHandle"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1946/"
] |
40,361
|
<p>I have an application which extracts data from an XML file using XPath. If a node in that XML source file is missing I want to return the value "N/A" (much like the Oracle NVL function). The trick is that the application doesn't support XSLT; I'd like to do this using XPath and XPath alone.</p>
<p>Is that possible?</p>
|
[
{
"answer_id": 41142,
"author": "jelovirt",
"author_id": 2679,
"author_profile": "https://Stackoverflow.com/users/2679",
"pm_score": 1,
"selected": false,
"text": "<foo>\n <bar/>\n</foo>\n"
},
{
"answer_id": 41152,
"author": "jelovirt",
"author_id": 2679,
"author_profile": "https://Stackoverflow.com/users/2679",
"pm_score": 4,
"selected": true,
"text": "substring(concat(\"N/A\", /foo/baz), 4 * number(boolean(/foo/baz)))\n"
},
{
"answer_id": 43142,
"author": "jelovirt",
"author_id": 2679,
"author_profile": "https://Stackoverflow.com/users/2679",
"pm_score": 2,
"selected": false,
"text": "boolean(string-length($node))\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40361",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1019/"
] |
40,368
|
<p>Is there a maximum number of inodes in a single directory? </p>
<p>I have a directory of over 2 million files and can't get the <code>ls</code> command to work against that directory. So now I'm wondering if I've exceeded a limit on inodes in Linux. Is there a limit before a 2^64 numerical limit?</p>
|
[
{
"answer_id": 40389,
"author": "Jordi Bunster",
"author_id": 4272,
"author_profile": "https://Stackoverflow.com/users/4272",
"pm_score": 4,
"selected": false,
"text": "tune2fs -l /dev/DEVICE | grep -i inode\n"
},
{
"answer_id": 40392,
"author": "Joseph Bui",
"author_id": 3275,
"author_profile": "https://Stackoverflow.com/users/3275",
"pm_score": 0,
"selected": false,
"text": "ls -f | head -10"
},
{
"answer_id": 40441,
"author": "tonylo",
"author_id": 4071,
"author_profile": "https://Stackoverflow.com/users/4071",
"pm_score": 6,
"selected": false,
"text": "df -i"
},
{
"answer_id": 76514,
"author": "Robᵩ",
"author_id": 8747,
"author_profile": "https://Stackoverflow.com/users/8747",
"pm_score": 4,
"selected": false,
"text": "ls -U"
},
{
"answer_id": 3555084,
"author": "markus",
"author_id": 429334,
"author_profile": "https://Stackoverflow.com/users/429334",
"pm_score": -1,
"selected": false,
"text": "find"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40368",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1536194/"
] |
40,372
|
<p>I need to reformat my machine but I have so many user/passwords stored in FF2 that I just keep putting it off. Yes I know about backing up the entire profile and restoring it. But for some reason my profile has many issues and I want to start fresh with that as well.</p>
<p>Are the username and passwords stored in a text file or is there some way to export them and import after I reformat?</p>
|
[
{
"answer_id": 40466,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "signons2.txt"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3747/"
] |
40,376
|
<p>Is it possible to handle POSIX signals within the Java Virtual Machine?</p>
<p>At least <a href="http://en.wikipedia.org/wiki/SIGINT_(POSIX)" rel="noreferrer">SIGINT</a> and <a href="http://en.wikipedia.org/wiki/SIGKILL" rel="noreferrer">SIGKILL</a> should be quite platform independent.</p>
|
[
{
"answer_id": 41157,
"author": "Will",
"author_id": 816,
"author_profile": "https://Stackoverflow.com/users/816",
"pm_score": 5,
"selected": true,
"text": "sun.misc.Signal"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4308/"
] |
40,402
|
<p>I need to empty an LDF file before sending to a colleague. How do I force SQL Server to truncate the log?</p>
|
[
{
"answer_id": 40420,
"author": "Blorgbeard",
"author_id": 369,
"author_profile": "https://Stackoverflow.com/users/369",
"pm_score": 8,
"selected": false,
"text": "Properties"
},
{
"answer_id": 40427,
"author": "ila",
"author_id": 1178,
"author_profile": "https://Stackoverflow.com/users/1178",
"pm_score": 8,
"selected": true,
"text": "BACKUP LOG databasename WITH TRUNCATE_ONLY\n\nDBCC SHRINKFILE ( databasename_Log, 1)\n"
},
{
"answer_id": 6978809,
"author": "Nathan R",
"author_id": 584878,
"author_profile": "https://Stackoverflow.com/users/584878",
"pm_score": 6,
"selected": false,
"text": "ALTER DATABASE ExampleDB SET RECOVERY SIMPLE\nDBCC SHRINKFILE('ExampleDB_log', 0, TRUNCATEONLY)\nALTER DATABASE ExampleDB SET RECOVERY FULL\n"
},
{
"answer_id": 7361576,
"author": "Matej",
"author_id": 117965,
"author_profile": "https://Stackoverflow.com/users/117965",
"pm_score": 5,
"selected": false,
"text": "nul"
},
{
"answer_id": 61259458,
"author": "rip747",
"author_id": 31278,
"author_profile": "https://Stackoverflow.com/users/31278",
"pm_score": 0,
"selected": false,
"text": "BACKUP LOG Database TO DISK='NUL:'\nDBCC SHRINKFILE (Database_Log, 1)\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1042/"
] |
40,422
|
<p>Ok, so I want an autocomplete dropdown with linkbuttons as selections. So, the user puts the cursor in the "text box" and is greated with a list of options. They can either start typing to narrow down the list, or select one of the options on the list. As soon as they click (or press enter) the dataset this is linked to will be filtered by the selection. </p>
<p>Ok, is this as easy as wrapping an AJAX autocomplete around a dropdown? No? (Please?) </p>
|
[
{
"answer_id": 339033,
"author": "thoughtcrimes",
"author_id": 37814,
"author_profile": "https://Stackoverflow.com/users/37814",
"pm_score": 1,
"selected": true,
"text": " __________ _\n|__________||v|__ <-- text and button\n | | <-- ul (styled to appear relative to text input)\n | |\n | |\n |______________|\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4140/"
] |
40,423
|
<p>Actually, this question seems to have two parts:</p>
<ul>
<li>How to implement pattern matching?</li>
<li>How to implement <a href="http://erlang.org/doc/reference_manual/expressions.html#6.9" rel="noreferrer">send and receive</a> (i.e. the Actor model)?</li>
</ul>
<p>For the pattern matching part, I've been looking into various projects like <a href="http://members.cox.net/nelan/app.html" rel="noreferrer">App</a> and <a href="http://www.cs.nyu.edu/leunga/papers/research/prop/prop.html" rel="noreferrer">Prop</a>. These look pretty nice, but couldn't get them to work on a recent version (4.x) of g++. The <a href="http://felix-lang.org/" rel="noreferrer">Felix</a> language also seems to support pattern matching pretty well, but isn't really C++.</p>
<p>As for the <a href="http://en.wikipedia.org/wiki/Actor_model" rel="noreferrer">Actor model</a>, there are existing implementations like ACT++ and <a href="http://theron.ashtonmason.net/" rel="noreferrer">Theron</a>, but I couldn't find anything but papers on the former<strike>, and the latter is single-threaded only</strike> [see answers].</p>
<p>Personally, I've implemented actors using threading and a thread-safe message queue. Messages are hash-like structures, and used these together with a number of preprocessor macros to implemented simple pattern matching.</p>
<p>Right now, I can use the following code to send a message:</p>
<pre><code>(new Message(this))
->set("foo", "bar")
->set("baz", 123)
->send(recipient);
</code></pre>
<p>And the following to do simple pattern matching (<code>qDebug</code> and <code>qPrintable</code> are Qt-specific):</p>
<pre><code>receive_and_match(m)
match_key("foo") { qDebug("foo: %s", qPrintable(m->value("foo").toString())); }
or_match_key("baz") { qDebug("baz: %d", m->value("baz").toInt()); }
or_match_ignore
end_receive
</code></pre>
<p>However, this looks a bit hackish to me, and isn't very robust.</p>
<p>How would you do it? Did I miss any existing work?</p>
|
[
{
"answer_id": 912489,
"author": "neverlord",
"author_id": 112736,
"author_profile": "https://Stackoverflow.com/users/112736",
"pm_score": 2,
"selected": false,
"text": "recipient.send(23, 12.23f);\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
40,452
|
<p>I have to POST some parameters to a URL outside my network, and the developers on the other side asked me to not use HTTP Parameters: instead I have to post my key-values in <strong>HTTP Headers</strong>.</p>
<p>The fact is that I don't really understand what they mean: I tried to use a ajax-like post, with XmlHttp objects, and also I tried to write in the header with something like</p>
<pre><code>Request.Headers.Add(key,value);
</code></pre>
<p>but I cannot (exception from the framework); I tried the other way around, using the Response object like</p>
<pre><code>Response.AppendHeader("key", "value");
</code></pre>
<p>and then redirect to the page... but this doesn't work, as well.</p>
<p>It's evident, I think, that I'm stuck there, any help?</p>
<hr>
<p><strong>EDIT</strong> I forgot to tell you that my environment is .Net 2.0, c#, on Win server 2003.
The exception I got is</p>
<pre><code>System.PlatformNotSupportedException was unhandled by user code
Message="Operation is not supported on this platform."
Source="System.Web"
</code></pre>
<p>This looks like it's caused by my tentative to Request.Add, MS an year ago published some security fixes that don't permit this. </p>
|
[
{
"answer_id": 40468,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 0,
"selected": false,
"text": "http = httplib2.Http()\nhttp.request(url, 'POST', headers={'key': 'value'}, body=urllib.urlencode(''))\n"
},
{
"answer_id": 40486,
"author": "Ryan Duffield",
"author_id": 2696,
"author_profile": "https://Stackoverflow.com/users/2696",
"pm_score": 2,
"selected": false,
"text": " WebClient client = new WebClient();\n NameValueCollection data = new NameValueCollection();\n data[\"var1\"] = \"var1\";\n client.UploadValues(\"http://somewhere.com/api\", \"POST\", data);\n"
},
{
"answer_id": 40742,
"author": "kudlur",
"author_id": 1647,
"author_profile": "https://Stackoverflow.com/users/1647",
"pm_score": 0,
"selected": false,
"text": "< script language=\"javascript\">\n\nfunction SendRequest()\n{\n var r = new XMLHttpRequest();\n r.open('get', 'http://localhost/TestSite/CheckHeader.aspx');\n r.setRequestHeader('X-Test', 'one');\n r.setRequestHeader('X-Test', 'two');\n r.send(null);\n\n}\n< script / >\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1178/"
] |
40,456
|
<p>If I select from a table group by the month, day, year,
it only returns rows with records and leaves out combinations without any records, making it appear at a glance that every day or month has activity, you have to look at the date column actively for gaps. How can I get a row for every day/month/year, even when no data is present, in T-SQL?</p>
|
[
{
"answer_id": 40619,
"author": "ryw",
"author_id": 2477,
"author_profile": "https://Stackoverflow.com/users/2477",
"pm_score": 2,
"selected": true,
"text": "declare @career-fair-id int \nselect @career-fair-id = 125\n\ncreate table #data ([date] datetime null, [cumulative] int null) \n\ndeclare @event-date datetime, @current-process-date datetime, @day-count int \nselect @event-date = (select careerfairdate from tbl-career-fair where careerfairid = @career-fair-id) \nselect @current-process-date = dateadd(day, -90, @event-date) \n\n while @event-date <> @current-process-date \n begin \n select @current-process-date = dateadd(day, 1, @current-process-date) \n select @day-count = (select count(*) from tbl-career-fair-junction where attendanceregister <= @current-process-date and careerfairid = @career-fair-id) \n if @current-process-date <= getdate() \n insert into #data ([date], [cumulative]) values(@current-process-date, @day-count) \n end \n\n select * from #data \n drop table #data \n"
},
{
"answer_id": 274057,
"author": "6eorge Jetson",
"author_id": 23422,
"author_profile": "https://Stackoverflow.com/users/23422",
"pm_score": 0,
"selected": false,
"text": "\nDECLARE @StartInt int\nDECLARE @Increment int\nDECLARE @Iterations int\n\nSET @StartInt = 0\nSET @Increment = 1\nSET @Iterations = 365\n\n\nSELECT\n tCompleteDateSet.[Date]\n ,AggregatedMeasure = SUM(ISNULL(t.Data, 0))\nFROM\n (\n SELECT \n [Date] = dateadd(dd,GeneratedInt, @StartDate)\n FROM \n [dbo].[tvfUtilGenerateIntegerList] (\n @StartInt, \n ,@Increment, \n ,@Iterations\n )\n ) tCompleteDateSet\n LEFT JOIN tblData t\n ON (t.[Date] = tCompleteDateSet.[Date])\nGROUP BY\n tCompleteDateSet.[Date]\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2477/"
] |
40,465
|
<p>I have a List of Foo.</p>
<p>Foo has a string property named Bar.</p>
<p>I'd like to use <strong>LINQ</strong> to get a string[] of <strong>distinct</strong> values for Foo.Bar in List of Foo.</p>
<p>How can I do this?</p>
|
[
{
"answer_id": 40477,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 2,
"selected": false,
"text": "var distinctFooBars = (from foo in foos\n select foo.Bar).Distinct().ToArray();\n"
},
{
"answer_id": 40488,
"author": "Guy",
"author_id": 1463,
"author_profile": "https://Stackoverflow.com/users/1463",
"pm_score": 2,
"selected": false,
"text": "string[] arrayStrings = fooList.Select(a => a.Bar).Distinct().ToArray();\n"
},
{
"answer_id": 40497,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 4,
"selected": true,
"text": "var bars = Foos.Select(f => f.Bar).Distinct().ToArray();\n"
},
{
"answer_id": 40498,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var strings = (from a in fooList select a.Bar).Distinct();\nstring[] array = strings.ToArray();\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1946/"
] |
40,471
|
<p>What are the differences between a <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/HashMap.html" rel="noreferrer"><code>HashMap</code></a> and a <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Hashtable.html" rel="noreferrer"><code>Hashtable</code></a> in Java?</p>
<p>Which is more efficient for non-threaded applications?</p>
|
[
{
"answer_id": 40512,
"author": "izb",
"author_id": 974,
"author_profile": "https://Stackoverflow.com/users/974",
"pm_score": 6,
"selected": false,
"text": "Hashtable"
},
{
"answer_id": 40522,
"author": "Miles D",
"author_id": 3898,
"author_profile": "https://Stackoverflow.com/users/3898",
"pm_score": 6,
"selected": false,
"text": "Hashtable"
},
{
"answer_id": 40548,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 6,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 40878,
"author": "Josh Brown",
"author_id": 2030,
"author_profile": "https://Stackoverflow.com/users/2030",
"pm_score": 13,
"selected": true,
"text": "HashMap"
},
{
"answer_id": 40894,
"author": "Apocalisp",
"author_id": 3434,
"author_profile": "https://Stackoverflow.com/users/3434",
"pm_score": 7,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 41454,
"author": "serg10",
"author_id": 1853,
"author_profile": "https://Stackoverflow.com/users/1853",
"pm_score": 10,
"selected": false,
"text": "Map"
},
{
"answer_id": 1041798,
"author": "aberrant80",
"author_id": 124111,
"author_profile": "https://Stackoverflow.com/users/124111",
"pm_score": 9,
"selected": false,
"text": "Hashtable"
},
{
"answer_id": 7644118,
"author": "sravan",
"author_id": 759012,
"author_profile": "https://Stackoverflow.com/users/759012",
"pm_score": 8,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 8832544,
"author": "pwes",
"author_id": 283519,
"author_profile": "https://Stackoverflow.com/users/283519",
"pm_score": 5,
"selected": false,
"text": "for (Elem elem : map.keys()) {\n elem.doSth();\n}\n"
},
{
"answer_id": 10372667,
"author": "alain.janinm",
"author_id": 1140748,
"author_profile": "https://Stackoverflow.com/users/1140748",
"pm_score": 5,
"selected": false,
"text": "Map m = Collections.synchronizedMap(new HashMap(...));\n"
},
{
"answer_id": 13467173,
"author": "Sujan",
"author_id": 819014,
"author_profile": "https://Stackoverflow.com/users/819014",
"pm_score": 6,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 13797704,
"author": "SkyWalker",
"author_id": 1142881,
"author_profile": "https://Stackoverflow.com/users/1142881",
"pm_score": 5,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 14452144,
"author": "raja",
"author_id": 1199342,
"author_profile": "https://Stackoverflow.com/users/1199342",
"pm_score": 4,
"selected": false,
"text": "Hashtable"
},
{
"answer_id": 17651399,
"author": "pong",
"author_id": 1162526,
"author_profile": "https://Stackoverflow.com/users/1162526",
"pm_score": 3,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 22491742,
"author": "Shreyos Adikari",
"author_id": 838841,
"author_profile": "https://Stackoverflow.com/users/838841",
"pm_score": 4,
"selected": false,
"text": "Hashtable"
},
{
"answer_id": 22629569,
"author": "pierrotlefou",
"author_id": 115722,
"author_profile": "https://Stackoverflow.com/users/115722",
"pm_score": 7,
"selected": false,
"text": "HashTable"
},
{
"answer_id": 25348157,
"author": "Night0",
"author_id": 2647077,
"author_profile": "https://Stackoverflow.com/users/2647077",
"pm_score": 3,
"selected": false,
"text": "Map m = Collections.synchronizedMap(hashMap);\n"
},
{
"answer_id": 25526024,
"author": "Rahul Tripathi",
"author_id": 3981269,
"author_profile": "https://Stackoverflow.com/users/3981269",
"pm_score": 4,
"selected": false,
"text": "Hashmap"
},
{
"answer_id": 28426488,
"author": "IntelliJ Amiya",
"author_id": 3395198,
"author_profile": "https://Stackoverflow.com/users/3395198",
"pm_score": 3,
"selected": false,
"text": "Hashtable:"
},
{
"answer_id": 37031553,
"author": "Kostas Kryptos",
"author_id": 3294902,
"author_profile": "https://Stackoverflow.com/users/3294902",
"pm_score": 4,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 42622789,
"author": "roottraveller",
"author_id": 5167682,
"author_profile": "https://Stackoverflow.com/users/5167682",
"pm_score": 7,
"selected": false,
"text": "HashMap"
},
{
"answer_id": 48094803,
"author": "Yash",
"author_id": 5081877,
"author_profile": "https://Stackoverflow.com/users/5081877",
"pm_score": 5,
"selected": false,
"text": "Collection"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4316/"
] |
40,480
|
<p>I always thought Java uses <strong>pass-by-reference</strong>.</p>
<p>However, I've seen <a href="http://javadude.com/articles/passbyvalue.htm" rel="noreferrer">a blog post</a> that claims that Java uses <strong>pass-by-value</strong>.</p>
<p>I don't think I understand the distinction they're making.</p>
<p>What is the explanation?</p>
|
[
{
"answer_id": 40499,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 10,
"selected": false,
"text": "int"
},
{
"answer_id": 40507,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 8,
"selected": false,
"text": "private static void foo(Object bar) {\n bar = null;\n}\n\npublic static void main(String[] args) {\n String baz = \"Hah!\";\n foo(baz);\n System.out.println(baz);\n}\n"
},
{
"answer_id": 40523,
"author": "erlando",
"author_id": 4192,
"author_profile": "https://Stackoverflow.com/users/4192",
"pm_score": 13,
"selected": false,
"text": "public static void main(String[] args) {\n Dog aDog = new Dog(\"Max\");\n Dog oldDog = aDog;\n\n // we pass the object to foo\n foo(aDog);\n // aDog variable is still pointing to the \"Max\" dog when foo(...) returns\n aDog.getName().equals(\"Max\"); // true\n aDog.getName().equals(\"Fifi\"); // false\n aDog == oldDog; // true\n}\n\npublic static void foo(Dog d) {\n d.getName().equals(\"Max\"); // true\n // change d inside of foo() to point to a new Dog instance \"Fifi\"\n d = new Dog(\"Fifi\");\n d.getName().equals(\"Fifi\"); // true\n}\n"
},
{
"answer_id": 40630,
"author": "Paul de Vrieze",
"author_id": 4100,
"author_profile": "https://Stackoverflow.com/users/4100",
"pm_score": 5,
"selected": false,
"text": "int"
},
{
"answer_id": 42455,
"author": "pek",
"author_id": 2644,
"author_profile": "https://Stackoverflow.com/users/2644",
"pm_score": 5,
"selected": false,
"text": "public class Test {\n public static void main(String[] args) {\n Integer a = new Integer(2);\n Integer b = new Integer(3);\n System.out.println(\"Before: a = \" + a + \", b = \" + b);\n swap(a,b);\n System.out.println(\"After: a = \" + a + \", b = \" + b);\n }\n\n public static swap(Integer iA, Integer iB) {\n Integer tmp = iA;\n iA = iB;\n iB = tmp;\n }\n}\n"
},
{
"answer_id": 49857,
"author": "SWD",
"author_id": 3034,
"author_profile": "https://Stackoverflow.com/users/3034",
"pm_score": 5,
"selected": false,
"text": "public class PassByCopy{\n public static void changeName(Dog d){\n d.name = \"Fido\";\n }\n public static void main(String[] args){\n Dog d = new Dog(\"Maxx\");\n System.out.println(\"name= \"+ d.name);\n changeName(d);\n System.out.println(\"name= \"+ d.name);\n }\n}\nclass Dog{\n public String name;\n public Dog(String s){\n this.name = s;\n }\n}\n"
},
{
"answer_id": 73021,
"author": "Scott Stanchfield",
"author_id": 12541,
"author_profile": "https://Stackoverflow.com/users/12541",
"pm_score": 12,
"selected": false,
"text": "Dog myDog;\n"
},
{
"answer_id": 85711,
"author": "Eclipse",
"author_id": 8701,
"author_profile": "https://Stackoverflow.com/users/8701",
"pm_score": 8,
"selected": false,
"text": "void cppMethod(int val, int &ref, Dog obj, Dog &objRef, Dog *objPtr, Dog *&objPtrRef)\n{\n val = 7; // Modifies the copy\n ref = 7; // Modifies the original variable\n obj.SetName(\"obj\"); // Modifies the copy of Dog passed\n objRef.SetName(\"objRef\"); // Modifies the original Dog passed\n objPtr->SetName(\"objPtr\"); // Modifies the original Dog pointed to \n // by the copy of the pointer passed.\n objPtr = new Dog(\"newObjPtr\"); // Modifies the copy of the pointer, \n // leaving the original object alone.\n objPtrRef->SetName(\"objRefPtr\"); // Modifies the original Dog pointed to \n // by the original pointer passed. \n objPtrRef = new Dog(\"newObjPtrRef\"); // Modifies the original pointer passed\n}\n\nint main()\n{\n int a = 0;\n int b = 0;\n Dog d0 = Dog(\"d0\");\n Dog d1 = Dog(\"d1\");\n Dog *d2 = new Dog(\"d2\");\n Dog *d3 = new Dog(\"d3\");\n cppMethod(a, b, d0, d1, d2, d3);\n // a is still set to 0\n // b is now set to 7\n // d0 still have name \"d0\"\n // d1 now has name \"objRef\"\n // d2 now has name \"objPtr\"\n // d3 now has name \"newObjPtrRef\"\n}\n"
},
{
"answer_id": 623155,
"author": "Jared Oberhaus",
"author_id": 73019,
"author_profile": "https://Stackoverflow.com/users/73019",
"pm_score": 6,
"selected": false,
"text": "void getValues(int& arg1, int& arg2) {\n arg1 = 1;\n arg2 = 2;\n}\nvoid caller() {\n int x;\n int y;\n getValues(x, y);\n cout << \"Result: \" << x << \" \" << y << endl;\n}\n"
},
{
"answer_id": 707416,
"author": "kukudas",
"author_id": 48402,
"author_profile": "https://Stackoverflow.com/users/48402",
"pm_score": 6,
"selected": false,
"text": "public static void swap(StringBuffer s1, StringBuffer s2) {\n StringBuffer temp = s1;\n s1 = s2;\n s2 = temp;\n}\n\n\npublic static void main(String[] args) {\n StringBuffer s1 = new StringBuffer(\"Hello\");\n StringBuffer s2 = new StringBuffer(\"World\");\n swap(s1, s2);\n System.out.println(s1);\n System.out.println(s2);\n}\n"
},
{
"answer_id": 1964361,
"author": "fastcodejava",
"author_id": 184730,
"author_profile": "https://Stackoverflow.com/users/184730",
"pm_score": 5,
"selected": false,
"text": "new"
},
{
"answer_id": 3439923,
"author": "Vinay Lodha",
"author_id": 212665,
"author_profile": "https://Stackoverflow.com/users/212665",
"pm_score": 4,
"selected": false,
"text": "NullPointerException"
},
{
"answer_id": 7034719,
"author": "Marsellus Wallace",
"author_id": 807231,
"author_profile": "https://Stackoverflow.com/users/807231",
"pm_score": 10,
"selected": false,
"text": "1. Person person;\n2. person = new Person(\"Tom\");\n3. changeName(person);\n4.\n5. //I didn't use Person person below as an argument to be nice\n6. static void changeName(Person anotherReferenceToTheSamePersonObject) {\n7. anotherReferenceToTheSamePersonObject.setName(\"Jerry\");\n8. }\n"
},
{
"answer_id": 10236169,
"author": "Luigi R. Viggiano",
"author_id": 258289,
"author_profile": "https://Stackoverflow.com/users/258289",
"pm_score": 3,
"selected": false,
"text": "void bithday(Person p) {\n p.age++;\n}\n"
},
{
"answer_id": 11764499,
"author": "Fernando Espinosa",
"author_id": 1426433,
"author_profile": "https://Stackoverflow.com/users/1426433",
"pm_score": 4,
"selected": false,
"text": "int"
},
{
"answer_id": 12429953,
"author": "Eng.Fouad",
"author_id": 597657,
"author_profile": "https://Stackoverflow.com/users/597657",
"pm_score": 11,
"selected": false,
"text": "public class Main {\n\n public static void main(String[] args) {\n Foo f = new Foo(\"f\");\n changeReference(f); // It won't change the reference!\n modifyReference(f); // It will modify the object that the reference variable \"f\" refers to!\n }\n\n public static void changeReference(Foo a) {\n Foo b = new Foo(\"b\");\n a = b;\n }\n\n public static void modifyReference(Foo c) {\n c.setAttribute(\"c\");\n }\n\n}\n"
},
{
"answer_id": 16880062,
"author": "Khaled.K",
"author_id": 2128327,
"author_profile": "https://Stackoverflow.com/users/2128327",
"pm_score": 3,
"selected": false,
"text": "class Example\n{\n public static void test (Cat ref)\n {\n // 3 - <ref> is a copy of the reference <a>\n // both currently reference Grumpy\n System.out.println(ref.getName());\n\n // 4 - now <ref> references a new <Cat> object named \"Nyan\"\n ref = new Cat(\"Nyan\");\n\n // 5 - this should print \"Nyan\"\n System.out.println( ref.getName() );\n }\n\n public static void main (String [] args)\n {\n // 1 - a is a <Cat> reference that references a Cat object in memory with name \"Grumpy\"\n Cat a = new Cat(\"Grumpy\");\n\n // 2 - call to function test which takes a <Cat> reference\n test (a);\n\n // 6 - function call ends, and <ref> life-time ends\n // \"Nyan\" object has no references and the Garbage\n // Collector will remove it from memory when invoked\n\n // 7 - this should print \"Grumpy\"\n System.out.println(a.getName());\n }\n}\n"
},
{
"answer_id": 17303467,
"author": "JasonG",
"author_id": 1255825,
"author_profile": "https://Stackoverflow.com/users/1255825",
"pm_score": 4,
"selected": false,
"text": "1. import java.awt.Dimension;\n2. class ReferenceTest {\n3. public static void main (String [] args) {\n4. Dimension d = new Dimension(5,10);\n5. ReferenceTest rt = new ReferenceTest();\n6. System.out.println(\"Before modify() d.height = \" + d.height);\n7. rt.modify(d);\n8. System.out.println(\"After modify() d.height = \"\n9. }\n10.\n11.\n12.\n13. }\n14. }\n"
},
{
"answer_id": 17563873,
"author": "Gaurav",
"author_id": 1912964,
"author_profile": "https://Stackoverflow.com/users/1912964",
"pm_score": 5,
"selected": false,
"text": "public void test() {\n MyClass obj = null;\n init(obj);\n //After calling init method, obj still points to null\n //this is because obj is passed as value and not as reference.\n}\nprivate void init(MyClass objVar) {\n objVar = new MyClass();\n}\n"
},
{
"answer_id": 18287583,
"author": "bvdb",
"author_id": 1833961,
"author_profile": "https://Stackoverflow.com/users/1833961",
"pm_score": 3,
"selected": false,
"text": "class Example\n{\n static void InitArray(out int[] arr)\n {\n arr = new int[5] { 1, 2, 3, 4, 5 };\n }\n\n static void Main()\n {\n int[] someArray;\n InitArray(out someArray);\n\n // This is true !\n boolean isTrue = (someArray[0] == 1);\n }\n}\n"
},
{
"answer_id": 18623099,
"author": "James Drinkard",
"author_id": 543572,
"author_profile": "https://Stackoverflow.com/users/543572",
"pm_score": 3,
"selected": false,
"text": "package test.abc;\n\npublic class TestObject {\n\n /**\n * @param args\n */\n public static void main(String[] args) {\n bar();\n }\n\n static void bar() {\n Foo f = new Foo();\n System.out.println(\"Object reference for f: \" + f);\n f.setName(\"James\");\n doStuff(f);\n System.out.println(f.getName());\n //Can change the state of an object variable in f, but can't change the object reference for f.\n //You still have 2 foo objects.\n System.out.println(\"Object reference for f: \" + f);\n }\n\n static void doStuff(Foo g) {\n g.setName(\"Boo\");\n g = new Foo();\n System.out.println(\"Object reference for g: \" + g);\n }\n}\n\n\npackage test.abc;\n\npublic class Foo {\n public String name = \"\";\n\n public String getName() {\n return name;\n }\n\n public void setName(String name) {\n this.name = name;\n }\n\n}\n"
},
{
"answer_id": 18740042,
"author": "cutmancometh",
"author_id": 1917489,
"author_profile": "https://Stackoverflow.com/users/1917489",
"pm_score": 8,
"selected": false,
"text": "int x = 3;\nfloat y = 101.1f;\nboolean amIAwesome = true;\n"
},
{
"answer_id": 18950805,
"author": "user1931858",
"author_id": 1931858,
"author_profile": "https://Stackoverflow.com/users/1931858",
"pm_score": 3,
"selected": false,
"text": "public static void dummyIncrease(int[] x, int y)\n{\n x[0]++;\n y++;\n}\npublic static void main(String[] args)\n{\n int[] arr = {3, 4, 5};\n int b = 1;\n dummyIncrease(arr, b);\n // arr[0] is 4, but b is still 1\n}\n\nmain()\n arr +---+ +---+---+---+\n | # | ----> | 3 | 4 | 5 |\n +---+ +---+---+---+\n b +---+ ^\n | 1 | | \n +---+ |\n |\ndummyIncrease() |\n x +---+ |\n | # | ------------+\n +---+ \n y +---+ \n | 1 | \n +---+ \n"
},
{
"answer_id": 19421107,
"author": "Ganesh",
"author_id": 1910406,
"author_profile": "https://Stackoverflow.com/users/1910406",
"pm_score": 7,
"selected": false,
"text": "public class PassByValue {\n public static void main(String[] args) {\n Test t = new Test();\n t.name = \"initialvalue\";\n new PassByValue().changeValue(t);\n System.out.println(t.name);\n }\n \n public void changeValue(Test f) {\n f.name = \"changevalue\";\n }\n}\n\nclass Test {\n String name;\n}\n"
},
{
"answer_id": 19970416,
"author": "Bhushan",
"author_id": 1907916,
"author_profile": "https://Stackoverflow.com/users/1907916",
"pm_score": 2,
"selected": false,
"text": "The following code example illustrates this point:\n1 public class PassTest {\n2\n3 // Methods to change the current values\n4 public static void changeInt(int value) {\n5 value = 55;\n6 }\n7 public static void changeObjectRef(MyDate ref) {\n8 ref = new MyDate(1, 1, 2000);\n9 }\n10 public static void changeObjectAttr(MyDate ref) {\n11 ref.setDay(4);\n12 }\n13\n14 public static void main(String args[]) {\n15 MyDate date;\n16 int val;\n17\n18 // Assign the int\n19 val = 11;\n20 // Try to change it\n21 changeInt(val);\n22 // What is the current value?\n23 System.out.println(\"Int value is: \" + val);\n24\n25 // Assign the date\n26 date = new MyDate(22, 7, 1964);\n27 // Try to change it\n28 changeObjectRef(date);\n29 // What is the current value?\n30 System.out.println(\"MyDate: \" + date);\n31\n32 // Now change the day attribute\n33 // through the object reference\n34 changeObjectAttr(date);\n35 // What is the current value?\n36 System.out.println(\"MyDate: \" + date);\n37 }\n38 }\n"
},
{
"answer_id": 20125921,
"author": "Srle",
"author_id": 922581,
"author_profile": "https://Stackoverflow.com/users/922581",
"pm_score": 7,
"selected": false,
"text": "Point pnt1 = new Point(0,0);"
},
{
"answer_id": 20566453,
"author": "karatedog",
"author_id": 216248,
"author_profile": "https://Stackoverflow.com/users/216248",
"pm_score": 6,
"selected": false,
"text": "5"
},
{
"answer_id": 21288385,
"author": "JAN",
"author_id": 779111,
"author_profile": "https://Stackoverflow.com/users/779111",
"pm_score": 3,
"selected": false,
"text": "public class Dog {\n\n String dog ;\n static int x_static;\n int y_not_static;\n\n public String getName()\n {\n return this.dog;\n }\n\n public Dog(String dog)\n {\n this.dog = dog;\n }\n\n public void setName(String name)\n {\n this.dog = name;\n }\n\n public static void foo(Dog someDog)\n {\n x_static = 1;\n // y_not_static = 2; // not possible !!\n someDog.setName(\"Max\"); // AAA\n someDog = new Dog(\"Fifi\"); // BBB\n someDog.setName(\"Rowlf\"); // CCC\n }\n\n public static void main(String args[])\n {\n Dog myDog = new Dog(\"Rover\");\n foo(myDog);\n System.out.println(myDog.getName());\n }\n}\n"
},
{
"answer_id": 24546764,
"author": "Sotirios Delimanolis",
"author_id": 438154,
"author_profile": "https://Stackoverflow.com/users/438154",
"pm_score": 6,
"selected": false,
"text": "new ..."
},
{
"answer_id": 24685542,
"author": "Dustin Deus",
"author_id": 1893773,
"author_profile": "https://Stackoverflow.com/users/1893773",
"pm_score": 3,
"selected": false,
"text": "@"
},
{
"answer_id": 26028582,
"author": "Michał Żbikowski",
"author_id": 3961865,
"author_profile": "https://Stackoverflow.com/users/3961865",
"pm_score": 4,
"selected": false,
"text": "void incrementValue(int inFunction){\n inFunction ++;\n System.out.println(\"In function: \" + inFunction);\n}\n\nint original = 10;\nSystem.out.print(\"Original before: \" + original);\nincrementValue(original);\nSystem.out.println(\"Original after: \" + original);\n\nWe see in the console:\n > Original before: 10\n > In Function: 11\n > Original after: 10 (NO CHANGE)\n"
},
{
"answer_id": 26210057,
"author": "drew7721",
"author_id": 2997238,
"author_profile": "https://Stackoverflow.com/users/2997238",
"pm_score": 3,
"selected": false,
"text": "public class Yo {\npublic static void foo(int x){\n System.out.println(x); //out 2\n x = x+2;\n System.out.println(x); // out 4\n}\npublic static void foo(int[] x){\n System.out.println(x[0]); //1\n x[0] = x[0]+2;\n System.out.println(x[0]); //3\n}\npublic static void main(String[] args) {\n int t = 2;\n foo(t);\n System.out.println(t); // out 2 (t did not change in foo)\n\n int[] tab = new int[]{1};\n foo(tab);\n System.out.println(tab[0]); // out 3 (tab[0] did change in foo)\n}}\n"
},
{
"answer_id": 27608651,
"author": "Ramprasad",
"author_id": 1695011,
"author_profile": "https://Stackoverflow.com/users/1695011",
"pm_score": 3,
"selected": false,
"text": "import java.io.*;\nclass Aclass\n{\n public int a;\n}\npublic class test\n{\n public static void foo_obj(Aclass obj)\n {\n obj.a=5;\n }\n public static void foo_int(int a)\n {\n a=3;\n }\n public static void main(String args[])\n {\n //test passing an object\n Aclass ob = new Aclass();\n ob.a=0;\n foo_obj(ob);\n System.out.println(ob.a);//prints 5\n\n //test passing an integer\n int i=0;\n foo_int(i);\n System.out.println(i);//prints 0\n }\n}\n"
},
{
"answer_id": 28750315,
"author": "João Oliveira",
"author_id": 1282030,
"author_profile": "https://Stackoverflow.com/users/1282030",
"pm_score": 3,
"selected": false,
"text": "PersonClass variable1 = new PersonClass(\"Mary\", 32);\n\nPersonClass variable2;\n"
},
{
"answer_id": 29133165,
"author": "Christian",
"author_id": 112670,
"author_profile": "https://Stackoverflow.com/users/112670",
"pm_score": 5,
"selected": false,
"text": "StringBuilder"
},
{
"answer_id": 30201678,
"author": "spiderman",
"author_id": 3250087,
"author_profile": "https://Stackoverflow.com/users/3250087",
"pm_score": 6,
"selected": false,
"text": "public class PassByValueString {\n public static void main(String[] args) {\n new PassByValueString().caller();\n }\n\n public void caller() {\n String value = \"Nikhil\";\n boolean valueflag = false;\n String output = method(value, valueflag);\n /*\n * 'output' is insignificant in this example. we are more interested in\n * 'value' and 'valueflag'\n */\n System.out.println(\"output : \" + output);\n System.out.println(\"value : \" + value);\n System.out.println(\"valueflag : \" + valueflag);\n\n }\n\n public String method(String value, boolean valueflag) {\n value = \"Anand\";\n valueflag = true;\n return \"output\";\n }\n}\n"
},
{
"answer_id": 34924074,
"author": "Placinta Alexandru",
"author_id": 4957499,
"author_profile": "https://Stackoverflow.com/users/4957499",
"pm_score": 4,
"selected": false,
"text": "public static void increment(int x) { x++; }\n\nint a = 3;\nincrement(a);\n"
},
{
"answer_id": 36843568,
"author": "OverCoder",
"author_id": 2164304,
"author_profile": "https://Stackoverflow.com/users/2164304",
"pm_score": 4,
"selected": false,
"text": "myObject"
},
{
"answer_id": 37669835,
"author": "Ravi Sanwal",
"author_id": 1195605,
"author_profile": "https://Stackoverflow.com/users/1195605",
"pm_score": 3,
"selected": false,
"text": "#include <iostream>\nusing namespace std;\n\nclass Foo {\n private:\n int x;\n public:\n Foo(int val) {x = val;}\n void foo()\n {\n cout<<x<<endl;\n }\n};\n\nvoid bar(Foo& ref)\n{\n ref.foo();\n ref = *(new Foo(99));\n ref.foo();\n}\n\nint main()\n{\n Foo f = Foo(1);\n f.foo();\n bar(f);\n f.foo();\n\n return 0;\n}\n"
},
{
"answer_id": 39709353,
"author": "Vivek Kumar",
"author_id": 5128145,
"author_profile": "https://Stackoverflow.com/users/5128145",
"pm_score": 3,
"selected": false,
"text": " public void badSwap(int var1, int\n var2{ int temp = var1; var1 = var2; var2 =\n temp; }\n"
},
{
"answer_id": 39767073,
"author": "khakishoiab",
"author_id": 5797598,
"author_profile": "https://Stackoverflow.com/users/5797598",
"pm_score": 4,
"selected": false,
"text": "swap(Type arg1, Type arg2) {\n Type temp = arg1;\n arg1 = arg2;\n arg2 = temp;\n}\n"
},
{
"answer_id": 40631632,
"author": "Taleev Aalam",
"author_id": 7051714,
"author_profile": "https://Stackoverflow.com/users/7051714",
"pm_score": 3,
"selected": false,
"text": "class S{\nString name=\"alam\";\npublic void setName(String n){\nthis.name=n; \n}}\n"
},
{
"answer_id": 41393112,
"author": "Rahul Kumar",
"author_id": 4958222,
"author_profile": "https://Stackoverflow.com/users/4958222",
"pm_score": 4,
"selected": false,
"text": "@Test\npublic void sampleTest(){\n int i = 5;\n incrementBy100(i);\n System.out.println(\"passed ==> \"+ i);\n Integer j = new Integer(5);\n incrementBy100(j);\n System.out.println(\"passed ==> \"+ j);\n}\n/**\n * @param i\n */\nprivate void incrementBy100(int i) {\n i += 100;\n System.out.println(\"incremented = \"+ i);\n}\n"
},
{
"answer_id": 41901960,
"author": "Raja",
"author_id": 1952852,
"author_profile": "https://Stackoverflow.com/users/1952852",
"pm_score": 3,
"selected": false,
"text": "public class Doggie {\n\n public static void main(String...args) {\n System.out.println(\"At the owner's home:\");\n Dog d = new Dog(12);\n d.wag();\n goodVet(d);\n System.out.println(\"With the owner again:)\");\n d.wag();\n badVet(d);\n System.out.println(\"With the owner again(:\");\n d.wag();\n }\n\n public static void goodVet (Dog dog) {\n System.out.println(\"At the good vet:\");\n dog.wag();\n dog = new Dog(12); // create a clone\n dog.cutTail(6); // cut the clone's tail\n dog.wag();\n }\n\n public static void badVet (Dog dog) {\n System.out.println(\"At the bad vet:\");\n dog.wag();\n dog.cutTail(2); // cut the original dog's tail\n dog.wag();\n } \n}\n\nclass Dog {\n\n int tailLength;\n\n public Dog(int originalLength) {\n this.tailLength = originalLength;\n }\n\n public void cutTail (int newLength) {\n this.tailLength = newLength;\n }\n\n public void wag() {\n System.out.println(\"Wagging my \" +tailLength +\" inch tail\");\n }\n}\n\nOutput:\nAt the owner's home:\nWagging my 12 inch tail\nAt the good vet:\nWagging my 12 inch tail\nWagging my 6 inch tail\nWith the owner again:)\nWagging my 12 inch tail\nAt the bad vet:\nWagging my 12 inch tail\nWagging my 2 inch tail\nWith the owner again(:\nWagging my 2 inch tail\n"
},
{
"answer_id": 43113746,
"author": "Basheer AL-MOMANI",
"author_id": 4251431,
"author_profile": "https://Stackoverflow.com/users/4251431",
"pm_score": 4,
"selected": false,
"text": "types of values"
},
{
"answer_id": 46026822,
"author": "Supriya",
"author_id": 4233180,
"author_profile": "https://Stackoverflow.com/users/4233180",
"pm_score": 4,
"selected": false,
"text": "class Test {\n\npublic static void main (String[] args) throws java.lang.Exception\n{\n // Primitive type\n System.out.println(\"Primitve:\");\n int a = 5;\n primitiveFunc(a);\n System.out.println(\"Three: \" + a); //5\n\n //Object\n System.out.println(\"Object:\");\n DummyObject dummyObject = new DummyObject();\n System.out.println(\"One: \" + dummyObject.getObj()); //555\n objectFunc(dummyObject);\n System.out.println(\"Four: \" + dummyObject.getObj()); //666 (555 if line in method uncommented.)\n\n}\n\nprivate static void primitiveFunc(int b) {\n System.out.println(\"One: \" + b); //5\n b = 10;\n System.out.println(\"Two:\" + b); //10\n}\n\nprivate static void objectFunc(DummyObject b) {\n System.out.println(\"Two: \" + b.getObj()); //555\n //b = new DummyObject();\n b.setObj(666);\n System.out.println(\"Three:\" + b.getObj()); //666\n}\n\n}\n\nclass DummyObject {\n private int obj = 555;\n public int getObj() { return obj; }\n public void setObj(int num) { obj = num; }\n}\n"
},
{
"answer_id": 46077533,
"author": "Raj S. Rusia",
"author_id": 7178104,
"author_profile": "https://Stackoverflow.com/users/7178104",
"pm_score": 5,
"selected": false,
"text": "public class Balloon {\n\n private String color;\n\n public Balloon(){}\n\n public Balloon(String c){\n this.color=c;\n }\n\n public String getColor() {\n return color;\n }\n\n public void setColor(String color) {\n this.color = color;\n }\n}\n"
},
{
"answer_id": 46871427,
"author": "NAGHMAAN MOHASEEN",
"author_id": 8808036,
"author_profile": "https://Stackoverflow.com/users/8808036",
"pm_score": 4,
"selected": false,
"text": "int *p;"
},
{
"answer_id": 47844599,
"author": "Premraj",
"author_id": 1697099,
"author_profile": "https://Stackoverflow.com/users/1697099",
"pm_score": 4,
"selected": false,
"text": "public class PassByValuePrimitive {\n public static void main(String[] args) {\n int i=5;\n System.out.println(i); //prints 5\n change(i);\n System.out.println(i); //prints 5\n }\n \n \n private static void change(int i) {\n System.out.println(i); //prints 5\n i=10;\n System.out.println(i); //prints 10\n \n }\n}\n"
},
{
"answer_id": 48591063,
"author": "Felypp Oliveira",
"author_id": 1977836,
"author_profile": "https://Stackoverflow.com/users/1977836",
"pm_score": 5,
"selected": false,
"text": "public void foo(Object param)\n{\n // some code in foo...\n}\n\npublic void bar()\n{\n Object obj = new Object();\n\n foo(obj);\n}\n"
},
{
"answer_id": 49330809,
"author": "mc01",
"author_id": 3216970,
"author_profile": "https://Stackoverflow.com/users/3216970",
"pm_score": 3,
"selected": false,
"text": "tinyHouseAt1234Main"
},
{
"answer_id": 49640653,
"author": "Michael",
"author_id": 4109266,
"author_profile": "https://Stackoverflow.com/users/4109266",
"pm_score": 5,
"selected": false,
"text": "Account account1 = new Account();\n"
},
{
"answer_id": 50391764,
"author": "asok",
"author_id": 5092157,
"author_profile": "https://Stackoverflow.com/users/5092157",
"pm_score": 3,
"selected": false,
"text": "package com.asok.cop.example.task;\npublic class Example {\n int data = 50;\n\n void change(int data) {\n data = data + 100;// changes will be in the local variable \n System.out.println(\"after add \" + data);\n }\n\n public static void main(String args[]) {\n Example op = new Example();\n System.out.println(\"before change \" + op.data);\n op.change(500);\n System.out.println(\"after change \" + op.data);\n }\n}\n"
},
{
"answer_id": 54373107,
"author": "Sanjeev",
"author_id": 1028560,
"author_profile": "https://Stackoverflow.com/users/1028560",
"pm_score": 7,
"selected": false,
"text": "using namespace std;\n#include <iostream>\n\nvoid change (char *&str){ // the '&' makes this a reference parameter\n str = NULL;\n}\n\nint main()\n{\n char *str = \"not Null\";\n change(str);\n cout<<\"str is \" << str; // ==>str is <null>\n}\n"
},
{
"answer_id": 55923549,
"author": "moldovean",
"author_id": 959876,
"author_profile": "https://Stackoverflow.com/users/959876",
"pm_score": 4,
"selected": false,
"text": "class Apple {\n private double weight;\n public Apple(double weight) {\n this.weight = weight;\n }\n // getters and setters ...\n\n}\n"
},
{
"answer_id": 57229012,
"author": "natwar kumar",
"author_id": 3957354,
"author_profile": "https://Stackoverflow.com/users/3957354",
"pm_score": 2,
"selected": false,
"text": "public class Test {\n\n static class Dog {\n String name;\n\n @Override\n public int hashCode() {\n final int prime = 31;\n int result = 1;\n result = prime * result + ((name == null) ? 0 : name.hashCode());\n return result;\n }\n\n @Override\n public boolean equals(Object obj) {\n if (this == obj)\n return true;\n if (obj == null)\n return false;\n if (getClass() != obj.getClass())\n return false;\n Dog other = (Dog) obj;\n if (name == null) {\n if (other.name != null)\n return false;\n } else if (!name.equals(other.name))\n return false;\n return true;\n }\n\n public String getName() {\n return name;\n }\n\n public void setName(String nb) {\n this.name = nb;\n }\n\n Dog(String sd) {\n this.name = sd;\n }\n }\n /**\n * \n * @param args\n */\n public static void main(String[] args) {\n Dog aDog = new Dog(\"Max\");\n\n // we pass the object to foo\n foo(aDog);\n Dog oldDog = aDog;\n\n System.out.println(\" 1: \" + aDog.getName().equals(\"Max\")); // false\n System.out.println(\" 2 \" + aDog.getName().equals(\"huahua\")); // false\n System.out.println(\" 3 \" + aDog.getName().equals(\"moron\")); // true\n System.out.println(\" 4 \" + \" \" + (aDog == oldDog)); // true\n\n // part2\n Dog aDog1 = new Dog(\"Max\");\n\n foo(aDog1, 5);\n Dog oldDog1 = aDog;\n\n System.out.println(\" 5 : \" + aDog1.getName().equals(\"huahua\")); // true\n System.out.println(\" part2 : \" + (aDog1 == oldDog1)); // false\n\n Dog oldDog2 = foo(aDog1, 5, 6);\n System.out.println(\" 6 \" + (aDog1 == oldDog2)); // true\n System.out.println(\" 7 \" + (aDog1 == oldDog)); // false\n System.out.println(\" 8 \" + (aDog == oldDog2)); // false\n }\n\n /**\n * \n * @param d\n */\n public static void foo(Dog d) {\n System.out.println(d.getName().equals(\"Max\")); // true\n\n d.setName(\"moron\");\n\n d = new Dog(\"huahua\");\n System.out.println(\" -:- \" + d.getName().equals(\"huahua\")); // true\n }\n\n /**\n * \n * @param d\n * @param a\n */\n public static void foo(Dog d, int a) {\n d.getName().equals(\"Max\"); // true\n\n d.setName(\"huahua\");\n }\n\n /**\n * \n * @param d\n * @param a\n * @param b\n * @return\n */\n public static Dog foo(Dog d, int a, int b) {\n d.getName().equals(\"Max\"); // true\n d.setName(\"huahua\");\n return d;\n }\n}\n"
},
{
"answer_id": 57616177,
"author": "grindlewald",
"author_id": 10240338,
"author_profile": "https://Stackoverflow.com/users/10240338",
"pm_score": 3,
"selected": false,
"text": "Book book = new Book(\"Effective Java\");\n"
},
{
"answer_id": 58038425,
"author": "Rose",
"author_id": 11725130,
"author_profile": "https://Stackoverflow.com/users/11725130",
"pm_score": 2,
"selected": false,
"text": "String name=\"Mehrose\"; // name referencing to 100\n\nChangeContenet(String name){\n name=\"Michael\"; // refernce has changed to 1001\n\n} \nSystem.out.print(name); //displays Mehrose\n"
},
{
"answer_id": 58704042,
"author": "DeC",
"author_id": 7888956,
"author_profile": "https://Stackoverflow.com/users/7888956",
"pm_score": 3,
"selected": false,
"text": "public void badSwap(int var1, int var2)\n{\n int temp = var1;\n var1 = var2;\n var2 = temp;\n}\n"
},
{
"answer_id": 64289407,
"author": "Alexandr",
"author_id": 511804,
"author_profile": "https://Stackoverflow.com/users/511804",
"pm_score": 2,
"selected": false,
"text": "pass-by-reference"
},
{
"answer_id": 64409378,
"author": "Duleepa Wickramasinghe",
"author_id": 6582191,
"author_profile": "https://Stackoverflow.com/users/6582191",
"pm_score": 3,
"selected": false,
"text": "public class ObjectReferenceExample {\n\n public static void main(String... doYourBest) {\n Student student = new Student();\n transformIntoHomer(student);\n System.out.println(student.name);\n }\n\n static void transformIntoDuleepa(Student student) {\n student.name = \"Duleepa\";\n }\n}\nclass Student {\n String name;\n}\n"
},
{
"answer_id": 64946506,
"author": "Pallav Khare",
"author_id": 11913248,
"author_profile": "https://Stackoverflow.com/users/11913248",
"pm_score": 3,
"selected": false,
"text": "public class PassByValue {\n public static void main(String[] args) {\n Test t = new Test();\n t.name = \"initialvalue\";\n new PassByValue().changeValue(t);\n System.out.println(t.name);\n }\n \n public void changeValue(Test f) {\n f.name = \"changevalue\";\n }\n}\n\nclass Test {\n String name;\n}\n"
},
{
"answer_id": 65460603,
"author": "jack",
"author_id": 8932910,
"author_profile": "https://Stackoverflow.com/users/8932910",
"pm_score": 4,
"selected": false,
"text": "pass by value"
},
{
"answer_id": 66523582,
"author": "charles",
"author_id": 4086871,
"author_profile": "https://Stackoverflow.com/users/4086871",
"pm_score": 2,
"selected": false,
"text": "void swap(int& a, int& b) \n{\n int tmp = a; \n a = b; \n b = tmp; \n}\n"
},
{
"answer_id": 66649532,
"author": "Alex de Kruijff",
"author_id": 12486085,
"author_profile": "https://Stackoverflow.com/users/12486085",
"pm_score": 1,
"selected": false,
"text": "Point p = Point(4,5);\n"
},
{
"answer_id": 67232841,
"author": "v010dya",
"author_id": 2893496,
"author_profile": "https://Stackoverflow.com/users/2893496",
"pm_score": -1,
"selected": false,
"text": "public class Test\n{\n private static void needValue(SomeObject so) throws CloneNotSupportedException\n {\n SomeObject internalObject = so.clone();\n so=null;\n \n // now we can edit internalObject safely.\n internalObject.set(999);\n }\n public static void main(String[] args)\n {\n SomeObject o = new SomeObject(5);\n System.out.println(o);\n try\n {\n needValue(o);\n }\n catch(CloneNotSupportedException e)\n {\n System.out.println(\"Apparently we cannot clone this\");\n }\n System.out.println(o);\n }\n}\n\npublic class SomeObject implements Cloneable\n{\n private int val;\n public SomeObject(int val)\n {\n this.val = val;\n }\n public void set(int val)\n {\n this.val = val;\n }\n public SomeObject clone()\n {\n return new SomeObject(val);\n }\n public String toString()\n {\n return Integer.toString(val);\n }\n}\n"
},
{
"answer_id": 67294696,
"author": "frostcs",
"author_id": 1027385,
"author_profile": "https://Stackoverflow.com/users/1027385",
"pm_score": 3,
"selected": false,
"text": "pass reference by value"
},
{
"answer_id": 69063599,
"author": "Sam Ginrich",
"author_id": 9437799,
"author_profile": "https://Stackoverflow.com/users/9437799",
"pm_score": 1,
"selected": false,
"text": "byte, char, short, int, long float, double"
},
{
"answer_id": 70586240,
"author": "Sam Ginrich",
"author_id": 9437799,
"author_profile": "https://Stackoverflow.com/users/9437799",
"pm_score": -1,
"selected": false,
"text": "/**\n * \n * @author Sam Ginrich\n * \n * All Rights Reserved!\n * \n */\npublic class JavaIsPassByValue\n{\n\n static class SomeClass\n {\n int someValue;\n\n public SomeClass(int someValue)\n {\n this.someValue = someValue;\n }\n }\n\n static void passReferenceByValue(SomeClass someObject)\n {\n if (someObject == null)\n {\n throw new NullPointerException(\n \"This Object Reference was passed by Value,\\r\\n that's why you don't get a value from it.\");\n }\n someObject.someValue = 49;\n }\n\n public static void main(String[] args)\n {\n SomeClass someObject = new SomeClass(27);\n System.out.println(\"Here is the original value: \" + someObject.someValue);\n\n passReferenceByValue(someObject);\n System.out.println(\n \"\\nAs ´Java is pass by value´,\\r\\n everything without exception is passed by value\\r\\n and so an object's attribute cannot change: \"\n + someObject.someValue);\n\n System.out.println();\n passReferenceByValue(null);\n }\n"
},
{
"answer_id": 70791100,
"author": "Alexander Kalinowski",
"author_id": 17676158,
"author_profile": "https://Stackoverflow.com/users/17676158",
"pm_score": -1,
"selected": false,
"text": "int"
},
{
"answer_id": 73769927,
"author": "ADITYA AHLAWAT",
"author_id": 15142774,
"author_profile": "https://Stackoverflow.com/users/15142774",
"pm_score": -1,
"selected": false,
"text": "public class Main \n{ \n public static void main(String[] args)\n { \n //Original value of 'x' will remain unchanged \n // in case of call-by-value \n \n int x = 5;\n System.out.println( \"Value of x before call-by-value: \" + x);\n // 5\n\n processData(x);\n System.out.println(\"Value of x after call-by-value: \" + x);\n // 5\n }\n public static void processData(int x) \n { \n x=x+10; \n }\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40480",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4315/"
] |
40,511
|
<p>As the title already states, I'm trying to declare a nested function and return a pointer to that function. I want this function 'not' to return a new function pointer which will return the negation of whatever the original function was.</p>
<p>Here is what I have:</p>
<pre><code>someType not( someType original ) {
int isNot( ListEntry* entry ) {
return !original( entry );
}
someType resultFunc = calloc( 1024, 1 );
memcpy( resultFunc, &isNot, 1024 );
return resultFunc;
}
</code></pre>
<p>someType is defined as:</p>
<pre><code>typedef int(*someType)(ListEntry* entry)
</code></pre>
|
[
{
"answer_id": 40537,
"author": "Steve Willard",
"author_id": 402,
"author_profile": "https://Stackoverflow.com/users/402",
"pm_score": 0,
"selected": false,
"text": "-fnested-functions\n"
},
{
"answer_id": 40757,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "someType resultFunc = calloc( 1024, 1 );\nmemcpy( resultFunc, &isNot, 1024 );\n"
},
{
"answer_id": 525951,
"author": "Logan Capaldo",
"author_id": 61289,
"author_profile": "https://Stackoverflow.com/users/61289",
"pm_score": 1,
"selected": false,
"text": "#define FN_NOT(F) !F\n#define notSomeFunc FN_NOT(someFunc)\n...\nx = notSomeFunc(entry);\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/402/"
] |
40,525
|
<p>I'm trying to call a function after I load some XML into Actionscript, and I'm just wondering how I call that function. Example:</p>
<pre><code>//Function Declarations
function parentFunction()
{
function callMe()
{
textField.text = "lawl";
}
}
</code></pre>
<p>Now, <strong>how do I call the "callMe()" function</strong> in a different part of the code, like an onRelease function?</p>
<pre><code>on(release)
{
callMe(); //doesn't work
parentFunction().callMe(); //doesn't work
parentFunction.callMe(); //doesn't work
}
</code></pre>
<p>ActionScript 2.0 is just so wonky! Any ideas?</p>
|
[
{
"answer_id": 113517,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var bar = function()\n{\n trace(\"bar\");\n};\n\nbar.call();\n"
},
{
"answer_id": 286276,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "//v--- on the frame\nfunction callMe(){\ntextArea.text='lawl';\n}\n//v---- for button\non(release){\ncallMe();\n}\n\n--- or -----\n"
},
{
"answer_id": 3237366,
"author": "freak_ts",
"author_id": 390454,
"author_profile": "https://Stackoverflow.com/users/390454",
"pm_score": 0,
"selected": false,
"text": "function SetMethod(Method:Function){\n //trace(Method.call()); \n //or something like:\n testbtn1.addEventListener(MouseEvent.CLICK, Method);\n testbtn2.addEventListener(MouseEvent.CLICK, Method);\n testbtn3.addEventListener(MouseEvent.CLICK, Method);\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/557/"
] |
40,535
|
<p>I need to determine if I'm on a particular view. My use case is that I'd like to decorate navigation elements with an "on" class for the current view. Is there a built in way of doing this?</p>
|
[
{
"answer_id": 40538,
"author": "Jim Geurts",
"author_id": 3085,
"author_profile": "https://Stackoverflow.com/users/3085",
"pm_score": 2,
"selected": false,
"text": "public static class UrlHelperExtensions\n{\n /// <summary>\n /// Determines if the current view equals the specified action\n /// </summary>\n /// <typeparam name=\"TController\">The type of the controller.</typeparam>\n /// <param name=\"helper\">Url Helper</param>\n /// <param name=\"action\">The action to check.</param>\n /// <returns>\n /// <c>true</c> if the specified action is the current view; otherwise, <c>false</c>.\n /// </returns>\n public static bool IsAction<TController>(this UrlHelper helper, LambdaExpression action) where TController : Controller\n {\n MethodCallExpression call = action.Body as MethodCallExpression;\n if (call == null)\n {\n throw new ArgumentException(\"Expression must be a method call\", \"action\");\n }\n\n return (call.Method.Name.Equals(helper.ViewContext.ViewName, StringComparison.OrdinalIgnoreCase) &&\n typeof(TController) == helper.ViewContext.Controller.GetType());\n }\n\n /// <summary>\n /// Determines if the current view equals the specified action\n /// </summary>\n /// <param name=\"helper\">Url Helper</param>\n /// <param name=\"actionName\">Name of the action.</param>\n /// <returns>\n /// <c>true</c> if the specified action is the current view; otherwise, <c>false</c>.\n /// </returns>\n public static bool IsAction(this UrlHelper helper, string actionName)\n {\n if (String.IsNullOrEmpty(actionName))\n {\n throw new ArgumentException(\"Please specify the name of the action\", \"actionName\");\n }\n string controllerName = helper.ViewContext.RouteData.GetRequiredString(\"controller\");\n return IsAction(helper, actionName, controllerName);\n }\n\n /// <summary>\n /// Determines if the current view equals the specified action\n /// </summary>\n /// <param name=\"helper\">Url Helper</param>\n /// <param name=\"actionName\">Name of the action.</param>\n /// <param name=\"controllerName\">Name of the controller.</param>\n /// <returns>\n /// <c>true</c> if the specified action is the current view; otherwise, <c>false</c>.\n /// </returns>\n public static bool IsAction(this UrlHelper helper, string actionName, string controllerName)\n {\n if (String.IsNullOrEmpty(actionName))\n {\n throw new ArgumentException(\"Please specify the name of the action\", \"actionName\");\n }\n if (String.IsNullOrEmpty(controllerName))\n {\n throw new ArgumentException(\"Please specify the name of the controller\", \"controllerName\");\n }\n\n if (!controllerName.EndsWith(\"Controller\", StringComparison.OrdinalIgnoreCase))\n {\n controllerName = controllerName + \"Controller\";\n }\n\n bool isOnView = helper.ViewContext.ViewName.SafeEquals(actionName, StringComparison.OrdinalIgnoreCase);\n return isOnView && helper.ViewContext.Controller.GetType().Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase);\n }\n}\n"
},
{
"answer_id": 45103,
"author": "Matt Hinze",
"author_id": 2676,
"author_profile": "https://Stackoverflow.com/users/2676",
"pm_score": 1,
"selected": false,
"text": " [NavigationLocationFilter(\"Products\")]\n public ViewResult List()\n {\n return View();\n }\n"
},
{
"answer_id": 2745475,
"author": "memical",
"author_id": 322622,
"author_profile": "https://Stackoverflow.com/users/322622",
"pm_score": 4,
"selected": true,
"text": "public static bool IsCurrentAction(this HtmlHelper helper, string actionName, string controllerName)\n {\n string currentControllerName = (string)helper.ViewContext.RouteData.Values[\"controller\"];\n string currentActionName = (string)helper.ViewContext.RouteData.Values[\"action\"];\n\n if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) && currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))\n return true;\n\n return false;\n }\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40535",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3085/"
] |
40,545
|
<p>Is there is any way to change the datasource location for a report and all of it's subreports without having to open each of them manually?</p>
|
[
{
"answer_id": 41979,
"author": "Jas",
"author_id": 777,
"author_profile": "https://Stackoverflow.com/users/777",
"pm_score": 3,
"selected": false,
"text": " #'SET REPORT CONNECTION INFO\n For i = 0 To rsource.ReportDocument.DataSourceConnections.Count - 1\n rsource.ReportDocument.DataSourceConnections(i).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)\n Next\n\n For i = 0 To rsource.ReportDocument.Subreports.Count - 1\n For x = 0 To rsource.ReportDocument.Subreports(i).DataSourceConnections.Count - 1\n rsource.ReportDocument.OpenSubreport(rsource.ReportDocument.Subreports(i).Name).DataSourceConnections(x).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword)\n Next\n Next\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4286/"
] |
40,568
|
<p>Are square brackets in URLs allowed?</p>
<p>I noticed that <a href="http://hc.apache.org/httpclient-3.x/index.html" rel="noreferrer">Apache commons HttpClient</a> (3.0.1) throws an IOException, wget and Firefox however accept square brackets.</p>
<p>URL example:</p>
<pre><code>http://example.com/path/to/file[3].html
</code></pre>
<p>My HTTP client encounters such URLs but I'm not sure whether to patch the code or to throw an exception (as it actually should be).</p>
|
[
{
"answer_id": 1718238,
"author": "MM.",
"author_id": 126603,
"author_profile": "https://Stackoverflow.com/users/126603",
"pm_score": 4,
"selected": false,
"text": "http://www.example.com/foo.php?bar[]=1&bar[]=2&bar[]=3\n"
},
{
"answer_id": 44901804,
"author": "oHo",
"author_id": 938111,
"author_profile": "https://Stackoverflow.com/users/938111",
"pm_score": 5,
"selected": false,
"text": "["
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4308/"
] |
40,577
|
<p>In Ruby, I'm trying to do the following.</p>
<pre><code>def self.stats(since)
return Events.find(:all, :select => 'count(*) as this_count', :conditions => ['Date(event_date) >= ?', (Time.now - since)]).first.this_count
end
</code></pre>
<p>where "since" is a string representing an amount of time ('1 hour', '1 day', '3 days') and so on. Any suggestions?</p>
|
[
{
"answer_id": 40822,
"author": "Wieczo",
"author_id": 4195,
"author_profile": "https://Stackoverflow.com/users/4195",
"pm_score": 3,
"selected": true,
"text": "require 'active_support'\n\ndef string_to_date(date_string)\n parts = date_string.split\n return parts[0].to_i.send(parts[1])\nend\nsinces = ['1 hour', '1 day', '3 days']\n\nsinces.each do |since|\n puts \"#{since} ago: #{string_to_date(since).ago(Time.now)}\"\nend\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4322/"
] |
40,590
|
<p>Both the jQuery and Prototpye JavaScript libraries refuse to allow me to use a variable to select an list item element by index number although they accept a hard coded number. </p>
<p>For example, in Prototype this works:</p>
<pre><code>$$('li')[5].addClassName('active');
</code></pre>
<p>But this will not work no matter how I try to cast the variable as a number or integer:</p>
<pre><code>$$('li')[currentPage].addClassName('active');
</code></pre>
<p>In jQuery I get similar weirdness. This will work:</p>
<pre><code>jQuery('li').eq(5).addClass("active");
</code></pre>
<p>But this will not work again even though the value of currentPage is 5 and its type is number:</p>
<pre><code>jQuery('li').eq(currentPage).addClass("active");
</code></pre>
<p>I'm trying to create a JavaScript pagination system and I need to set the class on the active page button. The list item elements are created dynamically depending upon the number of pages I need.</p>
|
[
{
"answer_id": 40599,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "currentPage"
},
{
"answer_id": 40800,
"author": "user2601",
"author_id": 2601,
"author_profile": "https://Stackoverflow.com/users/2601",
"pm_score": 3,
"selected": true,
"text": "jQuery('#pagination-digg li').eq(currentPage).addClass(\"active\");\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4320/"
] |
40,602
|
<p>What kind of programming problems are state machines most suited for?</p>
<p>I have read about parsers being implemented using state machines, but would like to find out about problems that scream out to be implemented as a state machine.</p>
|
[
{
"answer_id": 40645,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 3,
"selected": false,
"text": "enum states{reset,initsend, initresponse, waitonsignal,dial,ppp,...}\nmodemfunction()\n{\n static currentstate\n\n switch(currentstate)\n {\n case reset:\n Do reset\n if reset was successful, nextstate=init else nextstate = reset\n break\n case initsend\n send \"ATD\"\n nextstate = initresponse \n break\n ...\n }\ncurrentstate=nextstate\n}\n"
},
{
"answer_id": 40747,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 5,
"selected": true,
"text": "player entered room"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1583/"
] |
40,608
|
<p>I've been using PHP for too long, but I'm new to JavaScript integration in some places. </p>
<p>I'm trying to find the fastest way to pass database information into a page where it can be modified and displayed dynamically in JavaScript. </p>
<p>Right now, I'm looking at loading a <em>JSON with PHP</em> echo statements because it's fast and effective, but I saw that I could use PHP's JSON library (PHP 5.2). </p>
<p><strong>Has anybody tried the new JSON library, and is it better than my earlier method?</strong></p>
|
[
{
"answer_id": 166701,
"author": "Sean",
"author_id": 5446,
"author_profile": "https://Stackoverflow.com/users/5446",
"pm_score": 2,
"selected": false,
"text": "function my_json_encode($row) {\n $json = \"{\";\n $keys = array_keys($row);\n $i=1;\n foreach ($keys as $key) {\n if ($i>1) $json .= ',';\n $json .= '\"'.addslashes($key).'\":\"'.addslashes($row[$key]).'\"';\n $i++;\n }\n $json .= \"}\";\n return $json;\n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40608",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4247/"
] |
40,632
|
<p>What are they and what are they good for?</p>
<p>I do not have a CS degree and my background is VB6 -> ASP -> ASP.NET/C#. Can anyone explain it in a clear and concise manner?</p>
|
[
{
"answer_id": 40736,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 3,
"selected": false,
"text": "(define (fork)\n (display \"forking\\n\")\n (call-with-current-continuation\n (lambda (cc)\n (enqueue (lambda ()\n (cc #f)))\n (cc #t))))\n\n(define (context-switch)\n (display \"context switching\\n\")\n (call-with-current-continuation\n (lambda (cc)\n (enqueue\n (lambda ()\n (cc 'nothing)))\n ((dequeue)))))\n\n(define (end-process)\n (display \"ending process\\n\")\n (let ((proc (dequeue)))\n (if (eq? proc 'queue-empty)\n (display \"all processes terminated\\n\")\n (proc))))\n"
},
{
"answer_id": 389940,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 4,
"selected": false,
"text": "try:\n broken_function()\nexcept SomeException:\n # jump to here\n pass\n\ndef broken_function():\n raise SomeException() # go back up the stack\n # stuff that won't be evaluated\n"
},
{
"answer_id": 396691,
"author": "Rich Dougherty",
"author_id": 49630,
"author_profile": "https://Stackoverflow.com/users/49630",
"pm_score": 2,
"selected": false,
"text": "return"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40632",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1583/"
] |
40,637
|
<p>I'm building an excel template (*.xlt) for a user here, and one of the things I want to do is have it insert the current date when a new document is created (ie, when they double-click the file in windows explorer). How do I do this?</p>
<p><strong>Update:</strong> I should have added that I would prefer not to use any vba (macro). If that's the only option, then so be it, but I'd really like to avoid forcing my user to remember to click some 'allow macro content' button.</p>
|
[
{
"answer_id": 40674,
"author": "1729",
"author_id": 4319,
"author_profile": "https://Stackoverflow.com/users/4319",
"pm_score": 2,
"selected": false,
"text": "Book.xlt"
},
{
"answer_id": 40785,
"author": "Graham",
"author_id": 1826,
"author_profile": "https://Stackoverflow.com/users/1826",
"pm_score": 3,
"selected": true,
"text": "Private Sub Workbook_Open()\n ThisWorkbook.Worksheets(\"Sheet1\").Range(\"A1\").Value = Date\nEnd Sub\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] |
40,651
|
<p>I've inherited a large VB6 app at my current workplace. I'm kinda learning VB6 on the job and there are a number of problems I'm having. The major issue at the moment is I can't figure out how to check if a key exists in a Collection object. Can anyone help?</p>
|
[
{
"answer_id": 40659,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 3,
"selected": false,
"text": "public function keyExists(myCollection as collection, sKey as string) as Boolean\n on error goto handleerror:\n\n dim val as variant\n\n val = myCollection(sKey)\n keyExists = true\n exit sub\nhandleerror:\n keyExists = false\nend function\n"
},
{
"answer_id": 40751,
"author": "Tom Mayfield",
"author_id": 2314,
"author_profile": "https://Stackoverflow.com/users/2314",
"pm_score": 5,
"selected": false,
"text": "Public Function Exists(col, index) As Boolean\nOn Error GoTo ExistsTryNonObject\n Dim o As Object\n\n Set o = col(index)\n Exists = True\n Exit Function\n\nExistsTryNonObject:\n Exists = ExistsNonObject(col, index)\nEnd Function\n\nPrivate Function ExistsNonObject(col, index) As Boolean\nOn Error GoTo ExistsNonObjectErrorHandler\n Dim v As Variant\n\n v = col(index)\n ExistsNonObject = True\n Exit Function\n\nExistsNonObjectErrorHandler:\n ExistsNonObject = False\nEnd Function\n"
},
{
"answer_id": 40831,
"author": "jevakallio",
"author_id": 4333,
"author_profile": "https://Stackoverflow.com/users/4333",
"pm_score": 3,
"selected": false,
"text": "Public Function Exists(ByVal key As Variant, ByRef col As Collection) As Boolean\n\n'Returns True if item with key exists in collection\n\nOn Error Resume Next\n\nConst ERR_OBJECT_TYPE As Long = 438\nDim item As Variant\n\n'Try reach item by key\nitem = col.item(key)\n\n'If no error occurred, key exists\nIf Err.Number = 0 Then\n Exists = True\n\n'In cases where error 438 is thrown, it is likely that\n'the item does exist, but is an object that cannot be Let\nElseIf Err.Number = ERR_OBJECT_TYPE Then\n\n 'Try reach object by key\n Set item = col.item(key)\n\n 'If an object was found, the key exists\n If Not item Is Nothing Then\n Exists = True\n End If\n\nEnd If\n\nErr.Clear\n\nEnd Function\n"
},
{
"answer_id": 883192,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "public Function TryGet(key as string, col as collection) as Variant\n on error goto errhandler\n Set TryGet= col(key)\n exit function\nerrhandler:\n Set TryGet = nothing \nend function\n"
},
{
"answer_id": 1825403,
"author": "Vijay",
"author_id": 107537,
"author_profile": "https://Stackoverflow.com/users/107537",
"pm_score": 2,
"selected": false,
"text": "Option Explicit\n\n'Purpose : Determines if an item already exists in a collection\n'Inputs : oCollection The collection to test for the existance of the item\n' vIndex The index of the item.\n' [vItem] See Outputs\n'Outputs : Returns True if the item already exists in the collection.\n' [vItem] The value of the item, if it exists, else returns \"empty\".\n'Notes :\n'Example :\n\nFunction CollectionItemExists(vIndex As Variant, oCollection As Collection, Optional vItem As Variant) As Boolean\n On Error GoTo ErrNotExist\n\n 'Clear output result\n If IsObject(vItem) Then\n Set vItem = Nothing\n Else\n vItem = Empty\n End If\n\n If VarType(vIndex) = vbString Then\n 'Test if item exists\n If VarType(oCollection.Item(CStr(vIndex))) = vbObject Then\n 'Return an object\n Set vItem = oCollection.Item(CStr(vIndex))\n Else\n 'Return an standard variable\n vItem = oCollection.Item(CStr(vIndex))\n End If\n Else\n 'Test if item exists\n If VarType(oCollection.Item(Int(vIndex))) = vbObject Then\n 'Return an object\n Set vItem = oCollection.Item(Int(vIndex))\n Else\n 'Return an standard variable\n vItem = oCollection.Item(Int(vIndex))\n End If\n End If\n 'Return success\n CollectionItemExists = True\n Exit Function\nErrNotExist:\n CollectionItemExists = False\n On Error GoTo 0\nEnd Function\n\n'Demonstration routine\nSub Test()\n Dim oColl As New Collection, oValue As Variant\n\n oColl.Add \"red1\", \"KEYA\"\n oColl.Add \"red2\", \"KEYB\"\n 'Return the two items in the collection\n Debug.Print CollectionItemExists(\"KEYA\", oColl, oValue)\n Debug.Print \"Returned: \" & oValue\n Debug.Print \"-----------\"\n Debug.Print CollectionItemExists(2, oColl, oValue)\n Debug.Print \"Returned: \" & oValue\n 'Should fail\n Debug.Print CollectionItemExists(\"KEYC\", oColl, oValue)\n Debug.Print \"Returned: \" & oValue\n Set oColl = Nothing\nEnd Sub\n"
},
{
"answer_id": 1825433,
"author": "Christian Hayter",
"author_id": 115413,
"author_profile": "https://Stackoverflow.com/users/115413",
"pm_score": 5,
"selected": false,
"text": "Public Function Exists(ByVal oCol As Collection, ByVal vKey As Variant) As Boolean\n\n On Error Resume Next\n oCol.Item vKey\n Exists = (Err.Number = 0)\n Err.Clear\n\nEnd Function\n"
},
{
"answer_id": 9535221,
"author": "R. van Drie",
"author_id": 1245312,
"author_profile": "https://Stackoverflow.com/users/1245312",
"pm_score": 2,
"selected": false,
"text": "Public Function Exists(col, index) As Boolean\nDim v As Variant\n\nTryObject:\n On Error GoTo ExistsTryObject\n Set v = col(index)\n Exists = True\n Exit Function\n\nTryNonObject:\n On Error GoTo ExistsTryNonObject\n\n v = col(index)\n Exists = True\n Exit Function\n\nExistsTryObject:\n ' This will reset your Err Handler\n Resume TryNonObject\n\nExistsTryNonObject:\n Exists = False\nEnd Function\n"
},
{
"answer_id": 15221341,
"author": "Martin",
"author_id": 1261136,
"author_profile": "https://Stackoverflow.com/users/1261136",
"pm_score": 0,
"selected": false,
"text": "Public Function Exists(ByRef Col As Collection, ByVal Key) As Boolean\n On Error GoTo KeyError\n If Not Col(Key) Is Nothing Then\n Exists = True\n Else\n Exists = False\n End If\n\n Exit Function\nKeyError:\n Err.Clear\n Exists = False\nEnd Function\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4315/"
] |
40,663
|
<p>I'm trying to find a way to validate a large XML file against an XSD. I saw the question <a href="https://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file">...best way to validate an XML...</a> but the answers all pointed to using the Xerces library for validation. The only problem is, when I use that library to validate a 180 MB file then I get an OutOfMemoryException.</p>
<p>Are there any other tools,libraries, strategies for validating a larger than normal XML file?</p>
<p>EDIT: The SAX solution worked for java validation, but the other two suggestions for the libxml tool were very helpful as well for validation outside of java.</p>
|
[
{
"answer_id": 40678,
"author": "jodonnell",
"author_id": 4223,
"author_profile": "https://Stackoverflow.com/users/4223",
"pm_score": 6,
"selected": true,
"text": "SAXParserFactory factory = SAXParserFactory.newInstance();\nfactory.setValidating(true);\nfactory.setNamespaceAware(true);\n\nSAXParser parser = factory.newSAXParser();\n\nXMLReader reader = parser.getXMLReader();\nreader.setErrorHandler(new SimpleErrorHandler());\nreader.parse(new InputSource(new FileReader (\"document.xml\")));\n"
},
{
"answer_id": 628133,
"author": "GaZ",
"author_id": 62667,
"author_profile": "https://Stackoverflow.com/users/62667",
"pm_score": 1,
"selected": false,
"text": "java -Xmx512m com.foo.MyClass"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3274/"
] |
40,665
|
<p>I'm maintaining some code that uses a *= operator in a query to a Sybase database and I can't find documentation on it. Does anyone know what *= does? I assume that it is some sort of a join.</p>
<pre><code>select * from a, b where a.id *= b.id</code></pre>
<p>I can't figure out how this is different from:</p>
<pre><code>select * from a, b where a.id = b.id</code></pre>
|
[
{
"answer_id": 40671,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 3,
"selected": false,
"text": "*= is LEFT JOIN and =* is RIGHT JOIN.\n"
},
{
"answer_id": 40698,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 3,
"selected": false,
"text": "SELECT *\nFROM a\nLEFT JOIN b ON b.id=a.id\n"
},
{
"answer_id": 40700,
"author": "Adam Tegen",
"author_id": 4066,
"author_profile": "https://Stackoverflow.com/users/4066",
"pm_score": 1,
"selected": false,
"text": "select * from a, b where a.id = b.id"
},
{
"answer_id": 40702,
"author": "jason saldo",
"author_id": 1293,
"author_profile": "https://Stackoverflow.com/users/1293",
"pm_score": 3,
"selected": false,
"text": "select \n * \nfrom \n a\n , b \n\nwhere \n a.id *= b.id\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4066/"
] |
40,680
|
<p>I need to be able to get at the full URL of the page I am on from a user control. Is it just a matter of concatenating a bunch of Request variables together? If so which ones? Or is there a more simpiler way?</p>
|
[
{
"answer_id": 40693,
"author": "Christian Hagelid",
"author_id": 202,
"author_profile": "https://Stackoverflow.com/users/202",
"pm_score": 3,
"selected": false,
"text": "Request.ServerVariables(\"HTTPS\") // to check if it's HTTP or HTTPS\nRequest.ServerVariables(\"SERVER_NAME\") \nRequest.ServerVariables(\"SCRIPT_NAME\") \nRequest.ServerVariables(\"QUERY_STRING\")\n"
},
{
"answer_id": 40718,
"author": "RedWolves",
"author_id": 648,
"author_profile": "https://Stackoverflow.com/users/648",
"pm_score": 3,
"selected": false,
"text": "\"http://\" + Request.ServerVariables[\"SERVER_NAME\"] + Request.RawUrl.ToString()\n"
},
{
"answer_id": 41149,
"author": "travis",
"author_id": 1414,
"author_profile": "https://Stackoverflow.com/users/1414",
"pm_score": 8,
"selected": true,
"text": "Request.Url.ToString()"
},
{
"answer_id": 41199,
"author": "DevelopingChris",
"author_id": 1220,
"author_profile": "https://Stackoverflow.com/users/1220",
"pm_score": 6,
"selected": false,
"text": "Request.Url.AbsoluteUri\n"
},
{
"answer_id": 20353567,
"author": "IonB",
"author_id": 3061797,
"author_profile": "https://Stackoverflow.com/users/3061797",
"pm_score": 1,
"selected": false,
"text": "Request.Url.Authority\n"
},
{
"answer_id": 21226409,
"author": "Mohsen",
"author_id": 1989454,
"author_profile": "https://Stackoverflow.com/users/1989454",
"pm_score": 8,
"selected": false,
"text": "Request.ApplicationPath : /virtual_dir\nRequest.CurrentExecutionFilePath : /virtual_dir/webapp/page.aspx\nRequest.FilePath : /virtual_dir/webapp/page.aspx\nRequest.Path : /virtual_dir/webapp/page.aspx\nRequest.PhysicalApplicationPath : d:\\Inetpub\\wwwroot\\virtual_dir\\\nRequest.QueryString : /virtual_dir/webapp/page.aspx?q=qvalue\nRequest.Url.AbsolutePath : /virtual_dir/webapp/page.aspx\nRequest.Url.AbsoluteUri : http://localhost:2000/virtual_dir/webapp/page.aspx?q=qvalue\nRequest.Url.Host : localhost\nRequest.Url.Authority : localhost:80\nRequest.Url.LocalPath : /virtual_dir/webapp/page.aspx\nRequest.Url.PathAndQuery : /virtual_dir/webapp/page.aspx?q=qvalue\nRequest.Url.Port : 80\nRequest.Url.Query : ?q=qvalue\nRequest.Url.Scheme : http\nRequest.Url.Segments : /\n virtual_dir/\n webapp/\n page.aspx\n"
},
{
"answer_id": 22373623,
"author": "Artem",
"author_id": 1713814,
"author_profile": "https://Stackoverflow.com/users/1713814",
"pm_score": 3,
"selected": false,
"text": "Request.Url.OriginalString"
},
{
"answer_id": 46311534,
"author": "Serj Sagan",
"author_id": 550975,
"author_profile": "https://Stackoverflow.com/users/550975",
"pm_score": 5,
"selected": false,
"text": "ASP.NET Core"
},
{
"answer_id": 54899250,
"author": "Abhishek Kanrar",
"author_id": 8520016,
"author_profile": "https://Stackoverflow.com/users/8520016",
"pm_score": 1,
"selected": false,
"text": "var FullUrl = Request.Url.AbsolutePath.ToString();\nvar ID = FullUrl.Split('/').Last();\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/648/"
] |
40,692
|
<p>Is it possible to create a REST web service using ASP.NET 2.0? The articles and blog entries I am finding all seem to indicate that ASP.NET 3.5 with WCF is required to create REST web services with ASP.NET.</p>
<p>If it is possible to create REST web services in ASP.NET 2.0 can you provide an example.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 40728,
"author": "Nathan Lee",
"author_id": 3453,
"author_profile": "https://Stackoverflow.com/users/3453",
"pm_score": 4,
"selected": true,
"text": "protected void PageLoad(object sender, EventArgs e)\n{\n using (XmlWriter xm = XmlWriter.Create(Response.OutputStream, GetXmlSettings()))\n {\n //do your stuff\n xm.Flush();\n }\n}\n\n /// <summary>\n /// Create Xml Settings object to properly format the output of the xml doc.\n /// </summary>\n private static XmlWriterSettings GetXmlSettings()\n {\n XmlWriterSettings xmlSettings = new XmlWriterSettings();\n xmlSettings.Indent = true;\n xmlSettings.IndentChars = \" \";\n return xmlSettings;\n }\n"
},
{
"answer_id": 41151,
"author": "jdiaz",
"author_id": 831,
"author_profile": "https://Stackoverflow.com/users/831",
"pm_score": 2,
"selected": false,
"text": "<webHttp />"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3498/"
] |
40,703
|
<p>It will be important for developers wanting to develop for the chrome browser to be able to review existing bugs (to avoid too much pulling-out of hair), and to add new ones (to improve the thing). Yet I can't seem to find the bug tracking for this project. It <em>is</em> open source, right?</p>
|
[
{
"answer_id": 36502481,
"author": "kenorb",
"author_id": 55075,
"author_profile": "https://Stackoverflow.com/users/55075",
"pm_score": 3,
"selected": false,
"text": "bugs.chromium.org"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
40,705
|
<p>At the beginning of all my executable Python scripts I put the <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)" rel="noreferrer">shebang</a> line:</p>
<pre><code>#!/usr/bin/env python
</code></pre>
<p>I'm running these scripts on a system where <code>env python</code> yields a Python 2.2 environment. My scripts quickly fail because I have a manual check for a compatible Python version:</p>
<pre><code>if sys.version_info < (2, 4):
raise ImportError("Cannot run with Python version < 2.4")
</code></pre>
<p>I don't want to have to change the shebang line on every executable file, if it's possible; however, I don't have administrative access to the machine to change the result of <code>env python</code> and I don't want to force a particular version, as in:</p>
<pre><code>#!/usr/bin/env python2.4
</code></pre>
<p>I'd like to avoid this because system may have a newer version than Python 2.4, or may have Python 2.5 but no Python 2.4.</p>
<p>What's the elegant solution?</p>
<p>[Edit:] I wasn't specific enough in posing the question -- I'd like to let users execute the scripts without manual configuration (e.g. path alteration or symlinking in <code>~/bin</code> and ensuring your PATH has <code>~/bin</code> before the Python 2.2 path). Maybe some distribution utility is required to prevent the manual tweaks?</p>
|
[
{
"answer_id": 40721,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 2,
"selected": false,
"text": "$ mkdir ~/bin\n$ ln -s `which python2.4` ~/bin/python\n$ export PATH=~/bin:$PATH\n"
},
{
"answer_id": 42516,
"author": "morais",
"author_id": 2846,
"author_profile": "https://Stackoverflow.com/users/2846",
"pm_score": 2,
"selected": false,
"text": "import os\nimport glob\ndef best_python():\n plist = []\n for i in os.getenv(\"PATH\").split(\":\"):\n for j in glob.glob(os.path.join(i, \"python2.[0-9]\")):\n plist.append(os.path.join(i, j))\n plist.sort()\n plist.reverse()\n if len(plist) == 0: return None\n return plist[0]\n"
},
{
"answer_id": 42794,
"author": "cdleary",
"author_id": 3594,
"author_profile": "https://Stackoverflow.com/users/3594",
"pm_score": 0,
"selected": false,
"text": "PATH"
},
{
"answer_id": 19188285,
"author": "Alex Nelson",
"author_id": 1207160,
"author_profile": "https://Stackoverflow.com/users/1207160",
"pm_score": 0,
"selected": false,
"text": "AM_PATH_PYTHON"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
40,716
|
<p>Although the general case is undecidable, many people still do solve problems that are equivilent well enough for day to day use.</p>
<p>In cohen's phd thesis on computer viruses, he showed how virus scanning is equivilent to the halting problem, yet we have an entire industry based around this challenge.</p>
<p>I also have seen microsoft's terminator project - <a href="http://research.microsoft.com/Terminator/" rel="noreferrer">http://research.microsoft.com/Terminator/</a> </p>
<p>Which leads me to ask - is the halting problem overrated - do we need to worry about the general case?</p>
<p>Will types become turing complete over time - dependant types do seem like a good development?</p>
<p>Or, to look the other way, will we begin to use non turing complete languages to gain the benefits of static analysis ?</p>
|
[
{
"answer_id": 40813,
"author": "mweerden",
"author_id": 4285,
"author_profile": "https://Stackoverflow.com/users/4285",
"pm_score": 0,
"selected": false,
"text": "while false do something"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40716",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4319/"
] |
40,730
|
<p>How do you give a C# auto-property an initial value?</p>
<p>I either use the constructor, or revert to the old syntax. </p>
<p><strong> Using the Constructor:</strong></p>
<pre><code>class Person
{
public Person()
{
Name = "Initial Name";
}
public string Name { get; set; }
}
</code></pre>
<p><strong>Using normal property syntax</strong> (with an initial value)</p>
<pre><code>private string name = "Initial Name";
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
</code></pre>
<p>Is there a better way?</p>
|
[
{
"answer_id": 40754,
"author": "Darren Kopp",
"author_id": 77,
"author_profile": "https://Stackoverflow.com/users/77",
"pm_score": 12,
"selected": true,
"text": "public int X { get; set; } = x; // C# 6 or higher\n"
},
{
"answer_id": 40882,
"author": "crucible",
"author_id": 3717,
"author_profile": "https://Stackoverflow.com/users/3717",
"pm_score": 6,
"selected": false,
"text": "class Person\n{\n private string _name; \n public string Name \n { \n get \n {\n return string.IsNullOrEmpty(_name) ? \"Default Name\" : _name;\n } \n\n set { _name = value; } \n }\n}\n"
},
{
"answer_id": 43594,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 8,
"selected": false,
"text": "class Person \n{\n public Person()\n {\n //do anything before variable assignment\n\n //assign initial values\n Name = \"Default Name\";\n\n //do anything after variable assignment\n }\n public string Name { get; set; }\n}\n"
},
{
"answer_id": 44197,
"author": "Lex",
"author_id": 4109,
"author_profile": "https://Stackoverflow.com/users/4109",
"pm_score": 4,
"selected": false,
"text": "public object Foo { get; set; } = bar;\n"
},
{
"answer_id": 3059751,
"author": "ghiboz",
"author_id": 349045,
"author_profile": "https://Stackoverflow.com/users/349045",
"pm_score": 4,
"selected": false,
"text": "using System.ComponentModel;\n\nprivate bool bShowGroup ;\n[Description(\"Show the group table\"), Category(\"Sea\"),DefaultValue(true)]\npublic bool ShowGroup\n{\n get { return bShowGroup; }\n set { bShowGroup = value; }\n}\n"
},
{
"answer_id": 6143989,
"author": "Nag",
"author_id": 771935,
"author_profile": "https://Stackoverflow.com/users/771935",
"pm_score": 0,
"selected": false,
"text": "class Person \n{ \n /// Gets/sets a value indicating whether auto \n /// save of review layer is enabled or not\n [System.ComponentModel.DefaultValue(true)] \n public bool AutoSaveReviewLayer { get; set; }\n}\n"
},
{
"answer_id": 6444527,
"author": "Chuck Rostance",
"author_id": 810915,
"author_profile": "https://Stackoverflow.com/users/810915",
"pm_score": 8,
"selected": false,
"text": "public class DefaultValuesTest\n{ \n public DefaultValuesTest()\n { \n foreach (PropertyDescriptor property in TypeDescriptor.GetProperties(this))\n {\n DefaultValueAttribute myAttribute = (DefaultValueAttribute)property.Attributes[typeof(DefaultValueAttribute)];\n\n if (myAttribute != null)\n {\n property.SetValue(this, myAttribute.Value);\n }\n }\n }\n\n public void DoTest()\n {\n var db = DefaultValueBool;\n var ds = DefaultValueString;\n var di = DefaultValueInt;\n }\n\n\n [System.ComponentModel.DefaultValue(true)]\n public bool DefaultValueBool { get; set; }\n\n [System.ComponentModel.DefaultValue(\"Good\")]\n public string DefaultValueString { get; set; }\n\n [System.ComponentModel.DefaultValue(27)]\n public int DefaultValueInt { get; set; }\n}\n"
},
{
"answer_id": 11738668,
"author": "Zack Jannsen",
"author_id": 1247236,
"author_profile": "https://Stackoverflow.com/users/1247236",
"pm_score": 2,
"selected": false,
"text": "public BaseClassAbstract()\n{\n this.PropertyName = \"Default Name\";\n}\n"
},
{
"answer_id": 14388960,
"author": "introspected",
"author_id": 1988564,
"author_profile": "https://Stackoverflow.com/users/1988564",
"pm_score": 4,
"selected": false,
"text": "[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]\npublic class InstanceAttribute : Attribute\n{\n public bool IsConstructorCall { get; private set; }\n public object[] Values { get; private set; }\n public InstanceAttribute() : this(true) { }\n public InstanceAttribute(object value) : this(false, value) { }\n public InstanceAttribute(bool isConstructorCall, params object[] values)\n {\n IsConstructorCall = isConstructorCall;\n Values = values ?? new object[0];\n }\n}\n"
},
{
"answer_id": 20434213,
"author": "user3076134",
"author_id": 3076134,
"author_profile": "https://Stackoverflow.com/users/3076134",
"pm_score": -1,
"selected": false,
"text": "private bool _SomeFlagSet = false;\npublic bool SomeFlag\n{\n get\n {\n if (!_SomeFlagSet)\n SomeFlag = false; \n\n return SomeFlag;\n }\n set\n {\n if (!_SomeFlagSet)\n _SomeFlagSet = true;\n\n SomeFlag = value; \n }\n}\n"
},
{
"answer_id": 23367865,
"author": "Habib",
"author_id": 961113,
"author_profile": "https://Stackoverflow.com/users/961113",
"pm_score": 5,
"selected": false,
"text": "public string Name { get; set; } = \"Some Name\";\n"
},
{
"answer_id": 25674677,
"author": "FloodMoo",
"author_id": 3710310,
"author_profile": "https://Stackoverflow.com/users/3710310",
"pm_score": 2,
"selected": false,
"text": "public Class ClassName{\n public int PropName{get;set;}\n public ClassName{\n PropName=0; //Default Value\n }\n}\n"
},
{
"answer_id": 38576042,
"author": "Shiva",
"author_id": 325521,
"author_profile": "https://Stackoverflow.com/users/325521",
"pm_score": 6,
"selected": false,
"text": "Class"
},
{
"answer_id": 40325486,
"author": "brakeroo",
"author_id": 7070657,
"author_profile": "https://Stackoverflow.com/users/7070657",
"pm_score": 5,
"selected": false,
"text": "public class Person{\n\n public string FullName => $\"{First} {Last}\"; // expression body notation\n\n public string First { get; set; } = \"First\";\n public string Last { get; set; } = \"Last\";\n}\n"
},
{
"answer_id": 42799414,
"author": "ANewGuyInTown",
"author_id": 2727444,
"author_profile": "https://Stackoverflow.com/users/2727444",
"pm_score": 5,
"selected": false,
"text": "public int ReadOnlyProp => 2;\n"
},
{
"answer_id": 53103732,
"author": "ComeIn",
"author_id": 909122,
"author_profile": "https://Stackoverflow.com/users/909122",
"pm_score": 3,
"selected": false,
"text": "private string name;\npublic string Name \n{\n get \n {\n if(name == null)\n {\n name = \"Default Name\";\n }\n return name;\n }\n set\n {\n name = value;\n }\n}\n"
},
{
"answer_id": 54750202,
"author": "SUNIL DHAPPADHULE",
"author_id": 9452616,
"author_profile": "https://Stackoverflow.com/users/9452616",
"pm_score": 3,
"selected": false,
"text": "public sealed class Employee\n{\n public int Id { get; set; } = 101;\n}\n"
},
{
"answer_id": 61993894,
"author": "Jesse Adam",
"author_id": 2551539,
"author_profile": "https://Stackoverflow.com/users/2551539",
"pm_score": -1,
"selected": false,
"text": "//base class\npublic class Car\n{\n public virtual string FuelUnits\n {\n get { return \"gasoline in gallons\"; }\n protected set { }\n }\n}\n//derived\npublic class Tesla : Car\n{\n public override string FuelUnits => \"ampere hour\";\n}\n"
},
{
"answer_id": 67673580,
"author": "codez0mb1e",
"author_id": 1507068,
"author_profile": "https://Stackoverflow.com/users/1507068",
"pm_score": 5,
"selected": false,
"text": "init"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/946/"
] |
40,733
|
<p>I am setting the <code>.Content</code> value of a Label to a string that contains underscores; the first underscore is being interpreted as an accelerator key.</p>
<p>Without changing the underlying string (by replacing all <code>_</code> with <code>__</code>), is there a way to disable the accelerator for Labels?</p>
|
[
{
"answer_id": 40784,
"author": "denis phillips",
"author_id": 748,
"author_profile": "https://Stackoverflow.com/users/748",
"pm_score": 5,
"selected": false,
"text": "<Page xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">\n <Grid>\n <Grid.Resources>\n <Style x:Key=\"{x:Type Label}\" BasedOn=\"{StaticResource {x:Type Label}}\" TargetType=\"Label\">\n <Setter Property=\"Template\">\n <Setter.Value>\n <ControlTemplate TargetType=\"Label\">\n <Border>\n <ContentPresenter\n HorizontalAlignment=\"{TemplateBinding HorizontalContentAlignment}\"\n VerticalAlignment=\"{TemplateBinding VerticalContentAlignment}\"\n RecognizesAccessKey=\"False\" />\n </Border>\n </ControlTemplate>\n </Setter.Value>\n </Setter>\n </Style>\n </Grid.Resources>\n <Label>_This is a test</Label>\n </Grid>\n</Page>\n"
},
{
"answer_id": 43497326,
"author": "satheesh reddy",
"author_id": 4929487,
"author_profile": "https://Stackoverflow.com/users/4929487",
"pm_score": 1,
"selected": false,
"text": "<TextBlock> ... </TextBlock>"
},
{
"answer_id": 44116685,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "public partial class LabelEx : Label\n {\n public bool PreventAccessKey { get; set; } = true;\n\n public LabelEx()\n {\n InitializeComponent();\n }\n\n public new object Content\n {\n get\n {\n var content = base.Content;\n if (content == null || !(content is string))\n return content;\n\n return PreventAccessKey ?\n (content as string).Replace(\"__\", \"_\") : content;\n }\n set\n {\n if (value == null || !(value is string))\n {\n base.Content = value;\n return;\n }\n\n base.Content = PreventAccessKey ?\n (value as string).Replace(\"_\", \"__\") : value;\n }\n }\n }\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40733",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2258/"
] |
40,737
|
<p><a href="https://stackoverflow.com/questions/32230/tracking-down-where-disk-space-has-gone-on-linux">In this question</a> someone asked for ways to display disk usage in Linux. I'd like to take this one step further down the cli-path... how about a shell script that takes the output from something like a reasonable answer to the previous question and generates a graph/chart from it (output in a png file or something)? This may be a bit too much code to ask for in a regular question, but my guess is that someone already has a oneliner laying around somewhere...</p>
|
[
{
"answer_id": 43733,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 4,
"selected": true,
"text": "disc1usage.value 1234"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4162/"
] |
40,764
|
<p>Are all of these equal? Under what circumstances should I choose each over the others?</p>
<ul>
<li><p>var.ToString()</p></li>
<li><p>CStr(var)</p></li>
<li><p>CType(var, String)</p></li>
<li><p>DirectCast(var, String)</p></li>
</ul>
<hr>
<p><em>EDIT: Suggestion from <strong><a href="https://stackoverflow.com/users/303/notmyself">NotMyself</a></strong>…</em></p>
<ul>
<li>TryCast(var, String)</li>
</ul>
|
[
{
"answer_id": 40771,
"author": "NotMyself",
"author_id": 303,
"author_profile": "https://Stackoverflow.com/users/303",
"pm_score": 3,
"selected": false,
"text": "Dim number As Integer = 1\nDim str As String = String.TryCast(number)\n\nIf str IsNot Nothing Then\n"
},
{
"answer_id": 40782,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 8,
"selected": true,
"text": "var."
},
{
"answer_id": 318669,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "Cstr()"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
40,769
|
<p>How do I determine the (local-) path for the "Program Files" directory on a remote computer? There does not appear to any version of SHGetFolderPath (or related function) that takes the name of a remote computer as a parameter.</p>
<p>I guess I could try to query HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir using remote-registry, but I was hoping there would be "documented" way of doing it.</p>
|
[
{
"answer_id": 40771,
"author": "NotMyself",
"author_id": 303,
"author_profile": "https://Stackoverflow.com/users/303",
"pm_score": 3,
"selected": false,
"text": "Dim number As Integer = 1\nDim str As String = String.TryCast(number)\n\nIf str IsNot Nothing Then\n"
},
{
"answer_id": 40782,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 8,
"selected": true,
"text": "var."
},
{
"answer_id": 318669,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "Cstr()"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3923/"
] |
40,779
|
<p>I've inherited a .NET application that automatically updates it's version number with each release. The problem, as I see it, is the length and number of digits in the version number.</p>
<p>An example of the current version number format is <code>3.5.3167.26981</code> which is a mouthful for the users to say when they are reporting bugs.</p>
<p>What I would like is something more like this: <code>3.5 (build 3198)</code>. I would prefer to manually update the major and minor versions, but have the build number update automatically.</p>
<p>Even better, I don't want the build number to increment unless I am compiling in RELEASE mode.</p>
<p>Anyone know if there is a way to do this -- and how?</p>
|
[
{
"answer_id": 40793,
"author": "Joseph Daigle",
"author_id": 507,
"author_profile": "https://Stackoverflow.com/users/507",
"pm_score": 3,
"selected": true,
"text": "[assembly: AssemblyVersion(\"3.5.*\")]"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3799/"
] |
40,787
|
<p>I'd like to keep a "compile-counter" for one of my projects. I figured a quick and dirty way to do this would be to keep a text file with a plain number in it, and then simply call upon a small script to increment this each time I compile.</p>
<p>How would I go about doing this using the regular Windows command line?</p>
<p>I don't really feel like installing some extra shell to do this but if you have any other super simple suggestions that would accomplish just this, they're naturally appreciated as well.</p>
|
[
{
"answer_id": 40826,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 2,
"selected": false,
"text": "[int](get-content counter.txt) + 1 | out-file counter.txt\n"
},
{
"answer_id": 40856,
"author": "Re0sless",
"author_id": 2098,
"author_profile": "https://Stackoverflow.com/users/2098",
"pm_score": 1,
"selected": false,
"text": "var fso, f, fileCount;\nvar ForReading = 1, ForWriting = 2; \nvar filename = \"c:\\\\testfile.txt\";\nfso = new ActiveXObject(\"Scripting.FileSystemObject\");\n\n//create file if its not found\nif (! fso.FileExists(filename))\n{\n f = fso.OpenTextFile(filename, ForWriting, true);\n f.Write(\"0\");\n f.Close();\n}\n\nf = fso.OpenTextFile(filename, ForReading);\nfileCount = parseInt(f.ReadAll());\n\n//make sure the input is a whole number\nif (isNaN(fileCount))\n{\n fileCount = 0; \n}\n\nfileCount = fileCount + 1;\n\nf = fso.OpenTextFile(filename, ForWriting, true);\nf.Write(fileCount);\nf.Close();\n"
},
{
"answer_id": 40869,
"author": "crono",
"author_id": 1462,
"author_profile": "https://Stackoverflow.com/users/1462",
"pm_score": 5,
"selected": true,
"text": "@echo off\nfor /f \" delims==\" %%i in (counter.txt) do set /A temp_counter= %%i+1\necho %temp_counter% > counter.txt\n"
},
{
"answer_id": 40899,
"author": "Tom",
"author_id": 3715,
"author_profile": "https://Stackoverflow.com/users/3715",
"pm_score": 2,
"selected": false,
"text": "date >> builddates.txt\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/914/"
] |
40,814
|
<p>I need to execute a large set of SQL statements (creating a bunch of tables, views and stored procedures) from within a C# program.</p>
<p>These statements need to be separated by <code>GO</code> statements, but <code>SqlCommand.ExecuteNonQuery()</code> does not like <code>GO</code> statements. My solution, which I suppose I'll post for reference, was to split the SQL string on <code>GO</code> lines, and execute each batch separately.</p>
<p>Is there an easier/better way?</p>
|
[
{
"answer_id": 40827,
"author": "Blorgbeard",
"author_id": 369,
"author_profile": "https://Stackoverflow.com/users/369",
"pm_score": 5,
"selected": false,
"text": "private void ExecuteBatchNonQuery(string sql, SqlConnection conn) {\n string sqlBatch = string.Empty;\n SqlCommand cmd = new SqlCommand(string.Empty, conn);\n conn.Open();\n sql += \"\\nGO\"; // make sure last batch is executed.\n try {\n foreach (string line in sql.Split(new string[2] { \"\\n\", \"\\r\" }, StringSplitOptions.RemoveEmptyEntries)) {\n if (line.ToUpperInvariant().Trim() == \"GO\") {\n cmd.CommandText = sqlBatch;\n cmd.ExecuteNonQuery();\n sqlBatch = string.Empty;\n } else {\n sqlBatch += line + \"\\n\";\n }\n } \n } finally {\n conn.Close();\n }\n}\n"
},
{
"answer_id": 40830,
"author": "Jon Galloway",
"author_id": 5,
"author_profile": "https://Stackoverflow.com/users/5",
"pm_score": 8,
"selected": true,
"text": "public static void Main() \n{ \n string scriptDirectory = \"c:\\\\temp\\\\sqltest\\\\\";\n string sqlConnectionString = \"Integrated Security=SSPI;\" +\n \"Persist Security Info=True;Initial Catalog=Northwind;Data Source=(local)\";\n DirectoryInfo di = new DirectoryInfo(scriptDirectory);\n FileInfo[] rgFiles = di.GetFiles(\"*.sql\");\n foreach (FileInfo fi in rgFiles)\n {\n FileInfo fileInfo = new FileInfo(fi.FullName);\n string script = fileInfo.OpenText().ReadToEnd();\n using (SqlConnection connection = new SqlConnection(sqlConnectionString))\n {\n Server server = new Server(new ServerConnection(connection));\n server.ConnectionContext.ExecuteNonQuery(script);\n }\n }\n}\n"
},
{
"answer_id": 40839,
"author": "tbreffni",
"author_id": 637,
"author_profile": "https://Stackoverflow.com/users/637",
"pm_score": 4,
"selected": false,
"text": "Server.ConnectionContext.ExecuteNonQuery()"
},
{
"answer_id": 10734775,
"author": "grv",
"author_id": 1414633,
"author_profile": "https://Stackoverflow.com/users/1414633",
"pm_score": -1,
"selected": false,
"text": " string[] str ={\n @\"\nUSE master;\n\",@\"\n\n\nCREATE DATABASE \" +con_str_initdir+ @\";\n\",@\"\n-- Verify the database files and sizes\n--SELECT name, size, size*1.0/128 AS [Size in MBs] \n--SELECT name \n--FROM sys.master_files\n--WHERE name = N'\" + con_str_initdir + @\"';\n--GO\n\nUSE \" + con_str_initdir + @\";\n\",@\"\n\nSET ANSI_NULLS ON\n\",@\"\nSET QUOTED_IDENTIFIER ON\n\",@\"\n\nIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Customers]') AND type in (N'U'))\nBEGIN\nCREATE TABLE [dbo].[Customers](\n [CustomerID] [int] IDENTITY(1,1) NOT NULL,\n [CustomerName] [nvarchar](50) NULL,\n CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED \n(\n [CustomerID] ASC\n)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]\n) ON [PRIMARY]\nEND\n\",@\"\n\n\n\nSET ANSI_NULLS ON\n\",@\"\nSET QUOTED_IDENTIFIER ON\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GOODS]') AND type in (N'U'))\nBEGIN\nCREATE TABLE [dbo].[GOODS](\n [GoodsID] [int] IDENTITY(1,1) NOT NULL,\n [GoodsName] [nvarchar](50) NOT NULL,\n [GoodsPrice] [float] NOT NULL,\n CONSTRAINT [PK_GOODS] PRIMARY KEY CLUSTERED \n(\n [GoodsID] ASC\n)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]\n) ON [PRIMARY]\nEND\n\",@\"\nSET ANSI_NULLS ON\n\",@\"\nSET QUOTED_IDENTIFIER ON\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Orders]') AND type in (N'U'))\nBEGIN\nCREATE TABLE [dbo].[Orders](\n [OrderID] [int] IDENTITY(1,1) NOT NULL,\n [CustomerID] [int] NOT NULL,\n [Date] [smalldatetime] NOT NULL,\n CONSTRAINT [PK_Orders] PRIMARY KEY CLUSTERED \n(\n [OrderID] ASC\n)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]\n) ON [PRIMARY]\nEND\n\",@\"\nSET ANSI_NULLS ON\n\",@\"\nSET QUOTED_IDENTIFIER ON\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[OrderDetails]') AND type in (N'U'))\nBEGIN\nCREATE TABLE [dbo].[OrderDetails](\n [OrderID] [int] NOT NULL,\n [GoodsID] [int] NOT NULL,\n [Qty] [int] NOT NULL,\n [Price] [float] NOT NULL,\n CONSTRAINT [PK_OrderDetails] PRIMARY KEY CLUSTERED \n(\n [OrderID] ASC,\n [GoodsID] ASC\n)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]\n) ON [PRIMARY]\nEND\n\",@\"\n\nSET ANSI_NULLS ON\n\",@\"\nSET QUOTED_IDENTIFIER ON\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[InsertCustomers]') AND type in (N'P', N'PC'))\nBEGIN\nEXEC dbo.sp_executesql @statement = N'-- =============================================\n-- Author: <Author,,Name>\n-- Create date: <Create Date,,>\n-- Description: <Description,,>\n-- =============================================\ncreate PROCEDURE [dbo].[InsertCustomers]\n @CustomerName nvarchar(50),\n @Identity int OUT\nAS\nINSERT INTO Customers (CustomerName) VALUES(@CustomerName)\nSET @Identity = SCOPE_IDENTITY()\n\n' \nEND\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Orders_Customers]') AND parent_object_id = OBJECT_ID(N'[dbo].[Orders]'))\nALTER TABLE [dbo].[Orders] WITH CHECK ADD CONSTRAINT [FK_Orders_Customers] FOREIGN KEY([CustomerID])\nREFERENCES [dbo].[Customers] ([CustomerID])\nON UPDATE CASCADE\n\",@\"\nALTER TABLE [dbo].[Orders] CHECK CONSTRAINT [FK_Orders_Customers]\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_OrderDetails_GOODS]') AND parent_object_id = OBJECT_ID(N'[dbo].[OrderDetails]'))\nALTER TABLE [dbo].[OrderDetails] WITH CHECK ADD CONSTRAINT [FK_OrderDetails_GOODS] FOREIGN KEY([GoodsID])\nREFERENCES [dbo].[GOODS] ([GoodsID])\nON UPDATE CASCADE\n\",@\"\nALTER TABLE [dbo].[OrderDetails] CHECK CONSTRAINT [FK_OrderDetails_GOODS]\n\",@\"\nIF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_OrderDetails_Orders]') AND parent_object_id = OBJECT_ID(N'[dbo].[OrderDetails]'))\nALTER TABLE [dbo].[OrderDetails] WITH CHECK ADD CONSTRAINT [FK_OrderDetails_Orders] FOREIGN KEY([OrderID])\nREFERENCES [dbo].[Orders] ([OrderID])\nON UPDATE CASCADE\nON DELETE CASCADE\n\",@\"\nALTER TABLE [dbo].[OrderDetails] CHECK CONSTRAINT [FK_OrderDetails_Orders]\n\n\n \"};\n\n\n for(int i =0; i<str.Length;i++) \n {\n myCommand.CommandText=str[i];\n try\n {\n myCommand.ExecuteNonQuery();\n }\n catch (SystemException ee)\n {\n MessageBox.Show(\"Error \"+ee.ToString());\n }\n\n }\n"
},
{
"answer_id": 23898655,
"author": "Ryan Penfold",
"author_id": 1111806,
"author_profile": "https://Stackoverflow.com/users/1111806",
"pm_score": 2,
"selected": false,
"text": "foreach (var sqlBatch in commandText.Split(new[] { \"GO\" }, StringSplitOptions.RemoveEmptyEntries))\n{\n sqlCommand.CommandText = sqlBatch;\n sqlCommand.ExecuteNonQuery();\n}\n"
},
{
"answer_id": 24179458,
"author": "jbrunodomingues",
"author_id": 3644735,
"author_profile": "https://Stackoverflow.com/users/3644735",
"pm_score": 0,
"selected": false,
"text": "String pattern = \"\\\\bGO\\\\b|\\\\bgo\\\\b\";\n\nString[] splitedSql = sql.split(pattern);\nfor (String chunk : splitedSql) {\n getJdbcTemplate().update(chunk);\n}\n"
},
{
"answer_id": 25601409,
"author": "Bigjim",
"author_id": 1773646,
"author_profile": "https://Stackoverflow.com/users/1773646",
"pm_score": 2,
"selected": false,
"text": "private List<string> SplitScriptGo(string script)\n{\n var result = new List<string>();\n int pos1 = 0;\n int pos2 = 0;\n bool whiteSpace = true;\n bool emptyLine = true;\n bool inStr = false;\n bool inComment1 = false;\n bool inComment2 = false;\n\n while (true)\n {\n while (pos2 < script.Length && Char.IsWhiteSpace(script[pos2]))\n {\n if (script[pos2] == '\\r' || script[pos2] == '\\n')\n {\n emptyLine = true;\n inComment1 = false;\n }\n\n pos2++;\n }\n\n if (pos2 == script.Length)\n break;\n\n bool min2 = (pos2 + 1) < script.Length;\n bool min3 = (pos2 + 2) < script.Length;\n\n if (!inStr && !inComment2 && min2 && script.Substring(pos2, 2) == \"--\")\n inComment1 = true;\n\n if (!inStr && !inComment1 && min2 && script.Substring(pos2, 2) == \"/*\")\n inComment2 = true;\n\n if (!inComment1 && !inComment2 && script[pos2] == '\\'')\n inStr = !inStr;\n\n if (!inStr && !inComment1 && !inComment2 && emptyLine\n && (min2 && script.Substring(pos2, 2).ToLower() == \"go\")\n && (!min3 || char.IsWhiteSpace(script[pos2 + 2]) || script.Substring(pos2 + 2, 2) == \"--\" || script.Substring(pos2 + 2, 2) == \"/*\"))\n {\n if (!whiteSpace)\n result.Add(script.Substring(pos1, pos2 - pos1));\n\n whiteSpace = true;\n emptyLine = false;\n pos2 += 2;\n pos1 = pos2;\n }\n else\n {\n pos2++;\n whiteSpace = false;\n\n if (!inComment2)\n emptyLine = false;\n }\n\n if (!inStr && inComment2 && pos2 > 1 && script.Substring(pos2 - 2, 2) == \"*/\")\n inComment2 = false;\n }\n\n if (!whiteSpace)\n result.Add(script.Substring(pos1));\n\n return result;\n}\n"
},
{
"answer_id": 25992625,
"author": "Stefan Steiger",
"author_id": 155077,
"author_profile": "https://Stackoverflow.com/users/155077",
"pm_score": 2,
"selected": false,
"text": " string strSQL = @\"\nSELECT * FROM INFORMATION_SCHEMA.columns\nGO\nSELECT * FROM INFORMATION_SCHEMA.views\n\";\n\n foreach(string Script in new Subtext.Scripting.ScriptSplitter(strSQL ))\n {\n Console.WriteLine(Script);\n }\n"
},
{
"answer_id": 28557032,
"author": "Sriwantha Attanayake",
"author_id": 215336,
"author_profile": "https://Stackoverflow.com/users/215336",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.IO;\nusing System.Text.RegularExpressions;\nnamespace RegExTrial\n{\n class Program\n {\n static void Main(string[] args)\n {\n string sql = String.Empty;\n string path=@\"D:\\temp\\sample.sql\";\n using (StreamReader reader = new StreamReader(path)) {\n sql = reader.ReadToEnd();\n } \n //Select any GO (ignore case) that starts with at least \n //one white space such as tab, space,new line, verticle tab etc\n string pattern=\"[\\\\s](?i)GO(?-i)\";\n\n Regex matcher = new Regex(pattern, RegexOptions.Compiled);\n int start = 0;\n int end = 0;\n Match batch=matcher.Match(sql);\n while (batch.Success) {\n end = batch.Index;\n string batchQuery = sql.Substring(start, end - start).Trim();\n //execute the batch\n ExecuteBatch(batchQuery);\n start = end + batch.Length;\n batch = matcher.Match(sql,start);\n }\n\n }\n\n private static void ExecuteBatch(string command)\n { \n //execute your query here\n }\n\n }\n}\n"
},
{
"answer_id": 31785091,
"author": "Morvael",
"author_id": 1286358,
"author_profile": "https://Stackoverflow.com/users/1286358",
"pm_score": 0,
"selected": false,
"text": "public static bool ExecuteExternalScript(string filePath)\n{\n using (StreamReader file = new StreamReader(filePath))\n using (SqlConnection conn = new SqlConnection(dbConnStr))\n {\n StringBuilder sql = new StringBuilder();\n\n string line;\n while ((line = file.ReadLine()) != null)\n {\n // replace GO with semi-colon\n if (line == \"GO\")\n sql.Append(\";\");\n // remove inline comments\n else if (line.IndexOf(\"--\") > -1)\n sql.AppendFormat(\" {0} \", line.Split(new string[] { \"--\" }, StringSplitOptions.None)[0]);\n // just the line as it is\n else\n sql.AppendFormat(\" {0} \", line);\n }\n conn.Open();\n\n SqlCommand cmd = new SqlCommand(sql.ToString(), conn);\n cmd.ExecuteNonQuery();\n }\n\n return true;\n}\n"
},
{
"answer_id": 47066366,
"author": "Yargo",
"author_id": 3748460,
"author_profile": "https://Stackoverflow.com/users/3748460",
"pm_score": 1,
"selected": false,
"text": "-- some commented text\n /*\ndrop table Users;\nGO\n */\n"
},
{
"answer_id": 52443620,
"author": "Filip Cordas",
"author_id": 6330636,
"author_profile": "https://Stackoverflow.com/users/6330636",
"pm_score": 3,
"selected": false,
"text": "SqlConnection"
},
{
"answer_id": 55621284,
"author": "Sprot",
"author_id": 2960937,
"author_profile": "https://Stackoverflow.com/users/2960937",
"pm_score": -1,
"selected": false,
"text": "using (var connection = new SqlConnection(connectionString))\n{\n var server = new Server(new ServerConnection(connection));\n server.ConnectionContext.ExecuteNonQuery(sql);\n}\n"
},
{
"answer_id": 66628734,
"author": "Ahmed Suror",
"author_id": 1655837,
"author_profile": "https://Stackoverflow.com/users/1655837",
"pm_score": 0,
"selected": false,
"text": ";"
},
{
"answer_id": 72480033,
"author": "adamency",
"author_id": 16974218,
"author_profile": "https://Stackoverflow.com/users/16974218",
"pm_score": 0,
"selected": false,
"text": "GO"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/369/"
] |
40,816
|
<p>If I have an HTML helper like so:</p>
<pre><code>Name:<br />
<%=Html.TextBox("txtName",20) %><br />
</code></pre>
<p>How do I apply a CSS class to it? Do I have to wrap it in a span? Or do I need to somehow utilize the HtmlAttributes property of the helper?</p>
|
[
{
"answer_id": 40846,
"author": "Dale Ragan",
"author_id": 1117,
"author_profile": "https://Stackoverflow.com/users/1117",
"pm_score": 6,
"selected": true,
"text": "Name:<br/> \n<%= Html.TextBox(\"txtName\", \"20\", new { @class = \"hello\" }) %>\n"
},
{
"answer_id": 40847,
"author": "Matt Hinze",
"author_id": 2676,
"author_profile": "https://Stackoverflow.com/users/2676",
"pm_score": 2,
"selected": false,
"text": "htmlAttributes"
},
{
"answer_id": 40877,
"author": "David Negron",
"author_id": 981,
"author_profile": "https://Stackoverflow.com/users/981",
"pm_score": 2,
"selected": false,
"text": "<input type=\"text\" class\"TextboxWatermark\" name=\"username\" id=\"username\" title=\"Must be at least 6 chars\" />\n"
},
{
"answer_id": 13659584,
"author": "JGilmartin",
"author_id": 266552,
"author_profile": "https://Stackoverflow.com/users/266552",
"pm_score": 4,
"selected": false,
"text": "@Html.TextBoxFor(x => x.TextBoxID, new { @class = \"SearchBarSelect\", style = \"width: 20px; background-color: green;\" })\n"
},
{
"answer_id": 52705298,
"author": "Nelson Martins",
"author_id": 6410596,
"author_profile": "https://Stackoverflow.com/users/6410596",
"pm_score": -1,
"selected": false,
"text": ".testClass {\ncolor: #1600d3;\n}\n"
},
{
"answer_id": 52768400,
"author": "Hamid Jolany",
"author_id": 555078,
"author_profile": "https://Stackoverflow.com/users/555078",
"pm_score": 0,
"selected": false,
"text": "public static class LabelExtensioncs\n{\n public static MvcHtmlString Alarm(this HtmlHelper helper, string target, string text)\n {\n return MvcHtmlString.Create(string.Format(\"<p class='alert' style='background-color: #b8f89d;border-radius: 5px;width: 100%;'><b>{0}</b><br /><i>{1}</i></p>\", target, text));\n } \n}\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/230/"
] |
40,853
|
<p>I have some code like this in a winforms app I was writing to query a user's mail box Storage Quota.</p>
<pre><code>DirectoryEntry mbstore = new DirectoryEntry(
@"LDAP://" + strhome,
m_serviceaccount,
[m_pwd],
AuthenticationTypes.Secure);
</code></pre>
<p>No matter what approach I tried (like <code>SecureString</code>), I am easily able to see the password (<strong>m_pwd</strong>) either using Reflector or using strings tab of Process Explorer for the executable.</p>
<p>I know I could put this code on the server or tighten up the security using mechanisms like delegation and giving only the required privileges to the service account.</p>
<p>Can somebody suggest a reasonably secure way to store the password in the local application without revealing the password to hackers?</p>
<p>Hashing is not possible since I need to know the exact password (not just the hash for matching purpose).
Encryption/Decryption mechanisms are not working since they are machine dependent.</p>
|
[
{
"answer_id": 40867,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 6,
"selected": true,
"text": "DATA_BLOB blobIn, blobOut;\nblobIn.pbData=(BYTE*)data;\nblobIn.cbData=wcslen(data)*sizeof(WCHAR);\n\nCryptProtectData(&blobIn, description, NULL, NULL, NULL, CRYPTPROTECT_LOCAL_MACHINE | CRYPTPROTECT_UI_FORBIDDEN, &blobOut);\n_encrypted=blobOut.pbData;\n_length=blobOut.cbData;\n"
}
] |
2008/09/02
|
[
"https://Stackoverflow.com/questions/40853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4337/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.