qid
int64 4
22.2M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
159,034
|
<p>Are C++ enums signed or unsigned? And by extension is it safe to validate an input by checking that it is <= your max value, and leave out >= your min value (assuming you started at 0 and incremented by 1)?</p>
|
[
{
"answer_id": 159068,
"author": "Cristián Romo",
"author_id": 1256,
"author_profile": "https://Stackoverflow.com/users/1256",
"pm_score": 3,
"selected": false,
"text": "enum Fruit\n{\n Apple = 0,\n Banana,\n Pineapple,\n Orange,\n Kumquat\n};\n\nenum Fruit fruitVariable = Banana; // Okay, Banana is a member of the Fruit enum\nfruitVariable = 1; // Error, 1 is not a member of enum Fruit even though it has the same value as banana.\n"
},
{
"answer_id": 159117,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": false,
"text": "enum X : signed int { ... }; // signed enum\nenum Y : unsigned int { ... }; // unsigned enum\n"
},
{
"answer_id": 164040,
"author": "Matt",
"author_id": 17693,
"author_profile": "https://Stackoverflow.com/users/17693",
"pm_score": 4,
"selected": false,
"text": "enum X : signed int { ... }; // signed enum\nenum Y : unsigned int { ... }; // unsigned enum\n"
},
{
"answer_id": 168060,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 2,
"selected": false,
"text": "enum { A = 1, B = 4};\n"
},
{
"answer_id": 24803626,
"author": "JavaMan",
"author_id": 237575,
"author_profile": "https://Stackoverflow.com/users/237575",
"pm_score": 3,
"selected": false,
"text": "underlying type"
},
{
"answer_id": 54572423,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 2,
"selected": false,
"text": "std::is_signed<std::underlying_type"
},
{
"answer_id": 69088603,
"author": "Preston L. Bannister",
"author_id": 184534,
"author_profile": "https://Stackoverflow.com/users/184534",
"pm_score": 0,
"selected": false,
"text": "enum FOO_STATUS {\n STATUS_ERROR = (1 << 31)\n};\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17693/"
] |
159,038
|
<p>Are disabling and enabling foreign key constraints supported in SQL Server? Or is my only option to <strong><code>drop</code></strong> and then <strong>re-<code>create</code></strong> the constraints?</p>
|
[
{
"answer_id": 159064,
"author": "ScottStonehouse",
"author_id": 2342,
"author_profile": "https://Stackoverflow.com/users/2342",
"pm_score": 9,
"selected": false,
"text": " -- Disable all table constraints\n ALTER TABLE MyTable NOCHECK CONSTRAINT ALL\n\n -- Enable all table constraints\n ALTER TABLE MyTable WITH CHECK CHECK CONSTRAINT ALL\n \n -- Disable single constraint\n \n ALTER TABLE MyTable NOCHECK CONSTRAINT MyConstraint\n \n -- Enable single constraint\n ALTER TABLE MyTable WITH CHECK CHECK CONSTRAINT MyConstraint\n"
},
{
"answer_id": 161410,
"author": "kristof",
"author_id": 3241,
"author_profile": "https://Stackoverflow.com/users/3241",
"pm_score": 11,
"selected": true,
"text": "-- disable all constraints\nEXEC sp_MSforeachtable \"ALTER TABLE ? NOCHECK CONSTRAINT all\"\n"
},
{
"answer_id": 9452317,
"author": "Amir Hussein Samiani",
"author_id": 1233666,
"author_profile": "https://Stackoverflow.com/users/1233666",
"pm_score": 4,
"selected": false,
"text": " --Drop and Recreate Foreign Key Constraints\n\nSET NOCOUNT ON\n\nDECLARE @table TABLE(\n RowId INT PRIMARY KEY IDENTITY(1, 1),\n ForeignKeyConstraintName NVARCHAR(200),\n ForeignKeyConstraintTableSchema NVARCHAR(200),\n ForeignKeyConstraintTableName NVARCHAR(200),\n ForeignKeyConstraintColumnName NVARCHAR(200),\n PrimaryKeyConstraintName NVARCHAR(200),\n PrimaryKeyConstraintTableSchema NVARCHAR(200),\n PrimaryKeyConstraintTableName NVARCHAR(200),\n PrimaryKeyConstraintColumnName NVARCHAR(200) \n)\n\nINSERT INTO @table(ForeignKeyConstraintName, ForeignKeyConstraintTableSchema, ForeignKeyConstraintTableName, ForeignKeyConstraintColumnName)\nSELECT \n U.CONSTRAINT_NAME, \n U.TABLE_SCHEMA, \n U.TABLE_NAME, \n U.COLUMN_NAME \nFROM \n INFORMATION_SCHEMA.KEY_COLUMN_USAGE U\n INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C\n ON U.CONSTRAINT_NAME = C.CONSTRAINT_NAME\nWHERE\n C.CONSTRAINT_TYPE = 'FOREIGN KEY'\n\nUPDATE @table SET\n PrimaryKeyConstraintName = UNIQUE_CONSTRAINT_NAME\nFROM \n @table T\n INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS R\n ON T.ForeignKeyConstraintName = R.CONSTRAINT_NAME\n\nUPDATE @table SET\n PrimaryKeyConstraintTableSchema = TABLE_SCHEMA,\n PrimaryKeyConstraintTableName = TABLE_NAME\nFROM @table T\n INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C\n ON T.PrimaryKeyConstraintName = C.CONSTRAINT_NAME\n\nUPDATE @table SET\n PrimaryKeyConstraintColumnName = COLUMN_NAME\nFROM @table T\n INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE U\n ON T.PrimaryKeyConstraintName = U.CONSTRAINT_NAME\n\n--SELECT * FROM @table\n\n--DROP CONSTRAINT:\nSELECT\n '\n ALTER TABLE [' + ForeignKeyConstraintTableSchema + '].[' + ForeignKeyConstraintTableName + '] \n DROP CONSTRAINT ' + ForeignKeyConstraintName + '\n\n GO'\nFROM\n @table\n\n--ADD CONSTRAINT:\nSELECT\n '\n ALTER TABLE [' + ForeignKeyConstraintTableSchema + '].[' + ForeignKeyConstraintTableName + '] \n ADD CONSTRAINT ' + ForeignKeyConstraintName + ' FOREIGN KEY(' + ForeignKeyConstraintColumnName + ') REFERENCES [' + PrimaryKeyConstraintTableSchema + '].[' + PrimaryKeyConstraintTableName + '](' + PrimaryKeyConstraintColumnName + ')\n\n GO'\nFROM\n @table\n\nGO\n"
},
{
"answer_id": 9479049,
"author": "Amir Hussein Samiani",
"author_id": 1233666,
"author_profile": "https://Stackoverflow.com/users/1233666",
"pm_score": 4,
"selected": false,
"text": "SET NOCOUNT ON\n\nDECLARE @table TABLE(\n RowId INT PRIMARY KEY IDENTITY(1, 1),\n ForeignKeyConstraintName NVARCHAR(200),\n ForeignKeyConstraintTableSchema NVARCHAR(200),\n ForeignKeyConstraintTableName NVARCHAR(200),\n ForeignKeyConstraintColumnName NVARCHAR(200),\n PrimaryKeyConstraintName NVARCHAR(200),\n PrimaryKeyConstraintTableSchema NVARCHAR(200),\n PrimaryKeyConstraintTableName NVARCHAR(200),\n PrimaryKeyConstraintColumnName NVARCHAR(200),\n UpdateRule NVARCHAR(100),\n DeleteRule NVARCHAR(100) \n)\n\nINSERT INTO @table(ForeignKeyConstraintName, ForeignKeyConstraintTableSchema, ForeignKeyConstraintTableName, ForeignKeyConstraintColumnName)\nSELECT \n U.CONSTRAINT_NAME, \n U.TABLE_SCHEMA, \n U.TABLE_NAME, \n U.COLUMN_NAME\nFROM \n INFORMATION_SCHEMA.KEY_COLUMN_USAGE U\n INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C\n ON U.CONSTRAINT_NAME = C.CONSTRAINT_NAME\nWHERE\n C.CONSTRAINT_TYPE = 'FOREIGN KEY'\n\nUPDATE @table SET\n T.PrimaryKeyConstraintName = R.UNIQUE_CONSTRAINT_NAME,\n T.UpdateRule = R.UPDATE_RULE,\n T.DeleteRule = R.DELETE_RULE\nFROM \n @table T\n INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS R\n ON T.ForeignKeyConstraintName = R.CONSTRAINT_NAME\n\nUPDATE @table SET\n PrimaryKeyConstraintTableSchema = TABLE_SCHEMA,\n PrimaryKeyConstraintTableName = TABLE_NAME\nFROM @table T\n INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C\n ON T.PrimaryKeyConstraintName = C.CONSTRAINT_NAME\n\nUPDATE @table SET\n PrimaryKeyConstraintColumnName = COLUMN_NAME\nFROM @table T\n INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE U\n ON T.PrimaryKeyConstraintName = U.CONSTRAINT_NAME\n\n--SELECT * FROM @table\n\nSELECT '\nBEGIN TRANSACTION\nBEGIN TRY'\n\n--DROP CONSTRAINT:\nSELECT\n '\n ALTER TABLE [' + ForeignKeyConstraintTableSchema + '].[' + ForeignKeyConstraintTableName + '] \n DROP CONSTRAINT ' + ForeignKeyConstraintName + '\n '\nFROM\n @table\n\nSELECT '\nEND TRY\n\nBEGIN CATCH\n ROLLBACK TRANSACTION\n RAISERROR(''Operation failed.'', 16, 1)\nEND CATCH\n\nIF(@@TRANCOUNT != 0)\nBEGIN\n COMMIT TRANSACTION\n RAISERROR(''Operation completed successfully.'', 10, 1)\nEND\n'\n\n--ADD CONSTRAINT:\nSELECT '\nBEGIN TRANSACTION\nBEGIN TRY'\n\nSELECT\n '\n ALTER TABLE [' + ForeignKeyConstraintTableSchema + '].[' + ForeignKeyConstraintTableName + '] \n ADD CONSTRAINT ' + ForeignKeyConstraintName + ' FOREIGN KEY(' + ForeignKeyConstraintColumnName + ') REFERENCES [' + PrimaryKeyConstraintTableSchema + '].[' + PrimaryKeyConstraintTableName + '](' + PrimaryKeyConstraintColumnName + ') ON UPDATE ' + UpdateRule + ' ON DELETE ' + DeleteRule + '\n '\nFROM\n @table\n\nSELECT '\nEND TRY\n\nBEGIN CATCH\n ROLLBACK TRANSACTION\n RAISERROR(''Operation failed.'', 16, 1)\nEND CATCH\n\nIF(@@TRANCOUNT != 0)\nBEGIN\n COMMIT TRANSACTION\n RAISERROR(''Operation completed successfully.'', 10, 1)\nEND'\n\nGO\n"
},
{
"answer_id": 10000559,
"author": "Diego Mendes",
"author_id": 484222,
"author_profile": "https://Stackoverflow.com/users/484222",
"pm_score": 6,
"selected": false,
"text": "ALTER"
},
{
"answer_id": 16906559,
"author": "vic",
"author_id": 1604319,
"author_profile": "https://Stackoverflow.com/users/1604319",
"pm_score": 5,
"selected": false,
"text": "PRINT N'-- CREATE FOREIGN KEY CONSTRAINTS --';\n\nSET NOCOUNT ON;\nSELECT '\nPRINT N''Creating '+ const.const_name +'...''\nGO\nALTER TABLE ' + const.parent_obj + '\n ADD CONSTRAINT ' + const.const_name + ' FOREIGN KEY (\n ' + const.parent_col_csv + '\n ) REFERENCES ' + const.ref_obj + '(' + const.ref_col_csv + ')\nGO'\nFROM (\n SELECT QUOTENAME(fk.NAME) AS [const_name]\n ,QUOTENAME(schParent.NAME) + '.' + QUOTENAME(OBJECT_name(fkc.parent_object_id)) AS [parent_obj]\n ,STUFF((\n SELECT ',' + QUOTENAME(COL_NAME(fcP.parent_object_id, fcp.parent_column_id))\n FROM sys.foreign_key_columns AS fcP\n WHERE fcp.constraint_object_id = fk.object_id\n FOR XML path('')\n ), 1, 1, '') AS [parent_col_csv]\n ,QUOTENAME(schRef.NAME) + '.' + QUOTENAME(OBJECT_NAME(fkc.referenced_object_id)) AS [ref_obj]\n ,STUFF((\n SELECT ',' + QUOTENAME(COL_NAME(fcR.referenced_object_id, fcR.referenced_column_id))\n FROM sys.foreign_key_columns AS fcR\n WHERE fcR.constraint_object_id = fk.object_id\n FOR XML path('')\n ), 1, 1, '') AS [ref_col_csv]\n FROM sys.foreign_key_columns AS fkc\n INNER JOIN sys.foreign_keys AS fk ON fk.object_id = fkc.constraint_object_id\n INNER JOIN sys.objects AS oParent ON oParent.object_id = fkc.parent_object_id\n INNER JOIN sys.schemas AS schParent ON schParent.schema_id = oParent.schema_id\n INNER JOIN sys.objects AS oRef ON oRef.object_id = fkc.referenced_object_id\n INNER JOIN sys.schemas AS schRef ON schRef.schema_id = oRef.schema_id\n GROUP BY fkc.parent_object_id\n ,fkc.referenced_object_id\n ,fk.NAME\n ,fk.object_id\n ,schParent.NAME\n ,schRef.NAME\n ) AS const\nORDER BY const.const_name\n"
},
{
"answer_id": 21772349,
"author": "Aditya",
"author_id": 2819400,
"author_profile": "https://Stackoverflow.com/users/2819400",
"pm_score": 3,
"selected": false,
"text": "SELECT * \nFROM sys.foreign_keys\nWHERE referenced_object_id = object_id('TABLE_NAME')\n"
},
{
"answer_id": 30945682,
"author": "Denmach",
"author_id": 5029331,
"author_profile": "https://Stackoverflow.com/users/5029331",
"pm_score": 3,
"selected": false,
"text": "----------------------------------------------------------------------------\n1)\n/*\nAuthor: Denmach\nDateCreated: 2014-04-23\nPurpose: Generates SQL statements to DROP, ADD, and CHECK existing constraints for a \n database. Stores scripts in tables on target database for execution. Executes\n those stored scripts via independent cursors. \nDateModified:\nModifiedBy\nComments: This will eliminate deletes and the T-log ballooning associated with it.\n*/\n\nDECLARE @schema_name SYSNAME; \nDECLARE @table_name SYSNAME; \nDECLARE @constraint_name SYSNAME; \nDECLARE @constraint_object_id INT; \nDECLARE @referenced_object_name SYSNAME; \nDECLARE @is_disabled BIT; \nDECLARE @is_not_for_replication BIT; \nDECLARE @is_not_trusted BIT; \nDECLARE @delete_referential_action TINYINT; \nDECLARE @update_referential_action TINYINT; \nDECLARE @tsql NVARCHAR(4000); \nDECLARE @tsql2 NVARCHAR(4000); \nDECLARE @fkCol SYSNAME; \nDECLARE @pkCol SYSNAME; \nDECLARE @col1 BIT; \nDECLARE @action CHAR(6); \nDECLARE @referenced_schema_name SYSNAME;\n\n\n\n--------------------------------Generate scripts to drop all foreign keys in a database --------------------------------\n\nIF OBJECT_ID('dbo.sync_dropFK') IS NOT NULL\nDROP TABLE sync_dropFK\n\nCREATE TABLE sync_dropFK\n (\n ID INT IDENTITY (1,1) NOT NULL\n , Script NVARCHAR(4000)\n )\n\nDECLARE FKcursor CURSOR FOR\n\n SELECT \n OBJECT_SCHEMA_NAME(parent_object_id)\n , OBJECT_NAME(parent_object_id)\n , name\n FROM \n sys.foreign_keys WITH (NOLOCK)\n ORDER BY \n 1,2;\n\nOPEN FKcursor;\n\nFETCH NEXT FROM FKcursor INTO \n @schema_name\n , @table_name\n , @constraint_name\n\nWHILE @@FETCH_STATUS = 0\n\nBEGIN\n SET @tsql = 'ALTER TABLE '\n + QUOTENAME(@schema_name) \n + '.' \n + QUOTENAME(@table_name)\n + ' DROP CONSTRAINT ' \n + QUOTENAME(@constraint_name) \n + ';';\n --PRINT @tsql;\n INSERT sync_dropFK (\n Script\n )\n VALUES (\n @tsql\n ) \n\n FETCH NEXT FROM FKcursor INTO \n @schema_name\n , @table_name\n , @constraint_name\n ;\n\nEND;\n\nCLOSE FKcursor;\n\nDEALLOCATE FKcursor;\n\n\n---------------Generate scripts to create all existing foreign keys in a database --------------------------------\n----------------------------------------------------------------------------------------------------------\nIF OBJECT_ID('dbo.sync_createFK') IS NOT NULL\nDROP TABLE sync_createFK\n\nCREATE TABLE sync_createFK\n (\n ID INT IDENTITY (1,1) NOT NULL\n , Script NVARCHAR(4000)\n )\n\nIF OBJECT_ID('dbo.sync_createCHECK') IS NOT NULL\nDROP TABLE sync_createCHECK\n\nCREATE TABLE sync_createCHECK\n (\n ID INT IDENTITY (1,1) NOT NULL\n , Script NVARCHAR(4000)\n ) \n\nDECLARE FKcursor CURSOR FOR\n\n SELECT \n OBJECT_SCHEMA_NAME(parent_object_id)\n , OBJECT_NAME(parent_object_id)\n , name\n , OBJECT_NAME(referenced_object_id)\n , OBJECT_ID\n , is_disabled\n , is_not_for_replication\n , is_not_trusted\n , delete_referential_action\n , update_referential_action\n , OBJECT_SCHEMA_NAME(referenced_object_id)\n\n FROM \n sys.foreign_keys WITH (NOLOCK)\n\n ORDER BY \n 1,2;\n\nOPEN FKcursor;\n\nFETCH NEXT FROM FKcursor INTO \n @schema_name\n , @table_name\n , @constraint_name\n , @referenced_object_name\n , @constraint_object_id\n , @is_disabled\n , @is_not_for_replication\n , @is_not_trusted\n , @delete_referential_action\n , @update_referential_action\n , @referenced_schema_name;\n\nWHILE @@FETCH_STATUS = 0\n\nBEGIN\n\n BEGIN\n SET @tsql = 'ALTER TABLE '\n + QUOTENAME(@schema_name) \n + '.' \n + QUOTENAME(@table_name)\n + CASE \n @is_not_trusted\n WHEN 0 THEN ' WITH CHECK '\n ELSE ' WITH NOCHECK '\n END\n + ' ADD CONSTRAINT ' \n + QUOTENAME(@constraint_name)\n + ' FOREIGN KEY (';\n\n SET @tsql2 = '';\n\n DECLARE ColumnCursor CURSOR FOR \n\n SELECT \n COL_NAME(fk.parent_object_id\n , fkc.parent_column_id)\n , COL_NAME(fk.referenced_object_id\n , fkc.referenced_column_id)\n\n FROM \n sys.foreign_keys fk WITH (NOLOCK)\n INNER JOIN sys.foreign_key_columns fkc WITH (NOLOCK) ON fk.[object_id] = fkc.constraint_object_id\n\n WHERE \n fkc.constraint_object_id = @constraint_object_id\n\n ORDER BY \n fkc.constraint_column_id;\n\n OPEN ColumnCursor;\n\n SET @col1 = 1;\n\n FETCH NEXT FROM ColumnCursor INTO @fkCol, @pkCol;\n\n WHILE @@FETCH_STATUS = 0\n\n BEGIN\n IF (@col1 = 1)\n SET @col1 = 0;\n ELSE\n BEGIN\n SET @tsql = @tsql + ',';\n SET @tsql2 = @tsql2 + ',';\n END;\n\n SET @tsql = @tsql + QUOTENAME(@fkCol);\n SET @tsql2 = @tsql2 + QUOTENAME(@pkCol);\n --PRINT '@tsql = ' + @tsql \n --PRINT '@tsql2 = ' + @tsql2\n FETCH NEXT FROM ColumnCursor INTO @fkCol, @pkCol;\n --PRINT 'FK Column ' + @fkCol\n --PRINT 'PK Column ' + @pkCol \n END;\n\n CLOSE ColumnCursor;\n DEALLOCATE ColumnCursor;\n\n SET @tsql = @tsql + ' ) REFERENCES ' \n + QUOTENAME(@referenced_schema_name) \n + '.' \n + QUOTENAME(@referenced_object_name)\n + ' (' \n + @tsql2 + ')';\n\n SET @tsql = @tsql\n + ' ON UPDATE ' \n + \n CASE @update_referential_action\n WHEN 0 THEN 'NO ACTION '\n WHEN 1 THEN 'CASCADE '\n WHEN 2 THEN 'SET NULL '\n ELSE 'SET DEFAULT '\n END\n\n + ' ON DELETE ' \n + \n CASE @delete_referential_action\n WHEN 0 THEN 'NO ACTION '\n WHEN 1 THEN 'CASCADE '\n WHEN 2 THEN 'SET NULL '\n ELSE 'SET DEFAULT '\n END\n\n + \n CASE @is_not_for_replication\n WHEN 1 THEN ' NOT FOR REPLICATION '\n ELSE ''\n END\n + ';';\n\n END;\n\n -- PRINT @tsql\n INSERT sync_createFK \n (\n Script\n )\n VALUES (\n @tsql\n )\n\n-------------------Generate CHECK CONSTRAINT scripts for a database ------------------------------\n----------------------------------------------------------------------------------------------------------\n\n BEGIN\n\n SET @tsql = 'ALTER TABLE '\n + QUOTENAME(@schema_name) \n + '.' \n + QUOTENAME(@table_name)\n + \n CASE @is_disabled\n WHEN 0 THEN ' CHECK '\n ELSE ' NOCHECK '\n END\n + 'CONSTRAINT ' \n + QUOTENAME(@constraint_name)\n + ';';\n --PRINT @tsql;\n INSERT sync_createCHECK \n (\n Script\n )\n VALUES (\n @tsql\n ) \n END;\n\n FETCH NEXT FROM FKcursor INTO \n @schema_name\n , @table_name\n , @constraint_name\n , @referenced_object_name\n , @constraint_object_id\n , @is_disabled\n , @is_not_for_replication\n , @is_not_trusted\n , @delete_referential_action\n , @update_referential_action\n , @referenced_schema_name;\n\nEND;\n\nCLOSE FKcursor;\n\nDEALLOCATE FKcursor;\n\n--SELECT * FROM sync_DropFK\n--SELECT * FROM sync_CreateFK\n--SELECT * FROM sync_CreateCHECK\n---------------------------------------------------------------------------\n2.)\n-----------------------------------------------------------------------------------------------------------------\n----------------------------execute Drop FK Scripts --------------------------------------------------\n\nDECLARE @scriptD NVARCHAR(4000)\n\nDECLARE DropFKCursor CURSOR FOR\n SELECT Script \n FROM sync_dropFK WITH (NOLOCK)\n\nOPEN DropFKCursor\n\nFETCH NEXT FROM DropFKCursor\nINTO @scriptD\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n--PRINT @scriptD\nEXEC (@scriptD)\nFETCH NEXT FROM DropFKCursor\nINTO @scriptD\nEND\nCLOSE DropFKCursor\nDEALLOCATE DropFKCursor\n--------------------------------------------------------------------------------\n3.) \n\n------------------------------------------------------------------------------------------------------------------\n----------------------------Truncate all tables in the database other than our staging tables --------------------\n------------------------------------------------------------------------------------------------------------------\n\n\nEXEC sp_MSforeachtable 'IF OBJECT_ID(''?'') NOT IN \n(\nISNULL(OBJECT_ID(''dbo.sync_createCHECK''),0),\nISNULL(OBJECT_ID(''dbo.sync_createFK''),0),\nISNULL(OBJECT_ID(''dbo.sync_dropFK''),0)\n)\nBEGIN TRY\n TRUNCATE TABLE ?\nEND TRY\nBEGIN CATCH\n PRINT ''Truncation failed on''+ ? +''\nEND CATCH;' \nGO\n-------------------------------------------------------------------------------\n-------------------------------------------------------------------------------------------------\n----------------------------execute Create FK Scripts and CHECK CONSTRAINT Scripts---------------\n----------------------------tack me at the end of the ETL in a SQL task-------------------------\n-------------------------------------------------------------------------------------------------\nDECLARE @scriptC NVARCHAR(4000)\n\nDECLARE CreateFKCursor CURSOR FOR\n SELECT Script \n FROM sync_createFK WITH (NOLOCK)\n\nOPEN CreateFKCursor\n\nFETCH NEXT FROM CreateFKCursor\nINTO @scriptC\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n--PRINT @scriptC\nEXEC (@scriptC)\nFETCH NEXT FROM CreateFKCursor\nINTO @scriptC\nEND\nCLOSE CreateFKCursor\nDEALLOCATE CreateFKCursor\n-------------------------------------------------------------------------------------------------\nDECLARE @scriptCh NVARCHAR(4000)\n\nDECLARE CreateCHECKCursor CURSOR FOR\n SELECT Script \n FROM sync_createCHECK WITH (NOLOCK)\n\nOPEN CreateCHECKCursor\n\nFETCH NEXT FROM CreateCHECKCursor\nINTO @scriptCh\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n--PRINT @scriptCh\nEXEC (@scriptCh)\nFETCH NEXT FROM CreateCHECKCursor\nINTO @scriptCh\nEND\nCLOSE CreateCHECKCursor\nDEALLOCATE CreateCHECKCursor\n"
},
{
"answer_id": 35427150,
"author": "Scott Munro",
"author_id": 81595,
"author_profile": "https://Stackoverflow.com/users/81595",
"pm_score": 4,
"selected": false,
"text": "WITH CHECK CHECK"
},
{
"answer_id": 36387561,
"author": "Zak Willis",
"author_id": 4618168,
"author_profile": "https://Stackoverflow.com/users/4618168",
"pm_score": 1,
"selected": false,
"text": "/****** Object: UserDefinedTableType [util].[typ_objects_for_managing] Script Date: 03/04/2016 16:42:55 ******/\nCREATE TYPE [util].[typ_objects_for_managing] AS TABLE(\n [schema] [sysname] NOT NULL,\n [object] [sysname] NOT NULL\n)\nGO\n\ncreate procedure [util].[truncate_table_with_constraints]\n@objects_for_managing util.typ_objects_for_managing readonly\n\n--@schema sysname\n--,@table sysname\n\nas \n--select\n-- @table = 'TABLE',\n-- @schema = 'SCHEMA'\n\ndeclare @exec_table as table (ordinal int identity (1,1), statement nvarchar(4000), primary key (ordinal));\n\n--print '/*Drop Foreign Key Statements for ['+@schema+'].['+@table+']*/'\n\ninsert into @exec_table (statement)\nselect\n 'ALTER TABLE ['+SCHEMA_NAME(o.schema_id)+'].['+ o.name+'] DROP CONSTRAINT ['+fk.name+']'\nfrom sys.foreign_keys fk\ninner join sys.objects o\n on fk.parent_object_id = o.object_id\nwhere \nexists ( \nselect * from @objects_for_managing chk \nwhere \nchk.[schema] = SCHEMA_NAME(o.schema_id) \nand \nchk.[object] = o.name\n) \n;\n --o.name = @table and\n --SCHEMA_NAME(o.schema_id) = @schema\n\ninsert into @exec_table (statement) \nselect\n'TRUNCATE TABLE ' + src.[schema] + '.' + src.[object] \nfrom @objects_for_managing src\n; \n\n--print '/*Create Foreign Key Statements for ['+@schema+'].['+@table+']*/'\ninsert into @exec_table (statement)\nselect 'ALTER TABLE ['+SCHEMA_NAME(o.schema_id)+'].['+o.name+'] ADD CONSTRAINT ['+fk.name+'] FOREIGN KEY (['+c.name+']) \nREFERENCES ['+SCHEMA_NAME(refob.schema_id)+'].['+refob.name+'](['+refcol.name+'])'\nfrom sys.foreign_key_columns fkc\ninner join sys.foreign_keys fk\n on fkc.constraint_object_id = fk.object_id\ninner join sys.objects o\n on fk.parent_object_id = o.object_id\ninner join sys.columns c\n on fkc.parent_column_id = c.column_id and\n o.object_id = c.object_id\ninner join sys.objects refob\n on fkc.referenced_object_id = refob.object_id\ninner join sys.columns refcol\n on fkc.referenced_column_id = refcol.column_id and\n fkc.referenced_object_id = refcol.object_id\nwhere \nexists ( \nselect * from @objects_for_managing chk \nwhere \nchk.[schema] = SCHEMA_NAME(o.schema_id) \nand \nchk.[object] = o.name\n) \n;\n\n --o.name = @table and\n --SCHEMA_NAME(o.schema_id) = @schema\n\n\n\ndeclare @looper int , @total_records int, @sql_exec nvarchar(4000)\n\nselect @looper = 1, @total_records = count(*) from @exec_table; \n\nwhile @looper <= @total_records \nbegin\n\nselect @sql_exec = (select statement from @exec_table where ordinal =@looper)\nexec sp_executesql @sql_exec \nprint @sql_exec \nset @looper = @looper + 1\nend\n"
},
{
"answer_id": 39510458,
"author": "Alex Hinton",
"author_id": 1288077,
"author_profile": "https://Stackoverflow.com/users/1288077",
"pm_score": 1,
"selected": false,
"text": "declare @schema nvarchar(max) = 'and Schema_Id=Schema_id(''Value'')'\ndeclare @deletiontables nvarchar(max) = '(''TableA'',''TableB'')'\ndeclare @truncateclause nvarchar(max) = @schema + ' and o.Name not in ' + + @deletiontables;\ndeclare @deleteclause nvarchar(max) = @schema + ' and o.Name in ' + @deletiontables; \n\nexec sp_MSforeachtable 'alter table ? nocheck constraint all', @whereand=@schema\nexec sp_MSforeachtable 'truncate table ?', @whereand=@truncateclause\nexec sp_MSforeachtable 'delete from ?', @whereand=@deleteclause\nexec sp_MSforeachtable 'alter table ? with check check constraint all', @whereand=@schema\n"
},
{
"answer_id": 42070759,
"author": "V. Agarwal",
"author_id": 5721483,
"author_profile": "https://Stackoverflow.com/users/5721483",
"pm_score": 2,
"selected": false,
"text": "select 'ALTER TABLE ' + object_name(id) + ' NOCHECK CONSTRAINT [' + object_name(constid) + ']'\nfrom sys.sysconstraints \nwhere status & 0x4813 = 0x813 order by object_name(id)\n"
},
{
"answer_id": 43004614,
"author": "lwilliams",
"author_id": 7763336,
"author_profile": "https://Stackoverflow.com/users/7763336",
"pm_score": 2,
"selected": false,
"text": "Alter table MyTable nocheck constraint FK_ForeignKeyConstraintName\n"
},
{
"answer_id": 51645951,
"author": "Carter Medlin",
"author_id": 324479,
"author_profile": "https://Stackoverflow.com/users/324479",
"pm_score": 1,
"selected": false,
"text": "DECLARE @sql AS NVARCHAR(max)=''\nselect @sql = @sql +\n 'ALTER INDEX ALL ON [' + t.[name] + '] DISABLE;'+CHAR(13)\nfrom \n sys.tables t\nwhere type='u'\n\nselect @sql = @sql +\n 'ALTER INDEX ' + i.[name] + ' ON [' + t.[name] + '] REBUILD;'+CHAR(13)\nfrom \n sys.key_constraints i\njoin\n sys.tables t on i.parent_object_id=t.object_id\nwhere\n i.type='PK'\n\n\nexec dbo.sp_executesql @sql;\ngo\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159038",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] |
159,076
|
<p>I have a c# application that runs as a windows service controlling socket connections and other things.
Also, there is another windows forms application to control and configure this service (systray with start, stop, show form with configuration parameters).</p>
<p>I'm using .net remoting to do the IPC and that was fine, but now I want to show some real traffic and other reports and remoting will not meet my performance requirements. So I want to combine both applications in one. </p>
<p>Here is the problem:</p>
<p>When I started the form from the windows service, nothing happened. Googling around I've found that I have to right click the service, go to Log on and check the "Allow service to interact with desktop" option. Since I don't want to ask my users to do that, I got some code googling again to set this option in the user's regedit during installation time. The problem is that even setting this option, it doesn't work. I have to open the Log On options of the service (it is checked), uncheck and check again.</p>
<p><strong>So, how to solve that? How is the best way to have a windows service with a systray control in the same process, available to any user logging in?</strong></p>
<p>UPDATE: Thanks for the comments so far, guys. I agree it is better to use IPC and I know that it is bad to mix windows services and user interfaces. Even though, I want to know how to do that.</p>
|
[
{
"answer_id": 221705,
"author": "CoolMagic",
"author_id": 22641,
"author_profile": "https://Stackoverflow.com/users/22641",
"pm_score": 0,
"selected": false,
"text": "ref class RunWindow{\npublic:\n static void MakeWindow(Object^ data)\n {\n Application::EnableVisualStyles();\n Application::SetCompatibleTextRenderingDefault(false); \n\n Application::Run(gcnew TMainForm());\n };\n};\n"
},
{
"answer_id": 1790642,
"author": "Phil",
"author_id": 138757,
"author_profile": "https://Stackoverflow.com/users/138757",
"pm_score": 1,
"selected": false,
"text": "string wmiPath = \"Win32_Service.Name='\" + SERVICE_NAME + \"'\";\nusing (ManagementObject service = new ManagementObject(wmiPath))\n{\n object[] parameters = new object[11];\n parameters[5] = true; // Enable desktop interaction\n service.InvokeMethod(\"Change\", parameters);\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22693/"
] |
159,087
|
<p>I inherited a database built with the idea that composite keys are much more ideal than using a unique object ID field and that when building a database, a single unique ID should <b><em>never</em></b> be used as a primary key. Because I was building a Rails front-end for this database, I ran into difficulties getting it to conform to the Rails conventions (though it was possible using custom views and a few additional gems to handle composite keys).</p>
<p>The reasoning behind this specific schema design from the person who wrote it had to do with how the database handles ID fields in a non-efficient manner and when it's building indexes, tree sorts are flawed. This explanation lacked any depth and I'm still trying to wrap my head around the concept (I'm familiar with using composite keys, but not 100% of the time).</p>
<p>Can anyone offer opinions or add any greater depth to this topic? </p>
|
[
{
"answer_id": 160085,
"author": "JeremyDWill",
"author_id": 12603,
"author_profile": "https://Stackoverflow.com/users/12603",
"pm_score": 7,
"selected": true,
"text": "\"SELECT InvoiceNumber FROM Invoice WHERE CustomerCode = 'XYZ123'\""
},
{
"answer_id": 161382,
"author": "Hank Gay",
"author_id": 4203,
"author_profile": "https://Stackoverflow.com/users/4203",
"pm_score": 1,
"selected": false,
"text": "DOMAIN"
},
{
"answer_id": 164338,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 3,
"selected": false,
"text": "computer"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23909/"
] |
159,088
|
<p>In WPF:</p>
<p>Can someone please explain the relationship between DependencyProperty and Databinding?</p>
<p>I have a property in my code behind I want to be the source of my databinding.
When does a DependencyProperty (or does it) come into play if I want to bind this object to textboxes on the XAML.</p>
|
[
{
"answer_id": 159284,
"author": "Joel B Fant",
"author_id": 22211,
"author_profile": "https://Stackoverflow.com/users/22211",
"pm_score": 5,
"selected": true,
"text": "DependencyProperty"
},
{
"answer_id": 67103647,
"author": "james.lee",
"author_id": 9438258,
"author_profile": "https://Stackoverflow.com/users/9438258",
"pm_score": 0,
"selected": false,
"text": "sealed"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2744/"
] |
159,097
|
<p>Is there any way to output the contents of an XDocument without the BOM? When reading the output with Flash, it causes errors.</p>
|
[
{
"answer_id": 159203,
"author": "Chris Wenham",
"author_id": 5548,
"author_profile": "https://Stackoverflow.com/users/5548",
"pm_score": 4,
"selected": true,
"text": "XmlWriter writer = XmlWriter.Create(\"foo.xml\");\nwriter.Settings.Encoding = new System.Text.UTF8Encoding(false);\nmyXDocument.WriteTo(writer);\n"
},
{
"answer_id": 159299,
"author": "Chris Shaffer",
"author_id": 6744,
"author_profile": "https://Stackoverflow.com/users/6744",
"pm_score": 2,
"selected": false,
"text": "\nMemoryStream ms = new MemoryStream();\nStreamWriter writer = new StreamWriter(ms, new UTF8Encoding(false));\nxmlDocument.Save(writer);\n"
},
{
"answer_id": 594343,
"author": "MattH",
"author_id": 71813,
"author_profile": "https://Stackoverflow.com/users/71813",
"pm_score": 2,
"selected": false,
"text": "using(XmlWriter...) {...}"
},
{
"answer_id": 3108266,
"author": "Reed Rector",
"author_id": 409194,
"author_profile": "https://Stackoverflow.com/users/409194",
"pm_score": 3,
"selected": false,
"text": "XmlWriterSettings settings = new XmlWriterSettings();\nsettings.Encoding = new System.Text.UTF8Encoding(false); \n\nXmlWriter writer = XmlWriter.Create(\"foo.xml\", settings); \nmyXDocument.WriteTo(writer); \n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1786/"
] |
159,118
|
<p>For example, this regex</p>
<pre><code>(.*)<FooBar>
</code></pre>
<p>will match:</p>
<pre><code>abcde<FooBar>
</code></pre>
<p>But how do I get it to match across multiple lines?</p>
<pre><code>abcde
fghij<FooBar>
</code></pre>
|
[
{
"answer_id": 159139,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 9,
"selected": true,
"text": "/(.*)<FooBar>/s\n"
},
{
"answer_id": 159140,
"author": "levik",
"author_id": 4465,
"author_profile": "https://Stackoverflow.com/users/4465",
"pm_score": 9,
"selected": false,
"text": "((.|\\n)*)<FooBar>\n"
},
{
"answer_id": 159141,
"author": "Markus Jarderot",
"author_id": 22364,
"author_profile": "https://Stackoverflow.com/users/22364",
"pm_score": 3,
"selected": false,
"text": "\".\""
},
{
"answer_id": 159142,
"author": "tloach",
"author_id": 14092,
"author_profile": "https://Stackoverflow.com/users/14092",
"pm_score": 2,
"selected": false,
"text": "."
},
{
"answer_id": 159146,
"author": "Bill",
"author_id": 24190,
"author_profile": "https://Stackoverflow.com/users/24190",
"pm_score": 3,
"selected": false,
"text": "/(.*)<FooBar>/s\n"
},
{
"answer_id": 160781,
"author": "tye",
"author_id": 21496,
"author_profile": "https://Stackoverflow.com/users/21496",
"pm_score": 3,
"selected": false,
"text": "(.|\\n)*"
},
{
"answer_id": 686146,
"author": "Slee",
"author_id": 34548,
"author_profile": "https://Stackoverflow.com/users/34548",
"pm_score": 1,
"selected": false,
"text": "mystring = Regex.Replace(mystring, \"\\r\\n\", \"\")\n"
},
{
"answer_id": 2626317,
"author": "shmall",
"author_id": 315032,
"author_profile": "https://Stackoverflow.com/users/315032",
"pm_score": 3,
"selected": false,
"text": "."
},
{
"answer_id": 4722479,
"author": "Spangen",
"author_id": 491557,
"author_profile": "https://Stackoverflow.com/users/491557",
"pm_score": 0,
"selected": false,
"text": " ...\n ...\n if(isTrue){\n doAction();\n\n }\n...\n...\n}\n"
},
{
"answer_id": 6883270,
"author": "Abbas Shahzadeh",
"author_id": 870668,
"author_profile": "https://Stackoverflow.com/users/870668",
"pm_score": 5,
"selected": false,
"text": "/[\\S\\s]*<Foobar>/"
},
{
"answer_id": 8269712,
"author": "Paulo Merson",
"author_id": 317522,
"author_profile": "https://Stackoverflow.com/users/317522",
"pm_score": 6,
"selected": false,
"text": "(?s).*<FooBar>\n"
},
{
"answer_id": 10009766,
"author": "Sian Lerk Lau",
"author_id": 1259696,
"author_profile": "https://Stackoverflow.com/users/1259696",
"pm_score": 2,
"selected": false,
"text": "sU"
},
{
"answer_id": 10262550,
"author": "user1348737",
"author_id": 1348737,
"author_profile": "https://Stackoverflow.com/users/1348737",
"pm_score": 0,
"selected": false,
"text": "<TASK>\n <UID>21</UID>\n <Name>Architectural design</Name>\n <PercentComplete>81</PercentComplete>\n</TASK>\n"
},
{
"answer_id": 11566656,
"author": "samwize",
"author_id": 242682,
"author_profile": "https://Stackoverflow.com/users/242682",
"pm_score": 5,
"selected": false,
"text": "([\\s\\S]*)<FooBar>"
},
{
"answer_id": 11791527,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "m"
},
{
"answer_id": 14138105,
"author": "Gordon",
"author_id": 1945412,
"author_profile": "https://Stackoverflow.com/users/1945412",
"pm_score": 3,
"selected": false,
"text": "Foo[\\S\\s]{1,10}.*Bar*\n"
},
{
"answer_id": 16890999,
"author": "Kamahire",
"author_id": 483191,
"author_profile": "https://Stackoverflow.com/users/483191",
"pm_score": 2,
"selected": false,
"text": "[\\s\\S]"
},
{
"answer_id": 45981809,
"author": "Wiktor Stribiżew",
"author_id": 3832970,
"author_profile": "https://Stackoverflow.com/users/3832970",
"pm_score": 7,
"selected": false,
"text": "."
},
{
"answer_id": 51702858,
"author": "Nambi_0915",
"author_id": 9976846,
"author_profile": "https://Stackoverflow.com/users/9976846",
"pm_score": 4,
"selected": false,
"text": "(.*?\\n)*?\n"
},
{
"answer_id": 54905939,
"author": "Paul Chris Jones",
"author_id": 2395096,
"author_profile": "https://Stackoverflow.com/users/2395096",
"pm_score": 2,
"selected": false,
"text": "$(\"#find_and_replace\").click(function() {\n var text = $(\"#textarea\").val();\n search_term = new RegExp(\"[^]*<Foobar>\", \"gi\");;\n replace_term = \"Replacement term\";\n var new_text = text.replace(search_term, replace_term);\n $(\"#textarea\").val(new_text);\n});"
},
{
"answer_id": 56904709,
"author": "js2010",
"author_id": 6654942,
"author_profile": "https://Stackoverflow.com/users/6654942",
"pm_score": 0,
"selected": false,
"text": "$file = Get-Content file.txt -raw\n\n$pattern = 'lineone\\r\\nlinetwo\\r\\nlinethree\\r\\n' # \"Windows\" text\n$pattern = 'lineone\\nlinetwo\\nlinethree\\n' # \"Unix\" text\n$pattern = 'lineone\\r?\\nlinetwo\\r?\\nlinethree\\r?\\n' # Both\n\n$file -match $pattern\n\n# output\nTrue\n"
},
{
"answer_id": 58260661,
"author": "Emma",
"author_id": 6553328,
"author_profile": "https://Stackoverflow.com/users/6553328",
"pm_score": -1,
"selected": false,
"text": "s"
},
{
"answer_id": 63637587,
"author": "hafiz031",
"author_id": 6907424,
"author_profile": "https://Stackoverflow.com/users/6907424",
"pm_score": 1,
"selected": false,
"text": ".*\\n*.*<FooBar>"
},
{
"answer_id": 70901941,
"author": "Hammad Khan",
"author_id": 777982,
"author_profile": "https://Stackoverflow.com/users/777982",
"pm_score": 2,
"selected": false,
"text": "<table (.|\\r\\n)*</table>\n"
},
{
"answer_id": 73492192,
"author": "Mateusz Kaflowski",
"author_id": 1604309,
"author_profile": "https://Stackoverflow.com/users/1604309",
"pm_score": 1,
"selected": false,
"text": "(\\X*)<FooBar>\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2108/"
] |
159,137
|
<p>I need a cross platform method of determining the MAC address of a computer at run time. For windows the 'wmi' module can be used and the only method under Linux I could find was to run ifconfig and run a regex across its output. I don't like using a package that only works on one OS, and parsing the output of another program doesn't seem very elegant not to mention error prone. </p>
<p>Does anyone know a cross platform method (windows and linux) method to get the MAC address? If not, does anyone know any more elegant methods then those I listed above?</p>
|
[
{
"answer_id": 159150,
"author": "camflan",
"author_id": 22445,
"author_profile": "https://Stackoverflow.com/users/22445",
"pm_score": 5,
"selected": false,
"text": "netifaces"
},
{
"answer_id": 159195,
"author": "Armin Ronacher",
"author_id": 19990,
"author_profile": "https://Stackoverflow.com/users/19990",
"pm_score": 9,
"selected": true,
"text": "from uuid import getnode as get_mac\nmac = get_mac()\n"
},
{
"answer_id": 159236,
"author": "DGentry",
"author_id": 4761,
"author_profile": "https://Stackoverflow.com/users/4761",
"pm_score": -1,
"selected": false,
"text": "struct ifreq ifr;\nuint8_t macaddr[6];\n\nif ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)\n return -1;\n\nstrcpy(ifr.ifr_name, \"eth0\");\n\nif (ioctl(s, SIOCGIFHWADDR, (void *)&ifr) == 0) {\n if (ifr.ifr_hwaddr.sa_family == ARPHRD_ETHER) {\n memcpy(macaddr, ifr.ifr_hwaddr.sa_data, 6);\n return 0;\n... etc ...\n"
},
{
"answer_id": 159992,
"author": "John Fouhy",
"author_id": 15154,
"author_profile": "https://Stackoverflow.com/users/15154",
"pm_score": 2,
"selected": false,
"text": "import platform\nif platform.system() == 'Linux':\n import LinuxMac\n mac_address = LinuxMac.get_mac_address()\nelif platform.system() == 'Windows':\n # etc\n"
},
{
"answer_id": 160821,
"author": "mhawke",
"author_id": 21945,
"author_profile": "https://Stackoverflow.com/users/21945",
"pm_score": 5,
"selected": false,
"text": "uuid.getnode()"
},
{
"answer_id": 4789267,
"author": "synthesizerpatel",
"author_id": 210613,
"author_profile": "https://Stackoverflow.com/users/210613",
"pm_score": 7,
"selected": false,
"text": "#!/usr/bin/python\n\nimport fcntl, socket, struct\n\ndef getHwAddr(ifname):\n s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))\n return ':'.join(['%02x' % ord(char) for char in info[18:24]])\n\nprint getHwAddr('eth0')\n"
},
{
"answer_id": 17884450,
"author": "Sarath Sadasivan Pillai",
"author_id": 1898494,
"author_profile": "https://Stackoverflow.com/users/1898494",
"pm_score": -1,
"selected": false,
"text": " ifconfig eth0 | grep HWaddr |cut -dH -f2|cut -d\\ -f2\n 00:26:6c:df:c3:95\n"
},
{
"answer_id": 18031954,
"author": "kursancew",
"author_id": 2362361,
"author_profile": "https://Stackoverflow.com/users/2362361",
"pm_score": 3,
"selected": false,
"text": "netifaces"
},
{
"answer_id": 32080877,
"author": "Julio Schurt",
"author_id": 3960185,
"author_profile": "https://Stackoverflow.com/users/3960185",
"pm_score": 5,
"selected": false,
"text": "def getmac(interface):\n try:\n mac = open('/sys/class/net/'+interface+'/address').readline()\n except:\n mac = \"00:00:00:00:00:00\"\n return mac[0:17]\n"
},
{
"answer_id": 41076835,
"author": "Python Novice",
"author_id": 3491787,
"author_profile": "https://Stackoverflow.com/users/3491787",
"pm_score": 3,
"selected": false,
"text": "import psutil\nnics = psutil.net_if_addrs()\nprint [j.address for j in nics[i] for i in nics if i!=\"lo\" and j.family==17]\n"
},
{
"answer_id": 51646850,
"author": "Ghost of Goes",
"author_id": 2214380,
"author_profile": "https://Stackoverflow.com/users/2214380",
"pm_score": 2,
"selected": false,
"text": "from getmac import get_mac_address\neth_mac = get_mac_address(interface=\"eth0\")\nwin_mac = get_mac_address(interface=\"Ethernet 3\")\nip_mac = get_mac_address(ip=\"192.168.0.1\")\nip6_mac = get_mac_address(ip6=\"::1\")\nhost_mac = get_mac_address(hostname=\"localhost\")\nupdated_mac = get_mac_address(ip=\"10.0.0.1\", network_request=True)\n"
},
{
"answer_id": 54399806,
"author": "Ajay Kumar K K",
"author_id": 6223994,
"author_profile": "https://Stackoverflow.com/users/6223994",
"pm_score": -1,
"selected": false,
"text": "import uuid\nmac_id=(':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff)\n"
},
{
"answer_id": 58237728,
"author": "Balaji Reddy",
"author_id": 4241487,
"author_profile": "https://Stackoverflow.com/users/4241487",
"pm_score": 2,
"selected": false,
"text": "eth0"
},
{
"answer_id": 73189303,
"author": "Sushen Biswas",
"author_id": 8118777,
"author_profile": "https://Stackoverflow.com/users/8118777",
"pm_score": 1,
"selected": false,
"text": "import psutil\n\nnics = psutil.net_if_addrs()\n\nmac_address = nics['Ethernet'][0].address\n\nprint(mac_address)\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9940/"
] |
159,148
|
<p>Groovy adds the <code>execute</code> method to <code>String</code> to make executing shells fairly easy;</p>
<pre><code>println "ls".execute().text
</code></pre>
<p>but if an error happens, then there is no resulting output. <strong>Is there an easy way to get both the standard error and standard out?</strong> (other than creating a bunch of code to; create two threads to read both inputstreams, then using a parent stream to wait for them to complete then convert the strings back to text?)</p>
<p>It would be nice to have something like;</p>
<pre><code> def x = shellDo("ls /tmp/NoFile")
println "out: ${x.out} err:${x.err}"
</code></pre>
|
[
{
"answer_id": 159244,
"author": "Joshua",
"author_id": 6013,
"author_profile": "https://Stackoverflow.com/users/6013",
"pm_score": 6,
"selected": false,
"text": "\"ls\".execute()"
},
{
"answer_id": 159270,
"author": "Bob Herrmann",
"author_id": 6580,
"author_profile": "https://Stackoverflow.com/users/6580",
"pm_score": 9,
"selected": true,
"text": "def sout = new StringBuilder(), serr = new StringBuilder()\ndef proc = 'ls /badDir'.execute()\nproc.consumeProcessOutput(sout, serr)\nproc.waitForOrKill(1000)\nprintln \"out> $sout\\nerr> $serr\"\n"
},
{
"answer_id": 12270627,
"author": "mholm815",
"author_id": 959352,
"author_profile": "https://Stackoverflow.com/users/959352",
"pm_score": 5,
"selected": false,
"text": "// a wrapper closure around executing a string \n// can take either a string or a list of strings (for arguments with spaces) \n// prints all output, complains and halts on error \ndef runCommand = { strList ->\n assert ( strList instanceof String ||\n ( strList instanceof List && strList.each{ it instanceof String } ) \\\n)\n def proc = strList.execute()\n proc.in.eachLine { line -> println line }\n proc.out.close()\n proc.waitFor()\n\n print \"[INFO] ( \"\n if(strList instanceof List) {\n strList.each { print \"${it} \" }\n } else {\n print strList\n }\n println \" )\"\n\n if (proc.exitValue()) {\n println \"gave the following error: \"\n println \"[ERROR] ${proc.getErrorStream()}\"\n }\n assert !proc.exitValue()\n}\n"
},
{
"answer_id": 25337451,
"author": "Aniket Thakur",
"author_id": 2396539,
"author_profile": "https://Stackoverflow.com/users/2396539",
"pm_score": 5,
"selected": false,
"text": "def proc = command.execute();\n"
},
{
"answer_id": 39629638,
"author": "emles-kz",
"author_id": 6861819,
"author_profile": "https://Stackoverflow.com/users/6861819",
"pm_score": 3,
"selected": false,
"text": "def exec = { encoding, execPath, execStr, execCommands ->\n\ndef outputCatcher = new ByteArrayOutputStream()\ndef errorCatcher = new ByteArrayOutputStream()\n\ndef proc = execStr.execute(null, new File(execPath))\ndef inputCatcher = proc.outputStream\n\nexecCommands.each { cm ->\n inputCatcher.write(cm.getBytes(encoding))\n inputCatcher.flush()\n}\n\nproc.consumeProcessOutput(outputCatcher, errorCatcher)\nproc.waitFor()\n\nreturn [new String(outputCatcher.toByteArray(), encoding), new String(errorCatcher.toByteArray(), encoding)]\n\n}\n\ndef out = exec(\"cp866\", \"C:\\\\Test\", \"cmd\", [\"cd..\\n\", \"dir\\n\", \"exit\\n\"])\n\nprintln \"OUT:\\n\" + out[0]\nprintln \"ERR:\\n\" + out[1]\n"
},
{
"answer_id": 42126817,
"author": "solstice333",
"author_id": 2630028,
"author_profile": "https://Stackoverflow.com/users/2630028",
"pm_score": 5,
"selected": false,
"text": "def proc = \"ls foo.txt doesnotexist.txt\".execute()\nassert proc.in.text == \"foo.txt\\n\"\nassert proc.err.text == \"ls: doesnotexist.txt: No such file or directory\\n\"\n"
},
{
"answer_id": 45070674,
"author": "舒何伟",
"author_id": 7387017,
"author_profile": "https://Stackoverflow.com/users/7387017",
"pm_score": -1,
"selected": false,
"text": "command = \"ls *\"\n\ndef execute_state=sh(returnStdout: true, script: command)\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6580/"
] |
159,152
|
<p>Is there a way with SVN to check out from a remote repository to another remote location rather than my local file system? Something like:</p>
<pre><code>svn co http://myrepository/svn/project ssh me@otherlocation.net:/var/www/project
</code></pre>
|
[
{
"answer_id": 159467,
"author": "davr",
"author_id": 14569,
"author_profile": "https://Stackoverflow.com/users/14569",
"pm_score": 4,
"selected": true,
"text": "ssh me@other.net 'svn co http://repository/svn/project /var/www/project'\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/577/"
] |
159,183
|
<p>I want to resize the font of a SPAN element's style until it the SPAN's text is 7.5 inches wide when printed out on paper, but JavaScript only reports the SPAN's clientWidth property in pixels.</p>
<pre><code><span id="test">123456</span>
</code></pre>
<p>And then:</p>
<pre><code>#test {
font-size:1.2in; /* adjust this for yourself until printout measures 7.5in wide */
}
</code></pre>
<p>And then:</p>
<pre><code>console.log(document.getElementById('test').clientWidth);
</code></pre>
<p>I've determined experimentally on one machine that it uses approximately 90 DPI as a conversion factor, because the above code logs approximately 675, at least under Firefox 3.</p>
<p>This number is not necessarily the same under different browser, printer, screen, etc. configurations.</p>
<p>So, how do I find the DPI the browser is using? What can I call to get back "90" on my system?</p>
|
[
{
"answer_id": 159316,
"author": "neonski",
"author_id": 17112,
"author_profile": "https://Stackoverflow.com/users/17112",
"pm_score": 1,
"selected": false,
"text": "<link rel=\"stylesheet\" type=\"text/css\" href=\"print.css\" media=\"print\" />\n"
},
{
"answer_id": 159322,
"author": "JacquesB",
"author_id": 7488,
"author_profile": "https://Stackoverflow.com/users/7488",
"pm_score": 0,
"selected": false,
"text": "@media print { #test { width: 7in; }}\n"
},
{
"answer_id": 159361,
"author": "Bill",
"author_id": 24190,
"author_profile": "https://Stackoverflow.com/users/24190",
"pm_score": 3,
"selected": true,
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<title>Untitled Document</title>\n<style type=\"text/css\">\n#container {width: 7in; border: solid 1px red;}\n#span {display: table-cell; width: 1px; border: solid 1px blue; font-size: 12px;}\n</style>\n<script language=\"javascript\" type=\"text/javascript\">\nfunction resizeText() {\n var container = document.getElementById(\"container\");\n var span = document.getElementById(\"span\");\n\n var containerWidth = container.clientWidth;\n var spanWidth = span.clientWidth; \n var nAttempts = 900;\n var i=1;\n var font_size = 12;\n\n while ( spanWidth < containerWidth && i < nAttempts ) {\n span.style.fontSize = font_size+\"px\";\n\n spanWidth = span.clientWidth;\n\n font_size++;\n i++;\n } \n}\n</script>\n</head>\n\n<body>\n<div id=\"container\">\n<span id=\"span\">test</span>\n</div>\n<a href=\"javascript:resizeText();\">resize text</a>\n</body>\n</html>\n"
},
{
"answer_id": 159586,
"author": "Kev",
"author_id": 16777,
"author_profile": "https://Stackoverflow.com/users/16777",
"pm_score": -1,
"selected": false,
"text": "var bob = document.body.appendChild(document.createElement('div'));\nbob.innerHTML = \"<div id='jake' style='width:1in'>j</div>\";\nalert(document.getElementById('jake').clientWidth);\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16777/"
] |
159,190
|
<p>In Eclipse, its easy to specify buttons for your toolbar using the ActionSets extension point. However, when I need to specify some items programmatically, I can't get the same look. I don't believe that the framework is using native buttons for these, but so far, I can't find the right recipe to match the Eclipse look. I wanted to see if anyone has found the right snippet to duplicate this functionality in code.</p>
|
[
{
"answer_id": 439165,
"author": "hudsonb",
"author_id": 53923,
"author_profile": "https://Stackoverflow.com/users/53923",
"pm_score": 4,
"selected": true,
"text": "IToolBarManager toolBarManager = actionBars.getToolBarManager();\ntoolBarManager.add(new ControlContribution(\"Toggle Chart\") {\n @Override\n protected Control createControl(Composite parent)\n {\n Button button = new Button(parent, SWT.PUSH);\n button.addSelectionListener(new SelectionAdapter() {\n @Override\n public void widgetSelected(SelectionEvent e) {\n // Perform action\n }\n });\n }\n});\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16476/"
] |
159,237
|
<p>I'm working in .Net 3.5sp1 in C# for an ASP.Net solution and I'm wondering if there's any way to turn on the Class Name and Method Name drop-downs in the text editor that VB.Net has at the top. It's one of the few things from VB that I actually miss.</p>
<p>Edit: Also, is there any way to get the drop downs to be populated with the possible events?</p>
<p>e.g. (Page Events) | (Declarations)</p>
|
[
{
"answer_id": 159246,
"author": "casademora",
"author_id": 5619,
"author_profile": "https://Stackoverflow.com/users/5619",
"pm_score": 3,
"selected": true,
"text": "Tools -> Options -> Text Editor -> C# -> General -> Navigation Bar\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1414/"
] |
159,240
|
<p>The more we use RAII in C++, the more we find ourselves with destructors that do non-trivial deallocation. Now, deallocation (finalization, however you want to call it) can fail, in which case exceptions are really the only way to let anybody upstairs know of our deallocation problem. But then again, throwing-destructors are a bad idea because of the possibility of exceptions being thrown during stack unwinding. <code>std::uncaught_exception()</code> lets you know when that happens, but not much more, so aside from letting you log a message before termination there's not much you can do, unless you're willing to leave your program in an undefined state, where some stuff is deallocated/finalized and some not.</p>
<p>One approach is to have no-throw destructors. But in many cases that just hides a real error. Our destructor might, for example, be closing some RAII-managed DB connections as a result of some exception being thrown, and those DB connections might fail to close. This doesn't necessarily mean we're ok with the program terminating at this point. On the other hand, logging and tracing these errors isn't really a solution for every case; otherwise we would have had no need for exceptions to begin with.
With no-throw destructors we also find ourselves having to create "reset()" functions that are supposed to be called before destruction - but that just defeats the whole purpose of RAII.</p>
<p>Another approach is just to <a href="http://www.kolpackov.net/projects/c++/eh/dtor-1.xhtml" rel="noreferrer">let the program terminate</a>, as it's the most predictable thing you can do.</p>
<p>Some people suggest chaining exceptions, so that more than one error can be handled at a time. But I honestly never actually seen that done in C++ and I've no idea how to implement such a thing.</p>
<p>So it's either RAII or exceptions. Isn't it? I'm leaning toward no-throw destructors; mainly because it keeps things simple(r). But I really hope there's a better solution, because, as I said, the more we use RAII, the more we find ourselves using dtors that do non-trivial things.</p>
<p><strong>Appendix</strong></p>
<p>I'm adding links to interesting on-topic articles and discussions I've found:</p>
<ul>
<li><a href="http://www.kolpackov.net/projects/c++/eh/dtor-1.xhtml" rel="noreferrer">Throwing Destructors</a></li>
<li>StackOverflow discussion on the <a href="https://stackoverflow.com/questions/164372/is-there-a-good-way-around-the-problems-of-structured-exception-handling-try-ex">problems with SEH</a></li>
<li>StackOverflow discussion on <a href="https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor#130123">throwing-destructors</a> (thanks, Martin York)</li>
<li><a href="http://www.joelonsoftware.com/items/2003/10/13.html" rel="noreferrer">Joel on Exceptions</a></li>
<li><a href="http://blogs.msdn.com/larryosterman/archive/2004/09/10/228068.aspx" rel="noreferrer">SEH Considered Harmful</a> </li>
<li><a href="http://bartdesmet.net/blogs/bart/archive/2006/04/04/clr-exception-handling-from-a-to-z-everything-you-didn-t-want-to-know-about-try-catch-finally-fault-filter.aspx" rel="noreferrer">CLR Exception Handling</a> which also touches on exception chaining</li>
<li><a href="http://www.gotw.ca/gotw/047.htm" rel="noreferrer">Herb Sutter on std::uncaught_exception</a> and why it's not as useful as you think</li>
<li><a href="http://www.cpptalk.net/1-vt12438.html?postdays=0&postorder=asc&start=0" rel="noreferrer">Historical discussion</a> on the matter with interesting participants (long!)</li>
<li>Stroustrup explaining <a href="http://www.research.att.com/~bs/bs_faq2.html#finally" rel="noreferrer">RAII</a></li>
<li>Andrei Alexandrescu's <a href="http://www.ddj.com/cpp/184403758" rel="noreferrer">Scope Guard</a></li>
</ul>
|
[
{
"answer_id": 159259,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 4,
"selected": false,
"text": "noexcept"
},
{
"answer_id": 159315,
"author": "puetzk",
"author_id": 14312,
"author_profile": "https://Stackoverflow.com/users/14312",
"pm_score": 0,
"selected": false,
"text": "bool std::uncaught_exception()\n"
},
{
"answer_id": 159987,
"author": "Aaron",
"author_id": 14153,
"author_profile": "https://Stackoverflow.com/users/14153",
"pm_score": 3,
"selected": false,
"text": "class DBCon{\npublic:\n DBCon() { \n handle = fooOpenDBConnection();\n }\n ~DBCon() {\n int err = fooCloseDBConnection();\n if(err){\n if(err == E_fooConnectionDropped){\n // do nothing. must have timed out\n } else if(fooIsCriticalError(err)){\n // critical errors aren't recoverable. log, save \n // restart information, and die\n std::clog << \"critical DB error: \" << err << \"\\n\";\n save_recovery_information();\n std::terminate();\n } else {\n // log, in case we need to gather this info in the future,\n // but continue normally.\n std::clog << \"non-critical DB error: \" << err << \"\\n\";\n }\n }\n // done!\n }\n};\n"
},
{
"answer_id": 210437,
"author": "paercebal",
"author_id": 14089,
"author_profile": "https://Stackoverflow.com/users/14089",
"pm_score": 3,
"selected": false,
"text": " void doSomething()\n {\n try\n {\n MyResource A, B, C, D, E ;\n\n // do something with A, B, C, D and E\n\n // Now we quit the scope...\n // destruction of E, then D, then C, then B and then A\n }\n catch(const MyResourceException & e)\n {\n // Do something with the exception...\n }\n }\n"
},
{
"answer_id": 6634009,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 3,
"selected": false,
"text": "close()"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11208/"
] |
159,252
|
<p>When I have a regular textbox in a UpdatePanel (not an ASP.NET control) with some JavaScript events on it, after the UpdatePanel updates my events are gone. Is there a way to re-attach my events after the update? (Preferably without putting my events inline).</p>
|
[
{
"answer_id": 159260,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 1,
"selected": false,
"text": "setInterval()"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18926/"
] |
159,255
|
<p>Bearing in mind that I'll be performing calculations on lat / long pairs, what datatype is best suited for use with a MySQL database?</p>
|
[
{
"answer_id": 159275,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": -1,
"selected": false,
"text": "FLOAT"
},
{
"answer_id": 25120203,
"author": "Simon",
"author_id": 1226018,
"author_profile": "https://Stackoverflow.com/users/1226018",
"pm_score": 7,
"selected": false,
"text": "Datatype Bytes Resolution\n\nDeg*100 (SMALLINT) 4 1570 m 1.0 mi Cities\nDECIMAL(4,2)/(5,2) 5 1570 m 1.0 mi Cities\nSMALLINT scaled 4 682 m 0.4 mi Cities\nDeg*10000 (MEDIUMINT) 6 16 m 52 ft Houses/Businesses\nDECIMAL(6,4)/(7,4) 7 16 m 52 ft Houses/Businesses\nMEDIUMINT scaled 6 2.7 m 8.8 ft\nFLOAT 8 1.7 m 5.6 ft\nDECIMAL(8,6)/(9,6) 9 16cm 1/2 ft Friends in a mall\nDeg*10000000 (INT) 8 16mm 5/8 in Marbles\nDOUBLE 16 3.5nm ... Fleas on a dog\n"
},
{
"answer_id": 27926894,
"author": "Alexander Holsgrove",
"author_id": 519924,
"author_profile": "https://Stackoverflow.com/users/519924",
"pm_score": 5,
"selected": false,
"text": "DECIMAL(8,6)"
},
{
"answer_id": 30853655,
"author": "Gajus",
"author_id": 368691,
"author_profile": "https://Stackoverflow.com/users/368691",
"pm_score": 6,
"selected": false,
"text": "Datatype Bytes resolution\n------------------ ----- --------------------------------\nDeg*100 (SMALLINT) 4 1570 m 1.0 mi Cities\nDECIMAL(4,2)/(5,2) 5 1570 m 1.0 mi Cities\nSMALLINT scaled 4 682 m 0.4 mi Cities\nDeg*10000 (MEDIUMINT) 6 16 m 52 ft Houses/Businesses\nDECIMAL(6,4)/(7,4) 7 16 m 52 ft Houses/Businesses\nMEDIUMINT scaled 6 2.7 m 8.8 ft\nFLOAT 8 1.7 m 5.6 ft\nDECIMAL(8,6)/(9,6) 9 16cm 1/2 ft Friends in a mall\nDeg*10000000 (INT) 8 16mm 5/8 in Marbles\nDOUBLE 16 3.5nm ... Fleas on a dog\n"
},
{
"answer_id": 33941442,
"author": "Armfoot",
"author_id": 1326147,
"author_profile": "https://Stackoverflow.com/users/1326147",
"pm_score": 3,
"selected": false,
"text": "VARCHAR"
},
{
"answer_id": 54307970,
"author": "mahfuz",
"author_id": 2625958,
"author_profile": "https://Stackoverflow.com/users/2625958",
"pm_score": 3,
"selected": false,
"text": "lat DECIMAL(10, 8) NOT NULL, lng DECIMAL(11, 8) NOT NULL"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12037/"
] |
159,261
|
<p>Does anyone have an example of script that can work reliably well across IE/Firefox to detect if the browser is capable of displaying embedded flash content. I say reliably because I know its not possible 100% of the time. </p>
|
[
{
"answer_id": 4565606,
"author": "Andrew Ensley",
"author_id": 20801,
"author_profile": "https://Stackoverflow.com/users/20801",
"pm_score": 7,
"selected": false,
"text": "swfobject.js"
},
{
"answer_id": 5159190,
"author": "Jon Clark",
"author_id": 639959,
"author_profile": "https://Stackoverflow.com/users/639959",
"pm_score": 5,
"selected": false,
"text": "<script src=\"Scripts/flash_detect.js\"></script>\n<script type=\"text/javascript\"> \n if (!FlashDetect.installed) {\n alert(\"Flash is required to enjoy this site.\"); \n } else {\n alert(\"Flash is installed on your Web browser.\");\n }\n</script> \n"
},
{
"answer_id": 9865667,
"author": "stewe",
"author_id": 511300,
"author_profile": "https://Stackoverflow.com/users/511300",
"pm_score": 5,
"selected": false,
"text": "// ==ClosureCompiler==\n// @compilation_level ADVANCED_OPTIMIZATIONS\n// @output_file_name default.js\n// @formatting pretty_print\n// @use_closure_library true\n// ==/ClosureCompiler==\n\n// ADD YOUR CODE HERE\ngoog.require('goog.userAgent.flash');\nif (goog.userAgent.flash.HAS_FLASH) {\n alert('flash version: '+goog.userAgent.flash.VERSION);\n}else{\n alert('no flash found');\n}\n"
},
{
"answer_id": 12902290,
"author": "Tom Roggero",
"author_id": 445887,
"author_profile": "https://Stackoverflow.com/users/445887",
"pm_score": 5,
"selected": false,
"text": "var hasFlash = function() {\n return (typeof navigator.plugins == \"undefined\" || navigator.plugins.length == 0) ? !!(new ActiveXObject(\"ShockwaveFlash.ShockwaveFlash\")) : navigator.plugins[\"Shockwave Flash\"];\n};\n"
},
{
"answer_id": 15174009,
"author": "trante",
"author_id": 429938,
"author_profile": "https://Stackoverflow.com/users/429938",
"pm_score": 3,
"selected": false,
"text": "isFlashExists"
},
{
"answer_id": 15346726,
"author": "bitinn",
"author_id": 1677057,
"author_profile": "https://Stackoverflow.com/users/1677057",
"pm_score": 1,
"selected": false,
"text": "function testFlash() {\n\n var support = false;\n\n //IE only\n if(\"ActiveXObject\" in window) {\n\n try{\n support = !!(new ActiveXObject(\"ShockwaveFlash.ShockwaveFlash\"));\n }catch(e){\n support = false;\n }\n\n //W3C, better support in legacy browser\n } else {\n\n support = !!navigator.mimeTypes['application/x-shockwave-flash'];\n\n }\n\n return support;\n\n}\n"
},
{
"answer_id": 16163487,
"author": "mike",
"author_id": 2310222,
"author_profile": "https://Stackoverflow.com/users/2310222",
"pm_score": 0,
"selected": false,
"text": ".swf"
},
{
"answer_id": 19156450,
"author": "Martin Bommeli",
"author_id": 1582179,
"author_profile": "https://Stackoverflow.com/users/1582179",
"pm_score": 2,
"selected": false,
"text": "var hasFlash = function() {\n var flash = false;\n try{\n if(new ActiveXObject('ShockwaveFlash.ShockwaveFlash')){\n flash=true;\n }\n }catch(e){\n if(navigator.mimeTypes ['application/x-shockwave-flash'] !== undefined){\n flash=true;\n }\n }\n return flash;\n};\n"
},
{
"answer_id": 22738965,
"author": "bizi",
"author_id": 793367,
"author_profile": "https://Stackoverflow.com/users/793367",
"pm_score": 2,
"selected": false,
"text": "function detectflash(){\n if (navigator.plugins != null && navigator.plugins.length > 0){\n return navigator.plugins[\"Shockwave Flash\"] && true;\n }\n if(~navigator.userAgent.toLowerCase().indexOf(\"webtv\")){\n return true;\n }\n if(~navigator.appVersion.indexOf(\"MSIE\") && !~navigator.userAgent.indexOf(\"Opera\")){\n try{\n return new ActiveXObject(\"ShockwaveFlash.ShockwaveFlash\") && true;\n } catch(e){}\n }\n return false;\n}\n"
},
{
"answer_id": 55506279,
"author": "chickens",
"author_id": 1602301,
"author_profile": "https://Stackoverflow.com/users/1602301",
"pm_score": 0,
"selected": false,
"text": "function hasFlash(){\n var b = !1;\n function c(a) {if (a = a.match(/[\\d]+/g)) {a.length = 3;}}\n (function() {\n if (navigator.plugins && navigator.plugins.length) {\n var a = navigator.plugins[\"Shockwave Flash\"];\n if (a && (b = !0, a.description)) {c(a.description);return;}\n if (navigator.plugins[\"Shockwave Flash 2.0\"]) {b = !0;return;}\n }\n if (navigator.mimeTypes && navigator.mimeTypes.length && (a = navigator.mimeTypes[\"application/x-shockwave-flash\"], b = !(!a || !a.enabledPlugin))) {c(a.enabledPlugin.description);return;}\n if (\"undefined\" != typeof ActiveXObject) {\n try {\n var d = new ActiveXObject(\"ShockwaveFlash.ShockwaveFlash.7\");b = !0;c(d.GetVariable(\"$version\"));return;\n } catch (e) {}\n try {\n d = new ActiveXObject(\"ShockwaveFlash.ShockwaveFlash.6\");b = !0;\n return;\n } catch (e) {}\n try {\n d = new ActiveXObject(\"ShockwaveFlash.ShockwaveFlash\"), b = !0, c(d.GetVariable(\"$version\"));\n } catch (e) {}\n }\n })();\n return b;\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7280/"
] |
159,282
|
<pre><code>grant {
permission java.security.AllPermission;
};
</code></pre>
<p>This works.</p>
<pre><code>grant file:///- {
permission java.security.AllPermission;
};
</code></pre>
<p>This does not work. Could someone please explain to me why?</p>
|
[
{
"answer_id": 159785,
"author": "David G",
"author_id": 3150,
"author_profile": "https://Stackoverflow.com/users/3150",
"pm_score": 1,
"selected": false,
"text": "file:///tmp/-"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
159,292
|
<p>I am using Apache's Velocity templating engine, and I would like to create a custom Directive. That is, I want to be able to write "#doMyThing()" and have it invoke some java code I wrote in order to generate the text.</p>
<p>I know that I can register a custom directive by adding a line</p>
<pre><code>userdirective=my.package.here.MyDirectiveName
</code></pre>
<p>to my velocity.properties file. And I know that I can write such a class by extending the <a href="http://svn.apache.org/repos/asf/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Directive.java" rel="nofollow noreferrer">Directive class</a>. What I don't know is <em>how</em> to extend the Directive class -- some sort of documentation for the author of a new Directive. For instance I'd like to know if my getType() method return "BLOCK" or "LINE" and I'd like to know what should my setLocation() method should do?</p>
<p>Is there any documentation out there that is better than just "<a href="http://www.catb.org/jargon/html/U/UTSL.html" rel="nofollow noreferrer">Use the source, Luke</a>"?</p>
|
[
{
"answer_id": 1012914,
"author": "gbegley",
"author_id": 76924,
"author_profile": "https://Stackoverflow.com/users/76924",
"pm_score": 2,
"selected": false,
"text": "import org.apache.velocity.runtime.directive.Directive;\nimport org.apache.velocity.runtime.RuntimeServices;\nimport org.apache.velocity.runtime.parser.node.Node;\nimport org.apache.velocity.context.InternalContextAdapter;\nimport org.apache.velocity.exception.MethodInvocationException;\nimport org.apache.velocity.exception.ResourceNotFoundException;\nimport org.apache.velocity.exception.ParseErrorException;\nimport org.apache.velocity.exception.TemplateInitException;\n\nimport java.io.Writer;\nimport java.io.IOException;\nimport java.io.StringWriter;\n\npublic class BlockSetDirective extends Directive {\n private String blockKey;\n\n /**\n * Return name of this directive.\n */\n public String getName() {\n return \"blockset\";\n }\n\n /**\n * Return type of this directive.\n */\n public int getType() {\n return BLOCK;\n }\n\n /**\n * simple init - get the blockKey\n */\n public void init( RuntimeServices rs, InternalContextAdapter context,\n Node node )\n throws TemplateInitException {\n super.init( rs, context, node );\n /*\n * first token is the name of the block. I don't even check the format,\n * just assume it looks like this: $block_name. Should check if it has\n * a '$' or not like macros.\n */\n blockKey = node.jjtGetChild( 0 ).getFirstToken().image.substring( 1 );\n }\n\n /**\n * Renders node to internal string writer and stores in the context at the\n * specified context variable\n */\n public boolean render( InternalContextAdapter context, Writer writer,\n Node node )\n throws IOException, MethodInvocationException,\n ResourceNotFoundException, ParseErrorException {\n StringWriter sw = new StringWriter(256);\n boolean b = node.jjtGetChild( 1 ).render( context, sw );\n context.put( blockKey, sw.toString() );\n return b;\n }\n\n}\n"
},
{
"answer_id": 1106361,
"author": "serg",
"author_id": 20128,
"author_profile": "https://Stackoverflow.com/users/20128",
"pm_score": 2,
"selected": false,
"text": "import java.io.IOException;\nimport java.io.StringWriter;\nimport java.io.Writer;\n\nimport org.apache.velocity.context.InternalContextAdapter;\nimport org.apache.velocity.exception.MethodInvocationException;\nimport org.apache.velocity.exception.ParseErrorException;\nimport org.apache.velocity.exception.ResourceNotFoundException;\nimport org.apache.velocity.exception.TemplateInitException;\nimport org.apache.velocity.runtime.RuntimeServices;\nimport org.apache.velocity.runtime.directive.Directive;\nimport org.apache.velocity.runtime.parser.node.Node;\nimport org.apache.velocity.runtime.log.Log;\n\nimport com.googlecode.htmlcompressor.compressor.HtmlCompressor;\n\n/**\n * Velocity directive that compresses an HTML content within #compressHtml ... #end block.\n */\npublic class HtmlCompressorDirective extends Directive {\n\n private static final HtmlCompressor htmlCompressor = new HtmlCompressor();\n\n private Log log;\n\n public String getName() {\n return \"compressHtml\";\n }\n\n public int getType() {\n return BLOCK;\n }\n\n @Override\n public void init(RuntimeServices rs, InternalContextAdapter context, Node node) throws TemplateInitException {\n super.init(rs, context, node);\n log = rs.getLog();\n\n //set compressor properties\n htmlCompressor.setEnabled(rs.getBoolean(\"userdirective.compressHtml.enabled\", true));\n htmlCompressor.setRemoveComments(rs.getBoolean(\"userdirective.compressHtml.removeComments\", true));\n }\n\n public boolean render(InternalContextAdapter context, Writer writer, Node node) \n throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {\n\n //render content to a variable\n StringWriter content = new StringWriter();\n node.jjtGetChild(0).render(context, content);\n\n //compress\n try {\n writer.write(htmlCompressor.compress(content.toString()));\n } catch (Exception e) {\n writer.write(content.toString());\n String msg = \"Failed to compress content: \"+content.toString();\n log.error(msg, e);\n throw new RuntimeException(msg, e);\n\n }\n return true;\n\n }\n\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14570/"
] |
159,296
|
<p>I've got a (poorly written) base class that I want to wrap in a proxy object. The base class resembles the following:</p>
<pre><code>public class BaseClass : SomeOtherBase
{
public BaseClass() {}
public BaseClass(int someValue) {}
//...more code, not important here
}
</code></pre>
<p>and, my proxy resembles:</p>
<pre><code>public BaseClassProxy : BaseClass
{
public BaseClassProxy(bool fakeOut){}
}
</code></pre>
<p>Without the "fakeOut" constructor, the base constructor is expected to be called. However, with it, I expected it to not be called. Either way, I either need a way to not call any base class constructors, or some other way to effectively proxy this (evil) class.</p>
|
[
{
"answer_id": 159327,
"author": "albertein",
"author_id": 23020,
"author_profile": "https://Stackoverflow.com/users/23020",
"pm_score": 1,
"selected": false,
"text": "public BaseClassProxy (bool fakeOut) : base (10) {}\n"
},
{
"answer_id": 159342,
"author": "Jake Pearson",
"author_id": 632,
"author_profile": "https://Stackoverflow.com/users/632",
"pm_score": 3,
"selected": false,
"text": "public class BaseClass : SomeOtherBase \n{\n public BaseClass() {}\n\n protected virtual void Setup()\n {\n }\n}\n\npublic BaseClassProxy : BaseClass\n{\n bool _fakeOut;\n protected BaseClassProxy(bool fakeOut)\n {\n _fakeOut = fakeOut;\n Setup();\n }\n\n public override void Setup()\n {\n if(_fakeOut)\n {\n base.Setup();\n }\n //Your other constructor code\n }\n} \n"
},
{
"answer_id": 159417,
"author": "Lucas",
"author_id": 24231,
"author_profile": "https://Stackoverflow.com/users/24231",
"pm_score": 3,
"selected": false,
"text": "public BaseClassProxy : BaseClass\n{\n public BaseClassProxy() : base() { }\n}\n"
},
{
"answer_id": 159434,
"author": "casademora",
"author_id": 5619,
"author_profile": "https://Stackoverflow.com/users/5619",
"pm_score": 0,
"selected": false,
"text": "public class BaseClassProxy : BaseClass \n{\n public BaseClass BaseClass { get; private set; }\n\n public virtual int MethodINeedToOverride(){}\n public virtual string PropertyINeedToOverride() { get; protected set; }\n}\n"
},
{
"answer_id": 160027,
"author": "Neil",
"author_id": 24315,
"author_profile": "https://Stackoverflow.com/users/24315",
"pm_score": 6,
"selected": false,
"text": "FormatterServices.GetUninitializedObject(typeof(MyClass));\n"
},
{
"answer_id": 49564273,
"author": "John Foll",
"author_id": 5100141,
"author_profile": "https://Stackoverflow.com/users/5100141",
"pm_score": 0,
"selected": false,
"text": "public MyClass();\n{\n throw new Exception(\"Error: Must call constructor with parameters.\");\n}\n"
},
{
"answer_id": 57034116,
"author": "marsh-wiggle",
"author_id": 1574221,
"author_profile": "https://Stackoverflow.com/users/1574221",
"pm_score": 0,
"selected": false,
"text": "public class MyClass_Base\n{\n public MyClass_Base() \n {\n /// Don't call the InitClass() when the object is inherited\n /// !!! CAUTION: The inherited constructor must call InitClass() itself when init is needed !!!\n if (this.GetType().IsSubclassOf(typeof(MyClass_Base)) == false)\n {\n this.InitClass();\n }\n }\n\n protected void InitClass()\n {\n // The init stuff\n }\n}\n\n\npublic class MyClass : MyClass_Base\n{\n public MyClass(bool callBaseClassInit)\n {\n if(callBaseClassInit == true)\n base.InitClass();\n }\n}\n"
},
{
"answer_id": 58180155,
"author": "Noob Guy",
"author_id": 11874175,
"author_profile": "https://Stackoverflow.com/users/11874175",
"pm_score": 0,
"selected": false,
"text": "using System;\n\npublic class Program\n{\n public static void Main()\n {\n Console.WriteLine(new Child().Test);\n }\n\n public class Child : Parent {\n public Child() : base(false) {\n //No Parent Constructor called\n }\n }\n public class Parent {\n public int Test {get;set;}\n public Parent()\n {\n Test = 5;\n }\n public Parent(bool NoBase){\n //Don't do anything\n }\n }\n}\n"
},
{
"answer_id": 65753033,
"author": "Trajwaj",
"author_id": 15020089,
"author_profile": "https://Stackoverflow.com/users/15020089",
"pm_score": 0,
"selected": false,
"text": "class parent\n{\n public parent()\n {\n //code for all children\n\n if (this.GetType() == typeof(child1))\n {\n //code only for objects of class \"child1\"\n }\n else\n {\n //code for objects of other child classes\n }\n }\n}\n\nclass child1 : parent\n{\n public child1()\n {}\n}\n\n// class child2: parent ... child3 : parent ... e.t.c\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5619/"
] |
159,298
|
<p>It looks like some work has been done to make <a href="http://sourceware.org/pthreads-win32/" rel="noreferrer">pthread-win32</a> work with x64, but there are no build instructions. I have tried simly building with the Visual Studio x64 Cross Tools Command Prompt, but when I try to link to the lib from an x64 application, it can't see any of the function exports. It seems like it is still compiling the lib as x86 or something.</p>
<p>I've even tried adding /MACHINE to the makefile in the appropriate places, but it doesn't help. Has anyone gotten this to work?</p>
|
[
{
"answer_id": 16399440,
"author": "rogerdpack",
"author_id": 32453,
"author_profile": "https://Stackoverflow.com/users/32453",
"pm_score": 2,
"selected": false,
"text": "$ make clean GC-static \n"
},
{
"answer_id": 48095275,
"author": "Vladimir Fekete",
"author_id": 2282321,
"author_profile": "https://Stackoverflow.com/users/2282321",
"pm_score": 1,
"selected": false,
"text": "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat amd64"
},
{
"answer_id": 62505868,
"author": "Victor S",
"author_id": 407615,
"author_profile": "https://Stackoverflow.com/users/407615",
"pm_score": 0,
"selected": false,
"text": "nmake"
},
{
"answer_id": 63266134,
"author": "AakashPatil",
"author_id": 9971526,
"author_profile": "https://Stackoverflow.com/users/9971526",
"pm_score": 3,
"selected": false,
"text": "bootstrap - vcpkg.bat\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21784/"
] |
159,313
|
<p>What is the scope of Runtime Callable Wrapper (RCW), when referencing unmanaged COM objects? According to the docs:</p>
<blockquote>
<p>The runtime creates exactly one RCW
for each COM object, regardless of the
number of references that exist on
that object.</p>
</blockquote>
<p>If I had to "guess" - this explanation should mean "one per process", but is it really? Any additional documentation will be very welcome.</p>
<p>My application runs in its own application domain (it is Outlook addin), and I would like to know what happens if I use Marshal.ReleaseComObject(x) in a loop until it's count reaches 0 (as recommended). Will it release references from other addins (running in other application domain in the same Outlook process)?</p>
<p>EDIT: Perfect - now the confusion is even bigger. Based on the 2 answers (from Lette and Ilya) we have 2 different answers. The official <a href="http://msdn.microsoft.com/en-us/library/8bwh56xe(VS.80).aspx" rel="nofollow noreferrer">MSDN doc</a> says per process (for ver. 2.0+), but it is missing this sentence for <a href="http://msdn.microsoft.com/en-us/library/8bwh56xe(VS.71).aspx" rel="nofollow noreferrer">ver. 1.1 of the doc</a>.</p>
<p>In the same time, in Mason Bendixen's article, it says it's per appdomain.</p>
<p>As his article is old (April 2007), I have send him an email asking for clarification, but if someone else has to add something, please do.</p>
<p>Thanks</p>
|
[
{
"answer_id": 163151,
"author": "Christoffer Lette",
"author_id": 11808,
"author_profile": "https://Stackoverflow.com/users/11808",
"pm_score": 1,
"selected": false,
"text": "ReleaseComObject"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8220/"
] |
159,317
|
<p>When should one do the following?</p>
<pre><code>class Foo : Control
{
protected override void OnClick(EventArgs e)
{
// new code here
}
}
</code></pre>
<p>As opposed to this?</p>
<pre><code>class Foo : Control
{
public Foo()
{
this.Click += new EventHandler(Clicked);
}
private void Clicked(object sender, EventArgs e)
{
// code
}
}
</code></pre>
|
[
{
"answer_id": 160041,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 2,
"selected": false,
"text": "public class MyDataTable : DataTable\n{\n public override void EndInit()\n {\n base.EndInit();\n this.TableNewRow += delegate(object sender, DataTableNewRowEventArgs e) { };\n }\n\n protected override void OnTableNewRow(DataTableNewRowEventArgs e)\n {\n base.OnTableNewRow(e);\n // your code here\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8505/"
] |
159,339
|
<p>I'm not sure if the term's actually "Array Addition". </p>
<p>I'm trying to understand what does the following line do:</p>
<pre><code>int var[2 + 1] = {2, 1};
</code></pre>
<p>How is that different from <code>int var[3]</code>?</p>
<p>I've been using Java for several years, so I'd appreciate if explained using Java-friendly words.</p>
<p>Edit: Thousands of thanks to everyone who helped me out, Occam's Razor applies here. </p>
|
[
{
"answer_id": 159352,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "int var[3]"
},
{
"answer_id": 159355,
"author": "Dima",
"author_id": 13313,
"author_profile": "https://Stackoverflow.com/users/13313",
"pm_score": 0,
"selected": false,
"text": "int var[3]"
},
{
"answer_id": 159363,
"author": "Constantin",
"author_id": 20310,
"author_profile": "https://Stackoverflow.com/users/20310",
"pm_score": 0,
"selected": false,
"text": "var[2 + 1]"
},
{
"answer_id": 159365,
"author": "Zan Lynx",
"author_id": 13422,
"author_profile": "https://Stackoverflow.com/users/13422",
"pm_score": 0,
"selected": false,
"text": "int var[3]"
},
{
"answer_id": 159368,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 0,
"selected": false,
"text": "2 + 1"
},
{
"answer_id": 159385,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 4,
"selected": true,
"text": "2 + 1"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24280/"
] |
159,351
|
<p>ActiveReports seems like a powerful flexible tool, but if you make a mistake anywhere, you get an exception "data member not found. please check your datasource and datamember properties". </p>
<p>There is no indication as to which datasource/datamember is at fault or what subreport the problem lies in, but Active Reports must know this!</p>
<p>The stack trace is no use, as the error is thrown after the report.run() method is invoked from deep within code generated by Active Reports itself.</p>
<p>Does anybody have a solution other than commenting out one subreport after another and checking all fields in turn?</p>
|
[
{
"answer_id": 6863977,
"author": "John Meyer",
"author_id": 868113,
"author_profile": "https://Stackoverflow.com/users/868113",
"pm_score": 2,
"selected": false,
"text": "Dim rpt as New ActiveReport"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
159,359
|
<p>I know we cannot do this at class level but at method level we can always do this. </p>
<pre><code>var myList=new List<string> // or something else like this
</code></pre>
<p>This question came to my mind since wherever we declare variable like this. We always provide the type information at the RHS of the expression. So compiler doesn't need to do type guessing. (correct me if i am wrong).</p>
<p>so question remains WHY NOT at class level while its allowed at method level</p>
|
[
{
"answer_id": 159559,
"author": "Joseph Daigle",
"author_id": 507,
"author_profile": "https://Stackoverflow.com/users/507",
"pm_score": 1,
"selected": false,
"text": "var"
},
{
"answer_id": 159574,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 0,
"selected": false,
"text": "[MyAttribute()] protected internal readonly var list = new List<T>();\n"
},
{
"answer_id": 15872114,
"author": "vinay Dubey",
"author_id": 2256281,
"author_profile": "https://Stackoverflow.com/users/2256281",
"pm_score": 0,
"selected": false,
"text": "class Class1\n{\n public void genmethod<T>(T i,int Count)\n {\n\n\n List<string> list = i as List<string>;\n\n for (int j = 0; j < Count; j++)\n {\n Console.WriteLine(list[j]);\n }\n }\n static void Main(string[] args)\n {\n Class1 c = new Class1();\n c.genmethod<string>(\"str\",0);\n List<string> l = new List<string>();\n l.Add(\"a\");\n l.Add(\"b\");\n l.Add(\"c\");\n l.Add(\"d\");\n c.genmethod<List<string>>(l,l.Count);\n\n Console.WriteLine(\"abc\");\n Console.ReadLine();\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22858/"
] |
159,362
|
<p>If I avoid referencing assemblies that don't exist in the silverlight 2.0 runtime, will the.Net 2.0 library dlls I create with VS2008 work with silverlight <strong>without recompilation</strong> or other alteration?</p>
|
[
{
"answer_id": 170936,
"author": "Jimmy",
"author_id": 25071,
"author_profile": "https://Stackoverflow.com/users/25071",
"pm_score": 0,
"selected": false,
"text": "#if SILVERLIGHT\n/* some code */\n#else // WPF\n/* some other code */\n#endif\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11356/"
] |
159,373
|
<p>Using .Net 3.0 and VS2005. </p>
<p>The objects in question are consumed from a WCF service then serialized back into XML for a legacy API. So rather than serializing the TestObject, it was serializing .TestObject which was missing the [XmlRoot] attribute; however, all the [Xml*] attributes for the child elements were in the generated proxy code so they worked just fine. So all the child elements worked just fine, but the enclosing element did not because the [XmlRoot] attribute wasn't included in the generated proxy code. The original object that included the [XmlRoot] attribute serializes fine manually.</p>
<p><strong>Can I have the proxy code include the [XmlRoot] attribute so the generated proxy class serializes correctly as well?</strong> If I can't do that I suspect I'll have to use [XmlType] but that causes minor havoc requiring me to change other components so I would prefer the former. I also want to avoid having to manually edit the autogenerated proxy class.</p>
<p>Here is some sample code (I have included the client and the service in the same app because this is quick and for test purposes. Comment out the service referencing code and add the service reference while running the app, then uncomment the service code and run.)</p>
<pre><code>namespace SerializationTest {
class Program {
static void Main( string[] args ) {
Type serviceType = typeof( TestService );
using (ServiceHost host = new ServiceHost(
serviceType,
new Uri[] {
new Uri( "http://localhost:8080/" )
}
))
{
ServiceMetadataBehavior behaviour = new ServiceMetadataBehavior();
behaviour.HttpGetEnabled = true;
host.Description.Behaviors.Add( behaviour );
host.AddServiceEndpoint( serviceType, new BasicHttpBinding(), "TestService" );
host.AddServiceEndpoint( typeof( IMetadataExchange ), new BasicHttpBinding(), "MEX" );
host.Open();
TestServiceClient client = new TestServiceClient();
localhost.TestObject to = client.GetObject();
String XmlizedString = null;
using (MemoryStream memoryStream = new MemoryStream()) {
XmlSerializer xs = new XmlSerializer( typeof( localhost.TestObject ) );
using (XmlWriter xmlWriter = XmlWriter.Create(memoryStream)) {
xs.Serialize( xmlWriter, to );
memoryStream = (MemoryStream)xmlWriter.BaseStream;
XmlizedString = Encoding.UTF8.GetString( memoryStream.ToArray() );
Console.WriteLine( XmlizedString );
}
}
}
Console.ReadKey();
}
}
[Serializable]
[XmlRoot( "SomethingElse" )]
public class TestObject {
private bool _worked;
public TestObject() { Worked = true; }
[XmlAttribute( AttributeName = "AttributeWorked" )]
public bool Worked {
get { return _worked; }
set { _worked = value; }
}
}
[ServiceContract]
public class TestService {
[OperationContract]
[XmlSerializerFormat]
public TestObject GetObject() {
return new TestObject();
}
}
}
</code></pre>
<p>Here is the Xml this generates.</p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<TestObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" AttributeWorked="true" />
</code></pre>
|
[
{
"answer_id": 177169,
"author": "hurst",
"author_id": 10991,
"author_profile": "https://Stackoverflow.com/users/10991",
"pm_score": -1,
"selected": true,
"text": "XmlAttributeOverrides"
},
{
"answer_id": 1031423,
"author": "graffic",
"author_id": 15987,
"author_profile": "https://Stackoverflow.com/users/15987",
"pm_score": 1,
"selected": false,
"text": "XmlRoot"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159373",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24279/"
] |
159,391
|
<p>Did anyone of you ever find a way of getting the Microsoft Report Viewer Control (Web) to work from within an Ajax UpdatePanel?</p>
|
[
{
"answer_id": 2673667,
"author": "user321101",
"author_id": 321101,
"author_profile": "https://Stackoverflow.com/users/321101",
"pm_score": 2,
"selected": false,
"text": " <assemblies> <add assembly=\"System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089\" /> <add assembly=\"System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089\" /> <add assembly=\"System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35\" /> <add assembly=\"System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089\" /> <add assembly=\"Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A\" /> <add assembly=\"Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A\" /> </assemblies>\n <assemblies>\n\n <add assembly=\"Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A\" />\n\n <add assembly=\"Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A\" />\n\n </assemblies>\n"
},
{
"answer_id": 42011014,
"author": "Daniel Soares",
"author_id": 4142735,
"author_profile": "https://Stackoverflow.com/users/4142735",
"pm_score": 0,
"selected": false,
"text": "<asp:Button ID=\"Button1\" runat=\"server\" OnClick=\"ViewReport_Clicked\" Text=\"View Report\" SkinID=\"ButtonA\" />\n<asp:UpdatePanel ID=\"TFD_UP\" runat=\"server\">\n <ContentTemplate>\n <rsweb:ReportViewer ID=\"ReportViewer1\" runat=\"server\" SizeToReportContent=\"True\"\n Height=\"202px\" Width=\"935px\" Font-Names=\"Verdana\" Font-Size=\"8pt\" InteractiveDeviceInfos=\"(Collection)\"\n WaitMessageFont-Names=\"Verdana\" WaitMessageFont-Size=\"14pt\" Visible=\"false\">\n <LocalReport ReportPath=\"Reports\\Report4.rdlc\">\n <DataSources>\n <rsweb:ReportDataSource DataSourceId=\"SqlDataSourceArchiSpecs\" Name=\"Proc_TechFilesDownloadsDataSetParent\" />\n </DataSources>\n </LocalReport>\n </rsweb:ReportViewer>\n <asp:SqlDataSource ID=\"SqlDataSourceArchiSpecs\" runat=\"server\" ConnectionString=\"<%$ ConnectionStrings:ArchiSpecsDBConnectionString %>\"\n SelectCommand=\"PROC_TECHNICALFILES_DOWNLOAD_DETAILS\" SelectCommandType=\"StoredProcedure\">\n <SelectParameters>\n <asp:Parameter Name=\"supId\" Type=\"Int32\" />\n <asp:Parameter Name=\"startDate\" Type=\"DateTime\" />\n <asp:Parameter Name=\"endDate\" Type=\"DateTime\" />\n </SelectParameters>\n </asp:SqlDataSource>\n </ContentTemplate>\n <Triggers>\n <asp:AsyncPostBackTrigger ControlID=\"Button1\" EventName=\"Click\" />\n </Triggers>\n</asp:UpdatePanel>\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23369/"
] |
159,393
|
<p>I want to create a script that parses or makes sense of apache's error log to see what the most recent error was. I was wondering if anyone out there has something that does this or has any ideas where to start?</p>
|
[
{
"answer_id": 159452,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 5,
"selected": true,
"text": "$contents = @file('/path/to/error.log', FILE_SKIP_EMPTY_LINES);\nif (is_array($contents)) {\n echo end($contents);\n}\nunset($contents);\n"
},
{
"answer_id": 163861,
"author": "SeanDowney",
"author_id": 5261,
"author_profile": "https://Stackoverflow.com/users/5261",
"pm_score": 4,
"selected": false,
"text": "<?php\nexec('tail /usr/local/apache/logs/error_log', $output);\n?>\n<Table border=\"1\">\n <tr>\n <th>Date</th>\n <th>Type</th>\n <th>Client</th>\n <th>Message</th>\n </tr>\n<?\n foreach($output as $line) {\n // sample line: [Wed Oct 01 15:07:23 2008] [error] [client 76.246.51.127] PHP 99. Debugger->handleError() /home/gsmcms/public_html/central/cake/libs/debugger.php:0\n preg_match('~^\\[(.*?)\\]~', $line, $date);\n if(empty($date[1])) {\n continue;\n }\n preg_match('~\\] \\[([a-z]*?)\\] \\[~', $line, $type);\n preg_match('~\\] \\[client ([0-9\\.]*)\\]~', $line, $client);\n preg_match('~\\] (.*)$~', $line, $message);\n ?>\n <tr>\n <td><?=$date[1]?></td>\n <td><?=$type[1]?></td>\n <td><?=$client[1]?></td>\n <td><?=$message[1]?></td>\n </tr>\n <?\n }\n?>\n</table>\n"
},
{
"answer_id": 4496086,
"author": "Ben Haley",
"author_id": 431079,
"author_profile": "https://Stackoverflow.com/users/431079",
"pm_score": 2,
"selected": false,
"text": "BigFile.php\n<?php\n$run_test = true;\n$test_file = 'BigFile.php';\n\nclass BigFile\n{\nprivate $file_handle;\n\n/**\n * \n * Load the file from a filepath \n * @param string $path_to_file\n * @throws Exception if path cannot be read from\n */\npublic function __construct( $path_to_log )\n{\n if( is_readable($path_to_log) )\n {\n $this->file_handle = fopen( $path_to_log, 'r');\n }\n else\n {\n throw new Exception(\"The file path to the file is not valid\");\n } \n}\n\n/**\n * \n * 'Finish your breakfast' - Jay Z's homme Strict\n */\npublic function __destruct()\n{\n fclose($this->file_handle); \n}\n\n/**\n * \n * Returns a number of characters from the end of a file w/o loading the entire file into memory\n * @param integer $number_of_characters_to_get\n * @return string $characters\n */\npublic function getFromEnd( $number_of_characters_to_get )\n{\n $offset = -1*$number_of_characters_to_get;\n $text = \"\";\n\n fseek( $this->file_handle, $offset , SEEK_END);\n\n while(!feof($this->file_handle))\n {\n $text .= fgets($this->file_handle);\n }\n\n return $text;\n}\n}\n\nif( $run_test )\n{\n$number_of_characters_to_get = 100000; \n$bf = new BigFile($test_file);\n$text = $bf->getFromEnd( $number_of_characters_to_get );\necho \"$test_file has the following $number_of_characters_to_get characters at the end: \n <br/> <pre>$text</pre>\";\n}\n\n?> \n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5261/"
] |
159,423
|
<p>I'm currently writing a simple .sh script to parse an Exim log file for strings matching " o' ". Currently, when viewing output.txt, all that is there is a 0 printed on every line(606 lines). I'm guessing my logic is wrong, as awk does not throw any errors.</p>
<p>Here is my code(updated for concatenation and counter issues). Edit: I've adopted some new code from dmckee's answer that I'm now working with over the old code in favor of simplicity.</p>
<pre><code>awk '/o'\''/ {
line = "> ";
for(i = 20; i <= 33; i++) {
line = line " " $i;
}
print line;
}' /var/log/exim/main.log > output.txt
</code></pre>
<p>Any ideas? </p>
<p>EDIT: For clarity's sake, I'm grepping for "o'" in email addresses, because ' is an illegal character in email addresses(and in our databases, appears only with o'-prefixed names).</p>
<p>EDIT 2: As per commentary request, here is a sanitized sample of some desired output:</p>
<pre><code>[xxx.xxx.xxx.xxx] kathleen.o'toole@domain.com <kathleen.o'toole@domain.com> routing defer (-51): retry time not reached
[xxx.xxx.xxx.xxx] julie.o'brien@domain.com <julie.o'brien@domain.com> routing defer (-51): retry time not reached
[xxx.xxx.xxx.xxx] james.o'dell@domain.com <james.o'dell@domain.com> routing defer (-51): retry time not reached
[xxx.xxx.xxx.xxx] daniel_o'leary@domain.com <aniel_o'leary@domain.com> routing defer (-51): retry time not reached
</code></pre>
<p>The reason I'm starting at 20 in my loop is because everything before the 20th field is just standard log information that isn't needed for my purposes here. All I need is everything from the IP and beyond for this solution(the messages for each 550 error are different for each mail server in use out there. I'm compiling a list of common ones)</p>
|
[
{
"answer_id": 159450,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 2,
"selected": false,
"text": "+"
},
{
"answer_id": 159501,
"author": "dmckee --- ex-moderator kitten",
"author_id": 2509,
"author_profile": "https://Stackoverflow.com/users/2509",
"pm_score": 3,
"selected": true,
"text": "awk '/o'\\''/ {\n line = \"> \";\n for(i = 20; i <= 33; i++) {\n line = line \" \" $i;\n }\n print line;\n }' /var/log/exim/main.log > output.txt\n"
},
{
"answer_id": 159560,
"author": "jj33",
"author_id": 430,
"author_profile": "https://Stackoverflow.com/users/430",
"pm_score": 1,
"selected": false,
"text": "Local-part = Dot-string / Quoted-string\n\nDot-string = Atom *(\".\" Atom)\n\nAtom = 1*atext\n"
},
{
"answer_id": 159722,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "import fileinput\nfor line in fileinput.input():\n if \"'\" in line:\n fields = line.split(' ')\n print \"> \", ' '.join( fields[20:34] )\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2153/"
] |
159,442
|
<p>This seems like a pretty softball question, but I always have a hard time looking up this function because there seem there are so many variations regarding the referencing of char and tchar.</p>
|
[
{
"answer_id": 159536,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 2,
"selected": false,
"text": "if (sizeof(TCHAR) != sizeof(wchar_t))\n{ .... }\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159442",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16260/"
] |
159,456
|
<p>I have a database in the following format:</p>
<pre><code> ID TYPE SUBTYPE COUNT MONTH
1 A Z 1 7/1/2008
1 A Z 3 7/1/2008
2 B C 2 7/2/2008
1 A Z 3 7/2/2008
</code></pre>
<p>Can I use SQL to convert it into this:</p>
<pre><code>ID A_Z B_C MONTH
1 4 0 7/1/2008
2 0 2 7/2/2008
1 0 3 7/2/2008
</code></pre>
<p>So, the <code>TYPE</code>, <code>SUBTYPE</code> are concatenated into new columns and <code>COUNT</code> is summed where the <code>ID</code> and <code>MONTH</code> match.</p>
<p>Any tips would be appreciated. Is this possible in SQL or should I program it manually?</p>
<p>The database is SQL Server 2005. </p>
<p>Assume there are 100s of <code>TYPES</code> and <code>SUBTYPES</code> so and 'A' and 'Z' shouldn't be hard coded but generated dynamically.</p>
|
[
{
"answer_id": 159488,
"author": "Bob Probst",
"author_id": 12424,
"author_profile": "https://Stackoverflow.com/users/12424",
"pm_score": 3,
"selected": false,
"text": "select id,\nsum(case when type = 'A' and subtype = 'Z' then [count] else 0 end) as A_Z,\nsum(case when type = 'B' and subtype = 'C' then [count] else 0 end) as B_C,\nmonth\nfrom tbl_why_would_u_do_this\ngroup by id, month\n"
},
{
"answer_id": 159803,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 6,
"selected": true,
"text": "/*\nCREATE TABLE [dbo].[stackoverflow_159456](\n [ID] [int] NOT NULL,\n [TYPE] [char](1) NOT NULL,\n [SUBTYPE] [char](1) NOT NULL,\n [COUNT] [int] NOT NULL,\n [MONTH] [datetime] NOT NULL\n) ON [PRIMARY]\n*/\n\nDECLARE @sql AS varchar(max)\nDECLARE @pivot_list AS varchar(max) -- Leave NULL for COALESCE technique\nDECLARE @select_list AS varchar(max) -- Leave NULL for COALESCE technique\n\nSELECT @pivot_list = COALESCE(@pivot_list + ', ', '') + '[' + PIVOT_CODE + ']'\n ,@select_list = COALESCE(@select_list + ', ', '') + 'ISNULL([' + PIVOT_CODE + '], 0) AS [' + PIVOT_CODE + ']'\nFROM (\n SELECT DISTINCT [TYPE] + '_' + SUBTYPE AS PIVOT_CODE\n FROM stackoverflow_159456\n) AS PIVOT_CODES\n\nSET @sql = '\n;WITH p AS (\n SELECT ID, [MONTH], [TYPE] + ''_'' + SUBTYPE AS PIVOT_CODE, SUM([COUNT]) AS [COUNT]\n FROM stackoverflow_159456\n GROUP BY ID, [MONTH], [TYPE] + ''_'' + SUBTYPE\n)\nSELECT ID, [MONTH], ' + @select_list + '\nFROM p\nPIVOT (\n SUM([COUNT])\n FOR PIVOT_CODE IN (\n ' + @pivot_list + '\n )\n) AS pvt\n'\n\nEXEC (@sql)\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23133/"
] |
159,469
|
<p>Hopefully, I can explain this issue properly. I have 3 classes that deals with my entities.</p>
<pre><code>@MappedSuperclass
public abstract class Swab implements ISwab {
...
private Collection<SwabAccounts> accounts;
...
}
@Entity
@Table(name="switches")
@DiscriminatorColumn(name="type")
@DiscriminatorValue(value="DMS500")
public class DmsSwab extends Swab implements ISwab, Serializable {
...
private ObjectPool pool;
...
@Transient
public ObjectPool getPool(){
return pool;
}
...
}
@Entity(name="swab_accounts")
public class SwabAccounts implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int swab_account_id;
private int swab_id;
...
}
</code></pre>
<p>And in a EJB a query is being doing this way</p>
<pre><code> DmsSwab dms = em.find(DmsSwab.class, 2);
List<Swab> s = new ArrayList<Swab>(1);
s.add(dms);
</code></pre>
<p>My persistence.xml looks like this:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="dflow-pu" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>com.dcom.sap.dms.DmsSwab</class>
<class>com.dcom.sap.jpa.SwabAccounts</class>
<properties>
<property name="toplink.jdbc.user" value="dflow"/>
<property name="toplink.jdbc.password" value="dflow"/>
<property name="toplink.jdbc.url" value="jdbc:mysql://itcd-400447:3306/dflow"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
</code></pre>
<p>I get this error:</p>
<pre><code>java.lang.IllegalArgumentException: Unknown entity bean class: class com.dcom.sap.dms.DmsSwab, please verify that this class has been marked with the @Entity annotation.
com.dcom.sap.SwabException: java.lang.IllegalArgumentException: Unknown entity bean class: class com.dcom.sap.dms.DmsSwab, please verify that this class has been marked with the @Entity annotation.
Caused by: java.lang.IllegalArgumentException: Unknown entity bean class: class com.dcom.sap.dms.DmsSwab, please verify that this class has been marked with the @Entity annotation.
at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.findInternal(EntityManagerImpl.java:306)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.find(EntityManagerImpl.java:148)
</code></pre>
<p>I am running netbeans 6.1 with the version of glassfish that comes with it. MySql 5.0.</p>
|
[
{
"answer_id": 43619011,
"author": "Mario Barreto MX",
"author_id": 7921419,
"author_profile": "https://Stackoverflow.com/users/7921419",
"pm_score": 0,
"selected": false,
"text": "public void contextDestroyed(ServletContextEvent servletContextEvent) {\n try {\n logger.info(\"contextDestroyed...\");\n LifeCycleManager lifeCycleManager = ServiceLocator.getLifeCycleManager();\n lifeCycleManager.closeEntityManagerFactory();\n\n } catch (Exception e) {\n logger.error(e.getMessage(), e);\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22763/"
] |
159,470
|
<p>I'm using an expander inside a <a href="http://kentb.blogspot.com/2007/04/resizer-wpf-control.html" rel="nofollow noreferrer">Resizer</a> (a ContentControl with a resize gripper), and it expands/collapses properly when the control initially comes up. Once I resize it, the Expander won't properly collapse, as documented below. I ran Snoop on my application, and I don't see any heights set on Expander or its constituents. </p>
<p>How would I go about convincing Expander to collapse properly again? Or modifying Resizer to not make Expander sad would work as well.</p>
<p>Expander documentation says:</p>
<blockquote>
<p>"For an Expander to work correctly, do not specify a Height on the Expander control when the ExpandDirection property is set to Down or Up. Similarly, do not specify a Width on the Expander control when the ExpandDirection property is set to Left or Right. When you set a size on the Expander control in the direction that the expanded content is displayed, the area that is defined by the size parameter is displayed with a border around it. This area displays even when the window is collapsed. To set the size of the expanded window, set size dimensions on the content of the Expander control or the ScrollViewer that encloses the content."</p>
</blockquote>
|
[
{
"answer_id": 43619011,
"author": "Mario Barreto MX",
"author_id": 7921419,
"author_profile": "https://Stackoverflow.com/users/7921419",
"pm_score": 0,
"selected": false,
"text": "public void contextDestroyed(ServletContextEvent servletContextEvent) {\n try {\n logger.info(\"contextDestroyed...\");\n LifeCycleManager lifeCycleManager = ServiceLocator.getLifeCycleManager();\n lifeCycleManager.closeEntityManagerFactory();\n\n } catch (Exception e) {\n logger.error(e.getMessage(), e);\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9970/"
] |
159,476
|
<p>Let's say I've got a website that works better if a client has installed and logged into a desktop application. I'd like to be able to do 2 things:</p>
<ul>
<li>Alter the website if they haven't installed the app (to make it easy for them to find a link to the installer)</li>
<li>If they've installed the app on a couple of machines, determine which machine they are browsing from</li>
</ul>
<p>I'd like something that works on Windows and OSX, on any of the major browsers. Linux is a bonus. </p>
<p>A few thoughts:</p>
<ul>
<li>Websites can detect if you've got Flash installed. How does that work and could it be used for both of my goals? </li>
<li>Could I just let the client serve HTTP on localhost and do some javascript requests to fetch a local ID? I know google desktop search did something like this at one point. Is this a standard practice? </li>
</ul>
<p>Thanks!</p>
|
[
{
"answer_id": 159518,
"author": "vaske",
"author_id": 16039,
"author_profile": "https://Stackoverflow.com/users/16039",
"pm_score": 0,
"selected": false,
"text": ".swf"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23524/"
] |
159,487
|
<p>Well, this is my first post here and really enjoying the site.</p>
<p>I have a very basic (ugly as sin) site I have started and for some reason, I can not get the CSS Sticky footer to work for FireFox. IE works but FF shows it halfway up the page.</p>
<p>The URL is <a href="http://dev.aipoker.co.uk" rel="nofollow noreferrer">http://dev.aipoker.co.uk</a></p>
<p>I know I should be developing in FF and bug fixing in IE so I am guessing I might have actually made a mistake and somehow it works in IE but nowhere else.</p>
<p>Can anyone help put me out of my misery please?</p>
<p>Thanks, guys and gals.</p>
|
[
{
"answer_id": 159558,
"author": "zigdon",
"author_id": 4913,
"author_profile": "https://Stackoverflow.com/users/4913",
"pm_score": 2,
"selected": false,
"text": "footer { \n display: block; \n position: absolute; \n width: 100%; \n bottom: 0px; \n}\n"
},
{
"answer_id": 159662,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 1,
"selected": false,
"text": "<style type=\"text/css\">\n #body, #footerSection { position: absolute; }\n #footerSection { bottom: 0px; }\n</style>\n\n<div id=\"body\">\n ...\n <div id=\"footerSection\">\n ...\n </div>\n</div>\n"
},
{
"answer_id": 10016187,
"author": "frontsideup",
"author_id": 618794,
"author_profile": "https://Stackoverflow.com/users/618794",
"pm_score": 1,
"selected": false,
"text": "Position: absolute;\ntop:auto;\nbottom: 0;\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6486/"
] |
159,506
|
<p>Can I programatically set the position of a WPF ListBox's scrollbar? By default, I want it to go in the center.</p>
|
[
{
"answer_id": 159565,
"author": "Bob King",
"author_id": 6897,
"author_profile": "https://Stackoverflow.com/users/6897",
"pm_score": 2,
"selected": false,
"text": "Dim cnt as Integer = myListBox.Items.Count\nDim midPoint as Integer = cnt\\2\nmyListBox.ScrollIntoView(myListBox.Items(midPoint))\n"
},
{
"answer_id": 3029266,
"author": "Zamboni",
"author_id": 174682,
"author_profile": "https://Stackoverflow.com/users/174682",
"pm_score": 4,
"selected": true,
"text": "<Window x:Class=\"ListBoxScrollPosition.Views.MainView\"\n xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\n xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\n Loaded=\"Window_Loaded\"\n Title=\"Main Window\" Height=\"100\" Width=\"200\">\n <DockPanel>\n <Grid>\n <ListBox x:Name=\"myListBox\">\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n <ListBoxItem>Zamboni</ListBoxItem>\n </ListBox>\n </Grid>\n </DockPanel>\n</Window>\n"
},
{
"answer_id": 11196632,
"author": "karol",
"author_id": 1480984,
"author_profile": "https://Stackoverflow.com/users/1480984",
"pm_score": 0,
"selected": false,
"text": "var border = VisualTreeHelper.GetChild(list, 0) as Decorator;\nif (border == null) return;\nvar scrollViewer = border.Child as ScrollViewer;\nif (scrollViewer == null) return;\nscrollViewer.ScrollToVerticalOffset((scrollViewer.ScrollableHeight/list.Items.Count)*\n (list.Items.IndexOf(list.SelectedItem) + 1));\n"
},
{
"answer_id": 59187611,
"author": "user1523904",
"author_id": 1523904,
"author_profile": "https://Stackoverflow.com/users/1523904",
"pm_score": 0,
"selected": false,
"text": " if (MusicList.HasItems)\n {\n Decorator border = VisualTreeHelper.GetChild(MusicList, 0) as Decorator;\n if (border != null)\n {\n ScrollViewer scrollViewer = border.Child as ScrollViewer;\n if (scrollViewer != null)\n {\n MusicList.ScrollIntoView(MusicList.SelectedItem);\n }\n }\n }\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047/"
] |
159,521
|
<p>I mean 100+ MB big; such text files can push the envelope of editors.</p>
<p>I need to look through a large XML file, but cannot if the editor is buggy.</p>
<p>Any suggestions?</p>
|
[
{
"answer_id": 159537,
"author": "Nick Ryberg",
"author_id": 21275,
"author_profile": "https://Stackoverflow.com/users/21275",
"pm_score": 12,
"selected": true,
"text": "tail"
},
{
"answer_id": 1343576,
"author": "Roboprog",
"author_id": 63369,
"author_profile": "https://Stackoverflow.com/users/63369",
"pm_score": 8,
"selected": false,
"text": ".."
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17865/"
] |
159,523
|
<p>When I call <code>Response.Redirect(someUrl)</code> I get the following HttpException:</p>
<blockquote>
<p>Cannot redirect after HTTP headers have been sent.</p>
</blockquote>
<p>Why do I get this? And how can I fix this issue?</p>
|
[
{
"answer_id": 159529,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": false,
"text": "HTTP/1.x 3xx Redirect Reason"
},
{
"answer_id": 159538,
"author": "Samuel Meacham",
"author_id": 23886,
"author_profile": "https://Stackoverflow.com/users/23886",
"pm_score": 8,
"selected": true,
"text": "Response.Redirect(string url)"
},
{
"answer_id": 159543,
"author": "Philip Rieck",
"author_id": 12643,
"author_profile": "https://Stackoverflow.com/users/12643",
"pm_score": 4,
"selected": false,
"text": "Response.Redirect()"
},
{
"answer_id": 14214537,
"author": "SamsonOnNet",
"author_id": 1958024,
"author_profile": "https://Stackoverflow.com/users/1958024",
"pm_score": 1,
"selected": false,
"text": "catch (System.Threading.ThreadAbortException)\n {\n // To Handle HTTP Exception \"Cannot redirect after HTTP headers have been sent\".\n }\n catch (Exception e)\n {//Here you can put your context.response.redirect(\"page.aspx\");}\n"
},
{
"answer_id": 29383317,
"author": "Aashish Garg",
"author_id": 4605106,
"author_profile": "https://Stackoverflow.com/users/4605106",
"pm_score": 0,
"selected": false,
"text": "HttpContext.Current.Server.ClearError();\n// Response.Headers.Clear();\nHttpContext.Current.Response.Redirect(\"/Home/Login\",false);\n"
},
{
"answer_id": 36173422,
"author": "Vasilis",
"author_id": 6103150,
"author_profile": "https://Stackoverflow.com/users/6103150",
"pm_score": 2,
"selected": false,
"text": "return RedirectPermanent(myUrl)"
},
{
"answer_id": 40020986,
"author": "1_bug",
"author_id": 1385292,
"author_profile": "https://Stackoverflow.com/users/1385292",
"pm_score": 1,
"selected": false,
"text": "Response"
},
{
"answer_id": 40372440,
"author": "Dipanki Jadav",
"author_id": 2845214,
"author_profile": "https://Stackoverflow.com/users/2845214",
"pm_score": 2,
"selected": false,
"text": "Response.Write(\"<script type='text/javascript'>\"); Response.Write(\"window.location = '\" + redirect url + \"'</script>\");Response.Flush();\n"
},
{
"answer_id": 48010988,
"author": "user9150083",
"author_id": 9150083,
"author_profile": "https://Stackoverflow.com/users/9150083",
"pm_score": -1,
"selected": false,
"text": "return"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23886/"
] |
159,541
|
<p>I'm running a Django site using the fastcgi interface to nginx. However, some pages are being served truncated (i.e. the page source just stops, sometimes in the middle of a tag). How do I fix this (let me know what extra information is needed, and I'll post it)</p>
<p>Details:</p>
<p>I'm using flup, and spawning the fastcgi server with the following command:</p>
<pre><code>python ./manage.py runfcgi umask=000 maxchildren=5 maxspare=1 minspare=0 method=prefork socket=/path/to/runfiles/django.sock pidfile=/path/to/runfiles/django.pid
</code></pre>
<p>The nginx config is as follows:</p>
<pre><code># search and replace this: {project_location}
pid /path/to/runfiles/nginx.pid;
worker_processes 2;
error_log /path/to/runfiles/error_log;
events {
worker_connections 1024;
use epoll;
}
http {
# default nginx location
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 4 2k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
sendfile on;
tcp_nopush on;
keepalive_timeout 75 20;
tcp_nodelay on;
client_max_body_size 10m;
client_body_buffer_size 256k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
client_body_temp_path /path/to/runfiles/client_body_temp;
proxy_temp_path /path/to/runfiles/proxy_temp;
fastcgi_temp_path /path/to/runfiles/fastcgi_temp;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain text/html application/x-javascript text/xml text/css;
ignore_invalid_headers on;
server {
listen 80;
server_name alpha2.sonyalabs.com;
index index.html;
root /path/to/django-root/static;
# static resources
location ~* ^/static/.*$
{
root /path/to/django-root;
expires 30d;
break;
}
location / {
# host and port to fastcgi server
fastcgi_pass unix:/path/to/runfiles/django.sock;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
location /403.html {
root /usr/local/nginx;
access_log off;
}
location /401.html {
root /usr/local/nginx;
access_log off;
}
location /404.html {
root /usr/local/nginx;
access_log off;
}
location = /_.gif {
empty_gif;
access_log off;
}
access_log /path/to/runfiles/localhost.access_log main;
error_log /path/to/runfiles/localhost.error_log;
}
}
</code></pre>
|
[
{
"answer_id": 4515898,
"author": "dwc",
"author_id": 57301,
"author_profile": "https://Stackoverflow.com/users/57301",
"pm_score": 3,
"selected": false,
"text": ".../nginx/tmp/..."
},
{
"answer_id": 6033063,
"author": "rewritten",
"author_id": 384417,
"author_profile": "https://Stackoverflow.com/users/384417",
"pm_score": 2,
"selected": false,
"text": "spaceless"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2933/"
] |
159,549
|
<p>I want to log to the console when I'm using un-minimized JavaScript files.</p>
<p>Comments are taken out already when I minimize JavaScript. I'm wondering if there's a way I can write a command that isn't commented out but will still be taken out when I minimize the JavaScript file. </p>
|
[
{
"answer_id": 161133,
"author": "Gene",
"author_id": 22673,
"author_profile": "https://Stackoverflow.com/users/22673",
"pm_score": 2,
"selected": true,
"text": "function doLogging(object){}"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9106/"
] |
159,554
|
<p>I'm looking for a built-in function/extended function in T-SQL for string manipulation similar to the <code>String.Format</code> method in .NET.</p>
|
[
{
"answer_id": 836894,
"author": "jj.",
"author_id": 103131,
"author_profile": "https://Stackoverflow.com/users/103131",
"pm_score": 2,
"selected": false,
"text": "FORMATMESSAGE()"
},
{
"answer_id": 1153194,
"author": "Josh",
"author_id": 123234,
"author_profile": "https://Stackoverflow.com/users/123234",
"pm_score": 6,
"selected": false,
"text": "DECLARE @ret_string varchar (255)\nEXEC xp_sprintf @ret_string OUTPUT, \n 'INSERT INTO %s VALUES (%s, %s)', 'table1', '1', '2'\nPRINT @ret_string\n"
},
{
"answer_id": 4502764,
"author": "Karthik D V",
"author_id": 550359,
"author_profile": "https://Stackoverflow.com/users/550359",
"pm_score": 4,
"selected": false,
"text": "-- DROP function will loose the security settings.\nIF object_id('[dbo].[svfn_FormatString]') IS NOT NULL\n DROP FUNCTION [dbo].[svfn_FormatString]\nGO\n\nCREATE FUNCTION [dbo].[svfn_FormatString]\n(\n @Format NVARCHAR(4000),\n @Parameters NVARCHAR(4000),\n @Delimiter CHAR(1) = ','\n)\nRETURNS NVARCHAR(MAX)\nAS\nBEGIN\n /*\n Name: [dbo].[svfn_FormatString]\n Creation Date: 12/18/2020\n\n Purpose: Returns the formatted string (Just like in C-Sharp)\n\n Input Parameters: @Format = The string to be Formatted\n @Parameters = The comma separated list of parameters\n @Delimiter = The delimitter to be used in the formatting process\n\n Format: @Format = N'Hi {0}, Welcome to our site {1}. Thank you {0}'\n @Parameters = N'Karthik,google.com'\n @Delimiter = ',' \n Examples:\n SELECT dbo.svfn_FormatString(N'Hi {0}, Welcome to our site {1}. Thank you {0}', N'Karthik,google.com', default)\n SELECT dbo.svfn_FormatString(N'Hi {0}, Welcome to our site {1}. Thank you {0}', N'Karthik;google.com', ';')\n */\n DECLARE @Message NVARCHAR(400)\n DECLARE @ParamTable TABLE ( Id INT IDENTITY(0,1), Paramter VARCHAR(1000))\n\n SELECT @Message = @Format\n\n ;WITH CTE (StartPos, EndPos) AS\n (\n SELECT 1, CHARINDEX(@Delimiter, @Parameters)\n UNION ALL\n SELECT EndPos + (LEN(@Delimiter)), CHARINDEX(@Delimiter, @Parameters, EndPos + (LEN(@Delimiter)))\n FROM CTE\n WHERE EndPos > 0\n )\n\n INSERT INTO @ParamTable ( Paramter )\n SELECT\n [Id] = SUBSTRING(@Parameters, StartPos, CASE WHEN EndPos > 0 THEN EndPos - StartPos ELSE 4000 END )\n FROM CTE\n\n UPDATE @ParamTable \n SET \n @Message = REPLACE(@Message, '{'+ CONVERT(VARCHAR, Id) + '}', Paramter )\n\n RETURN @Message\nEND\n"
},
{
"answer_id": 4514667,
"author": "BraveNewMath",
"author_id": 551811,
"author_profile": "https://Stackoverflow.com/users/551811",
"pm_score": 0,
"selected": false,
"text": "sp_addmessage @msgnum=50001,@severity=1,@msgText='Hello %s you are #%d',@replace='replace'\nSELECT FORMATMESSAGE(50001, 'Table1', 5)\n"
},
{
"answer_id": 4948646,
"author": "SP007",
"author_id": 610194,
"author_profile": "https://Stackoverflow.com/users/610194",
"pm_score": 2,
"selected": false,
"text": "**>>**IF OBJECT_ID( N'[dbo].[FormatString]', 'FN' ) IS NOT NULL\nDROP FUNCTION [dbo].[FormatString]\nGO\n/***************************************************\nObject Name : FormatString\nPurpose : Returns the formatted string.\nOriginal Author : Karthik D V http://stringformat-in-sql.blogspot.com/\nSample Call:\nSELECT dbo.FormatString ( N'Format {0} {1} {2} {0}', N'1,2,3' )\n*******************************************/\nCREATE FUNCTION [dbo].[FormatString](\n @Format NVARCHAR(4000) ,\n @Parameters NVARCHAR(4000)\n)\nRETURNS NVARCHAR(4000)\nAS\nBEGIN\n --DECLARE @Format NVARCHAR(4000), @Parameters NVARCHAR(4000) select @format='{0}{1}', @Parameters='hello,world'\n DECLARE @Message NVARCHAR(400), @Delimiter CHAR(1)\n DECLARE @ParamTable TABLE ( ID INT IDENTITY(0,1), Parameter VARCHAR(1000) )\n Declare @startPos int, @endPos int\n SELECT @Message = @Format, @Delimiter = ','**>>**\n\n --handle first parameter\n set @endPos=CHARINDEX(@Delimiter,@Parameters)\n if (@endPos=0 and @Parameters is not null) --there is only one parameter\n insert into @ParamTable (Parameter) values(@Parameters)\n else begin\n insert into @ParamTable (Parameter) select substring(@Parameters,0,@endPos)\n end\n\n while @endPos>0\n Begin\n --insert a row for each parameter in the \n set @startPos = @endPos + LEN(@Delimiter)\n set @endPos = CHARINDEX(@Delimiter,@Parameters, @startPos)\n if (@endPos>0)\n insert into @ParamTable (Parameter) \n select substring(@Parameters,@startPos,@endPos - @startPos)\n else\n insert into @ParamTable (Parameter) \n select substring(@Parameters,@startPos,4000) \n End\n\n UPDATE @ParamTable SET @Message = \n REPLACE ( @Message, '{'+CONVERT(VARCHAR,ID) + '}', Parameter )\n RETURN @Message\nEND\nGo\ngrant execute,references on dbo.formatString to public \n"
},
{
"answer_id": 28240424,
"author": "Vadim Loboda",
"author_id": 623190,
"author_profile": "https://Stackoverflow.com/users/623190",
"pm_score": 2,
"selected": false,
"text": "create function dbo.Format1\n(\n @String nvarchar(4000),\n @Param0 sql_variant\n)\nreturns nvarchar(4000)\nas\nbegin\n declare @Null nvarchar(4) = N'NULL';\n\n return replace(@String, N'{0}', cast(isnull(@Param0, @Null) as nvarchar(4000))); \nend\n"
},
{
"answer_id": 30260729,
"author": "g2server",
"author_id": 2293226,
"author_profile": "https://Stackoverflow.com/users/2293226",
"pm_score": 7,
"selected": false,
"text": "FORMATMESSAGE"
},
{
"answer_id": 43696634,
"author": "Tejasvi Hegde",
"author_id": 1726296,
"author_profile": "https://Stackoverflow.com/users/1726296",
"pm_score": 1,
"selected": false,
"text": "select dbo.FormatString('some string %s some int %s date %s','\"abcd\"',100,cast(getdate() as date),DEFAULT,DEFAULT)\nselect dbo.FormatString('some string %s some int %s date time %s','\"abcd\"',100,getdate(),DEFAULT,DEFAULT)\n"
},
{
"answer_id": 59577544,
"author": "Brijesh Kumar Tripathi",
"author_id": 9203434,
"author_profile": "https://Stackoverflow.com/users/9203434",
"pm_score": 2,
"selected": false,
"text": "SELECT FORMATMESSAGE('This is the %s and this is the %s.', 'first variable', 'second variable') AS Result\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
159,567
|
<p>How do I parse the first, middle, and last name out of a fullname field with SQL? </p>
<p>I need to try to match up on names that are not a direct match on full name. I'd like to be able to take the full name field and break it up into first, middle and last name. </p>
<p>The data does not include any prefixes or suffixes. The middle name is optional. The data is formatted 'First Middle Last'.</p>
<p>I'm interested in some practical solutions to get me 90% of the way there. As it has been stated, this is a complex problem, so I'll handle special cases individually.</p>
|
[
{
"answer_id": 159628,
"author": "neonski",
"author_id": 17112,
"author_profile": "https://Stackoverflow.com/users/17112",
"pm_score": 3,
"selected": false,
"text": "SUBSTRING ( expression , start , length )\n"
},
{
"answer_id": 159664,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 3,
"selected": false,
"text": "Jan Olav Olsen Heggelien\n"
},
{
"answer_id": 159676,
"author": "p3t0r",
"author_id": 16685,
"author_profile": "https://Stackoverflow.com/users/16685",
"pm_score": 0,
"selected": false,
"text": "SELECT \n SUBSTRING(fullname, '(\\\\w+)') as firstname,\n SUBSTRING(fullname, '\\\\w+\\\\s(\\\\w+)\\\\s\\\\w+') as middle,\n COALESCE(SUBSTRING(fullname, '\\\\w+\\\\s\\\\w+\\\\s(\\\\w+)'), SUBSTRING(fullname, '\\\\w+\\\\s(\\\\w+)')) as lastname\nFROM \npublic.person\n"
},
{
"answer_id": 159760,
"author": "JosephStyons",
"author_id": 672,
"author_profile": "https://Stackoverflow.com/users/672",
"pm_score": 8,
"selected": true,
"text": "SELECT\n FIRST_NAME.ORIGINAL_INPUT_DATA\n ,FIRST_NAME.TITLE\n ,FIRST_NAME.FIRST_NAME\n ,CASE WHEN 0 = CHARINDEX(' ',FIRST_NAME.REST_OF_NAME)\n THEN NULL --no more spaces? assume rest is the last name\n ELSE SUBSTRING(\n FIRST_NAME.REST_OF_NAME\n ,1\n ,CHARINDEX(' ',FIRST_NAME.REST_OF_NAME)-1\n )\n END AS MIDDLE_NAME\n ,SUBSTRING(\n FIRST_NAME.REST_OF_NAME\n ,1 + CHARINDEX(' ',FIRST_NAME.REST_OF_NAME)\n ,LEN(FIRST_NAME.REST_OF_NAME)\n ) AS LAST_NAME\nFROM\n ( \n SELECT\n TITLE.TITLE\n ,CASE WHEN 0 = CHARINDEX(' ',TITLE.REST_OF_NAME)\n THEN TITLE.REST_OF_NAME --No space? return the whole thing\n ELSE SUBSTRING(\n TITLE.REST_OF_NAME\n ,1\n ,CHARINDEX(' ',TITLE.REST_OF_NAME)-1\n )\n END AS FIRST_NAME\n ,CASE WHEN 0 = CHARINDEX(' ',TITLE.REST_OF_NAME) \n THEN NULL --no spaces @ all? then 1st name is all we have\n ELSE SUBSTRING(\n TITLE.REST_OF_NAME\n ,CHARINDEX(' ',TITLE.REST_OF_NAME)+1\n ,LEN(TITLE.REST_OF_NAME)\n )\n END AS REST_OF_NAME\n ,TITLE.ORIGINAL_INPUT_DATA\n FROM\n ( \n SELECT\n --if the first three characters are in this list,\n --then pull it as a \"title\". otherwise return NULL for title.\n CASE WHEN SUBSTRING(TEST_DATA.FULL_NAME,1,3) IN ('MR ','MS ','DR ','MRS')\n THEN LTRIM(RTRIM(SUBSTRING(TEST_DATA.FULL_NAME,1,3)))\n ELSE NULL\n END AS TITLE\n --if you change the list, don't forget to change it here, too.\n --so much for the DRY prinicple...\n ,CASE WHEN SUBSTRING(TEST_DATA.FULL_NAME,1,3) IN ('MR ','MS ','DR ','MRS')\n THEN LTRIM(RTRIM(SUBSTRING(TEST_DATA.FULL_NAME,4,LEN(TEST_DATA.FULL_NAME))))\n ELSE LTRIM(RTRIM(TEST_DATA.FULL_NAME))\n END AS REST_OF_NAME\n ,TEST_DATA.ORIGINAL_INPUT_DATA\n FROM\n (\n SELECT\n --trim leading & trailing spaces before trying to process\n --disallow extra spaces *within* the name\n REPLACE(REPLACE(LTRIM(RTRIM(FULL_NAME)),' ',' '),' ',' ') AS FULL_NAME\n ,FULL_NAME AS ORIGINAL_INPUT_DATA\n FROM\n (\n --if you use this, then replace the following\n --block with your actual table\n SELECT 'GEORGE W BUSH' AS FULL_NAME\n UNION SELECT 'SUSAN B ANTHONY' AS FULL_NAME\n UNION SELECT 'ALEXANDER HAMILTON' AS FULL_NAME\n UNION SELECT 'OSAMA BIN LADEN JR' AS FULL_NAME\n UNION SELECT 'MARTIN J VAN BUREN SENIOR III' AS FULL_NAME\n UNION SELECT 'TOMMY' AS FULL_NAME\n UNION SELECT 'BILLY' AS FULL_NAME\n UNION SELECT NULL AS FULL_NAME\n UNION SELECT ' ' AS FULL_NAME\n UNION SELECT ' JOHN JACOB SMITH' AS FULL_NAME\n UNION SELECT ' DR SANJAY GUPTA' AS FULL_NAME\n UNION SELECT 'DR JOHN S HOPKINS' AS FULL_NAME\n UNION SELECT ' MRS SUSAN ADAMS' AS FULL_NAME\n UNION SELECT ' MS AUGUSTA ADA KING ' AS FULL_NAME \n ) RAW_DATA\n ) TEST_DATA\n ) TITLE\n ) FIRST_NAME\n"
},
{
"answer_id": 159767,
"author": "Kluge",
"author_id": 8752,
"author_profile": "https://Stackoverflow.com/users/8752",
"pm_score": 0,
"selected": false,
"text": "create table parsname (fullname char(50), name1 char(30), name2 char(30), name3 char(30), name4 char(40));\ninsert into parsname (fullname) select fullname from ImportTable;\nupdate parsname set name1 = substring(fullname, 1, locate(' ', fullname)),\n fullname = ltrim(substring(fullname, locate(' ', fullname), length(fullname)))\n where locate(' ', rtrim(fullname)) > 0;\nupdate parsname set name2 = substring(fullname, 1, locate(' ', fullname)),\n fullname = ltrim(substring(fullname, locate(' ', fullname), length(fullname)))\n where locate(' ', rtrim(fullname)) > 0;\nupdate parsname set name3 = substring(fullname, 1, locate(' ', fullname)),\n fullname = ltrim(substring(fullname, locate(' ', fullname), length(fullname)))\n where locate(' ', rtrim(fullname)) > 0;\nupdate parsname set name4 = substring(fullname, 1, locate(' ', fullname)),\n fullname = ltrim(substring(fullname, locate(' ', fullname), length(fullname)))\n where locate(' ', rtrim(fullname)) > 0;\n// fullname now contains the last word in the string.\nselect fullname as FirstName, '' as MiddleName, '' as LastName from parsname where fullname is not null and name1 is null and name2 is null\nunion all\nselect name1 as FirstName, name2 as MiddleName, fullname as LastName from parsname where name1 is not null and name3 is null\n"
},
{
"answer_id": 159980,
"author": "Even Mien",
"author_id": 73794,
"author_profile": "https://Stackoverflow.com/users/73794",
"pm_score": 0,
"selected": false,
"text": "create procedure [dbo].[import_ParseName]\n( \n @FullName nvarchar(max),\n @FirstName nvarchar(255) output,\n @MiddleName nvarchar(255) output,\n @LastName nvarchar(255) output\n)\nas\nbegin\n\nset @FirstName = ''\nset @MiddleName = ''\nset @LastName = '' \nset @FullName = ltrim(rtrim(@FullName))\n\ndeclare @ReverseFullName nvarchar(max)\nset @ReverseFullName = reverse(@FullName)\n\ndeclare @lengthOfFullName int\ndeclare @endOfFirstName int\ndeclare @beginningOfLastName int\n\nset @lengthOfFullName = len(@FullName)\nset @endOfFirstName = charindex(' ', @FullName)\nset @beginningOfLastName = @lengthOfFullName - charindex(' ', @ReverseFullName) + 1\n\nset @FirstName = case when @endOfFirstName <> 0 \n then substring(@FullName, 1, @endOfFirstName - 1) \n else ''\n end\n\nset @MiddleName = case when (@endOfFirstName <> 0 and @beginningOfLastName <> 0 and @beginningOfLastName > @endOfFirstName)\n then ltrim(rtrim(substring(@FullName, @endOfFirstName , @beginningOfLastName - @endOfFirstName))) \n else ''\n end\n\nset @LastName = case when @beginningOfLastName <> 0 \n then substring(@FullName, @beginningOfLastName + 1 , @lengthOfFullName - @beginningOfLastName)\n else ''\n end\n\nreturn\n\nend \n"
},
{
"answer_id": 1408989,
"author": "Ken Williams",
"author_id": 169947,
"author_profile": "https://Stackoverflow.com/users/169947",
"pm_score": 0,
"selected": false,
"text": "Text::BibTeX::Name"
},
{
"answer_id": 1656234,
"author": "Jonathon Hill",
"author_id": 168815,
"author_profile": "https://Stackoverflow.com/users/168815",
"pm_score": 1,
"selected": false,
"text": "<?\n/*\nName: nameparse.php\nVersion: 0.2a\nDate: 030507\nFirst: 030407\nLicense: GNU General Public License v2\nBugs: If one of the words in the middle name is Ben (or St., for that matter),\n or any other possible last-name prefix, the name MUST be entered in\n last-name-first format. If the last-name parsing routines get ahold\n of any prefix, they tie up the rest of the name up to the suffix. i.e.:\n\n William Ben Carey would yield 'Ben Carey' as the last name, while,\n Carey, William Ben would yield 'Carey' as last and 'Ben' as middle.\n\n This is a problem inherent in the prefix-parsing routines algorithm,\n and probably will not be fixed. It's not my fault that there's some\n odd overlap between various languages. Just don't name your kids\n 'Something Ben Something', and you should be alright.\n\n*/\n\nfunction norm_str($string) {\n return trim(strtolower(\n str_replace('.','',$string)));\n }\n\nfunction in_array_norm($needle,$haystack) {\n return in_array(norm_str($needle),$haystack);\n }\n\nfunction parse_name($fullname) {\n $titles = array('dr','miss','mr','mrs','ms','judge');\n $prefices = array('ben','bin','da','dal','de','del','der','de','e',\n 'la','le','san','st','ste','van','vel','von');\n $suffices = array('esq','esquire','jr','sr','2','ii','iii','iv');\n\n $pieces = explode(',',preg_replace('/\\s+/',' ',trim($fullname)));\n $n_pieces = count($pieces);\n\n switch($n_pieces) {\n case 1: // array(title first middles last suffix)\n $subp = explode(' ',trim($pieces[0]));\n $n_subp = count($subp);\n for($i = 0; $i < $n_subp; $i++) {\n $curr = trim($subp[$i]);\n $next = trim($subp[$i+1]);\n\n if($i == 0 && in_array_norm($curr,$titles)) {\n $out['title'] = $curr;\n continue;\n }\n\n if(!$out['first']) {\n $out['first'] = $curr;\n continue;\n }\n\n if($i == $n_subp-2 && $next && in_array_norm($next,$suffices)) {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n $out['suffix'] = $next;\n break;\n }\n\n if($i == $n_subp-1) {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n continue;\n }\n\n if(in_array_norm($curr,$prefices)) {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n continue;\n }\n\n if($next == 'y' || $next == 'Y') {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n continue;\n }\n\n if($out['last']) {\n $out['last'] .= \" $curr\";\n continue;\n }\n\n if($out['middle']) {\n $out['middle'] .= \" $curr\";\n }\n else {\n $out['middle'] = $curr;\n }\n }\n break;\n case 2:\n switch(in_array_norm($pieces[1],$suffices)) {\n case TRUE: // array(title first middles last,suffix)\n $subp = explode(' ',trim($pieces[0]));\n $n_subp = count($subp);\n for($i = 0; $i < $n_subp; $i++) {\n $curr = trim($subp[$i]);\n $next = trim($subp[$i+1]);\n\n if($i == 0 && in_array_norm($curr,$titles)) {\n $out['title'] = $curr;\n continue;\n }\n\n if(!$out['first']) {\n $out['first'] = $curr;\n continue;\n }\n\n if($i == $n_subp-1) {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n continue;\n }\n\n if(in_array_norm($curr,$prefices)) {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n continue;\n }\n\n if($next == 'y' || $next == 'Y') {\n if($out['last']) {\n $out['last'] .= \" $curr\";\n }\n else {\n $out['last'] = $curr;\n }\n continue;\n }\n\n if($out['last']) {\n $out['last'] .= \" $curr\";\n continue;\n }\n\n if($out['middle']) {\n $out['middle'] .= \" $curr\";\n }\n else {\n $out['middle'] = $curr;\n }\n } \n $out['suffix'] = trim($pieces[1]);\n break;\n case FALSE: // array(last,title first middles suffix)\n $subp = explode(' ',trim($pieces[1]));\n $n_subp = count($subp);\n for($i = 0; $i < $n_subp; $i++) {\n $curr = trim($subp[$i]);\n $next = trim($subp[$i+1]);\n\n if($i == 0 && in_array_norm($curr,$titles)) {\n $out['title'] = $curr;\n continue;\n }\n\n if(!$out['first']) {\n $out['first'] = $curr;\n continue;\n }\n\n if($i == $n_subp-2 && $next &&\n in_array_norm($next,$suffices)) {\n if($out['middle']) {\n $out['middle'] .= \" $curr\";\n }\n else {\n $out['middle'] = $curr;\n }\n $out['suffix'] = $next;\n break;\n }\n\n if($i == $n_subp-1 && in_array_norm($curr,$suffices)) {\n $out['suffix'] = $curr;\n continue;\n }\n\n if($out['middle']) {\n $out['middle'] .= \" $curr\";\n }\n else {\n $out['middle'] = $curr;\n }\n }\n $out['last'] = $pieces[0];\n break;\n }\n unset($pieces);\n break;\n case 3: // array(last,title first middles,suffix)\n $subp = explode(' ',trim($pieces[1]));\n $n_subp = count($subp);\n for($i = 0; $i < $n_subp; $i++) {\n $curr = trim($subp[$i]);\n $next = trim($subp[$i+1]);\n if($i == 0 && in_array_norm($curr,$titles)) {\n $out['title'] = $curr;\n continue;\n }\n\n if(!$out['first']) {\n $out['first'] = $curr;\n continue;\n }\n\n if($out['middle']) {\n $out['middle'] .= \" $curr\";\n }\n else {\n $out['middle'] = $curr;\n }\n }\n\n $out['last'] = trim($pieces[0]);\n $out['suffix'] = trim($pieces[2]);\n break;\n default: // unparseable\n unset($pieces);\n break;\n }\n\n return $out;\n }\n\n\n?>\n"
},
{
"answer_id": 34507330,
"author": "hajili",
"author_id": 1217045,
"author_profile": "https://Stackoverflow.com/users/1217045",
"pm_score": 3,
"selected": false,
"text": "parsename"
},
{
"answer_id": 38261211,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Select \n\nDISTINCT NAMES ,\n\n SUBSTRING(NAMES , 1, CHARINDEX(' ', NAMES) - 1) as FirstName,\n\n RTRIM(LTRIM(REPLACE(REPLACE(NAMES,SUBSTRING(NAMES , 1, CHARINDEX(' ', NAMES) - 1),''),REVERSE( LEFT( REVERSE(NAMES), CHARINDEX(' ', REVERSE(NAMES))-1 ) ),'')))as MiddleName,\n\n REVERSE( LEFT( REVERSE(NAMES), CHARINDEX(' ', REVERSE(NAMES))-1 ) ) as LastName\n\nFrom TABLENAME\n"
},
{
"answer_id": 44426622,
"author": "CharlieNoTomatoes",
"author_id": 3545738,
"author_profile": "https://Stackoverflow.com/users/3545738",
"pm_score": 0,
"selected": false,
"text": "CREATE FUNCTION [dbo].[NameParser]\n(\n @name nvarchar(100)\n)\nRETURNS TABLE\nAS\nRETURN (\n\nWITH prep AS (\n SELECT \n original = @name,\n cleanName = REPLACE(REPLACE(REPLACE(REPLACE(LTRIM(RTRIM(@name)),' ',' '),' ',' '), '.', ''), ',', '')\n)\nSELECT\n prep.original,\n aux.prefix,\n firstName.firstName,\n middleName.middleName,\n lastName.lastName,\n aux.suffix\nFROM\n prep\n CROSS APPLY (\n SELECT \n prefix =\n CASE \n WHEN LEFT(prep.cleanName, 3) IN ('MR ', 'MS ', 'DR ', 'FR ')\n THEN LEFT(prep.cleanName, 2)\n WHEN LEFT(prep.cleanName, 4) IN ('MRS ', 'LRD ', 'SIR ')\n THEN LEFT(prep.cleanName, 3)\n WHEN LEFT(prep.cleanName, 5) IN ('LORD ', 'LADY ', 'MISS ', 'PROF ')\n THEN LEFT(prep.cleanName, 4)\n ELSE ''\n END,\n suffix =\n CASE \n WHEN RIGHT(prep.cleanName, 3) IN (' JR', ' SR', ' II', ' IV')\n THEN RIGHT(prep.cleanName, 2)\n WHEN RIGHT(prep.cleanName, 4) IN (' III', ' ESQ')\n THEN RIGHT(prep.cleanName, 3)\n ELSE ''\n END\n ) aux\n CROSS APPLY (\n SELECT\n baseName = LTRIM(RTRIM(SUBSTRING(prep.cleanName, LEN(aux.prefix) + 1, LEN(prep.cleanName) - LEN(aux.prefix) - LEN(aux.suffix)))),\n numParts = (SELECT COUNT(1) FROM STRING_SPLIT(LTRIM(RTRIM(SUBSTRING(prep.cleanName, LEN(aux.prefix) + 1, LEN(prep.cleanName) - LEN(aux.prefix) - LEN(aux.suffix)))), ' '))\n ) core\n CROSS APPLY (\n SELECT\n firstName = \n CASE\n WHEN core.numParts <= 1 THEN core.baseName\n ELSE LEFT(core.baseName, CHARINDEX(' ', core.baseName, 1) - 1) \n END\n\n ) firstName\n CROSS APPLY (\n SELECT\n remainder = \n CASE\n WHEN core.numParts <= 1 THEN ''\n ELSE LTRIM(SUBSTRING(core.baseName, LEN(firstName.firstName) + 1, 999999))\n END\n ) work1\n CROSS APPLY (\n SELECT\n middleName = \n CASE\n WHEN core.numParts <= 2 THEN ''\n ELSE LEFT(work1.remainder, CHARINDEX(' ', work1.remainder, 1) - 1) \n END\n ) middleName\n CROSS APPLY (\n SELECT\n lastName = \n CASE\n WHEN core.numParts <= 1 THEN ''\n ELSE LTRIM(SUBSTRING(work1.remainder, LEN(middleName.middleName) + 1, 999999))\n END\n ) lastName\n)\n\nGO\n\nSELECT * FROM dbo.NameParser('Madonna')\nSELECT * FROM dbo.NameParser('Will Smith')\nSELECT * FROM dbo.NameParser('Neil Degrasse Tyson')\nSELECT * FROM dbo.NameParser('Dr. Neil Degrasse Tyson')\nSELECT * FROM dbo.NameParser('Mr. Hyde')\nSELECT * FROM dbo.NameParser('Mrs. Thurston Howell, III')\n"
},
{
"answer_id": 48332386,
"author": "James A.",
"author_id": 9236942,
"author_profile": "https://Stackoverflow.com/users/9236942",
"pm_score": 0,
"selected": false,
"text": "SELECT name, REVERSE( SUBSTR( REVERSE(name), 1, STRPOS(REVERSE(name), ' ') ) ) AS middle_name \nFROM name_table"
},
{
"answer_id": 55521279,
"author": "Gus Lopez",
"author_id": 9498689,
"author_profile": "https://Stackoverflow.com/users/9498689",
"pm_score": 0,
"selected": false,
"text": "SELECT NAME,\nCASE WHEN parsename(replace(NAME, ' ', '.'), 4) IS NOT NULL THEN \n parsename(replace(NAME, ' ', '.'), 4) ELSE\n CASE WHEN parsename(replace(NAME, ' ', '.'), 3) IS NOT NULL THEN \n parsename(replace(NAME, ' ', '.'), 3) ELSE\n parsename(replace(NAME, ' ', '.'), 2) end END as FirstName\n ,\nCASE WHEN parsename(replace(NAME, ' ', '.'), 3) IS NOT NULL THEN \n parsename(replace(NAME, ' ', '.'), 2) ELSE NULL END as MiddleName,\n parsename(replace(NAME, ' ', '.'), 1) as LastName\nfrom {@YourTableName}\n"
},
{
"answer_id": 56321076,
"author": "Mukesh Pandey",
"author_id": 7774013,
"author_profile": "https://Stackoverflow.com/users/7774013",
"pm_score": 2,
"selected": false,
"text": "SELECT name\n ,Ltrim(SubString(name, 1, Isnull(Nullif(CHARINDEX(' ', name), 0), 1000))) AS FirstName\n ,Ltrim(SUBSTRING(name, CharIndex(' ', name), CASE \n WHEN (CHARINDEX(' ', name, CHARINDEX(' ', name) + 1) - CHARINDEX(' ', name)) <= 0\n THEN 0\n ELSE CHARINDEX(' ', name, CHARINDEX(' ', name) + 1) - CHARINDEX(' ', name)\n END)) AS MiddleName\n ,Ltrim(SUBSTRING(name, Isnull(Nullif(CHARINDEX(' ', name, Charindex(' ', name) + 1), 0), CHARINDEX(' ', name)), CASE \n WHEN Charindex(' ', name) = 0\n THEN 0\n ELSE LEN(name)\n END)) AS LastName\nFROM yourtableName\n"
},
{
"answer_id": 57056287,
"author": "Vinay Maurya",
"author_id": 6620695,
"author_profile": "https://Stackoverflow.com/users/6620695",
"pm_score": 0,
"selected": false,
"text": "UPDATE Employees\nSET [First Name] = CASE \n WHEN (len(name) - len(Replace(name, '.', ''))) = 2\n THEN PARSENAME(Name, 3)\n WHEN (len(name) - len(Replace(name, '.', ''))) = 1\n THEN PARSENAME(Name, 2)\n ELSE PARSENAME(Name, 1)\n END\n ,[Middle Name] = CASE \n WHEN (len(name) - len(Replace(name, '.', ''))) = 2\n THEN PARSENAME(Name, 2)\n ELSE NULL\n END\n ,[Last Name] = CASE \n WHEN (len(name) - len(Replace(name, '.', ''))) = 2\n THEN PARSENAME(Name, 1)\n WHEN (len(name) - len(Replace(name, '.', ''))) = 1\n THEN PARSENAME(Name, 1)\n ELSE NULL\n END GO\n\nUPDATE Employee\nSET [Name] = Replace([Name], '.', ' ') GO\n"
},
{
"answer_id": 68506141,
"author": "DeFlanko",
"author_id": 4006015,
"author_profile": "https://Stackoverflow.com/users/4006015",
"pm_score": 0,
"selected": false,
"text": ",FullName = CUST.FULLNAME\n,LastName = PARSENAME(REPLACE(CUST.FULLNAME, ',', '.'),2)\n,FirstName = (CASE WHEN PARSENAME(REPLACE(CUST.FULLNAME, ',', '.'),1) LIKE '% %' THEN PARSENAME(REPLACE(PARSENAME(REPLACE(CUST.FULLNAME, ',', '.'),1), ' ', '.'),2) ELSE PARSENAME(REPLACE(CUST.FULLNAME, ',', '.'),1) END)\n,MiddleName = (CASE WHEN PARSENAME(REPLACE(CUST.FULLNAME, ' ', '.'),1) LIKE '%,%' THEN NULL ELSE PARSENAME(REPLACE(CUST.FULLNAME, ' ', '.'),1) END)\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/73794/"
] |
159,590
|
<p>I've used recursion quite a lot on my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems.</p>
<p>So, sometime in the very far past I went to try and find if there existed any "pattern" or text-book way of transforming a common recursion approach to iteration and found nothing. Or at least nothing that I can remember it would help.</p>
<ul>
<li>Are there general rules?</li>
<li>Is there a "pattern"?</li>
</ul>
|
[
{
"answer_id": 159649,
"author": "Andrew Stein",
"author_id": 13029,
"author_profile": "https://Stackoverflow.com/users/13029",
"pm_score": 2,
"selected": false,
"text": "void foo(Node* node)\n{\n if(node == NULL)\n return;\n // Do something with node...\n foo(node->left);\n foo(node->right);\n}\n"
},
{
"answer_id": 159682,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 5,
"selected": false,
"text": "// tail-recursive\nint factorial (int n, int acc = 1)\n{\n if (n == 1)\n return acc;\n else\n return factorial(n - 1, acc * n);\n}\n\n// iterative\nint factorial (int n)\n{\n int acc = 1;\n for (; n > 1; --n)\n acc *= n;\n return acc;\n}\n"
},
{
"answer_id": 159692,
"author": "bobwienholt",
"author_id": 24257,
"author_profile": "https://Stackoverflow.com/users/24257",
"pm_score": 6,
"selected": false,
"text": "void quicksort(int* array, int left, int right)\n{\n if(left >= right)\n return;\n\n int index = partition(array, left, right);\n quicksort(array, left, index - 1);\n quicksort(array, index + 1, right);\n}\n"
},
{
"answer_id": 159777,
"author": "David Segonds",
"author_id": 13673,
"author_profile": "https://Stackoverflow.com/users/13673",
"pm_score": 10,
"selected": true,
"text": "var stack = [];\nstack.push(firstObject);\n\n// while not empty\nwhile (stack.length) {\n\n // Pop off end of stack.\n obj = stack.pop();\n\n // Do stuff.\n // Push other objects on the stack as needed.\n ...\n\n}\n"
},
{
"answer_id": 7185450,
"author": "Tae-Sung Shin",
"author_id": 749973,
"author_profile": "https://Stackoverflow.com/users/749973",
"pm_score": 3,
"selected": false,
"text": "void foo(Node* node)\n{\n if(node == NULL)\n return;\n // Do something with node...\n foo(node->left);\n foo(node->right);\n}\n"
},
{
"answer_id": 8512072,
"author": "T. Webster",
"author_id": 266457,
"author_profile": "https://Stackoverflow.com/users/266457",
"pm_score": 6,
"selected": false,
"text": "public static void AbcRecursiveTraversal(this AbcTreeNode x, List<int> list) {\n if (x != null) {\n AbcRecursiveTraversal(x.a, list);\n AbcRecursiveTraversal(x.b, list);\n AbcRecursiveTraversal(x.c, list);\n list.Add(x.key);//finally visit root\n }\n}\n"
},
{
"answer_id": 10719044,
"author": "naiem",
"author_id": 981646,
"author_profile": "https://Stackoverflow.com/users/981646",
"pm_score": 3,
"selected": false,
"text": "int Sum(int index, int[] array)\n{\n //This is the termination condition\n if (int >= array.Length)\n //This is the returning value when termination condition is true\n return 0;\n\n//This is the recursive call\n var sumofrest = Sum(index+1, array);\n\n//This is the work to do with the current item and the\n //result of recursive call\n return array[index]+sumofrest;\n}\n"
},
{
"answer_id": 16281550,
"author": "Chethan",
"author_id": 377762,
"author_profile": "https://Stackoverflow.com/users/377762",
"pm_score": 4,
"selected": false,
"text": "struct tnode\n{\n tnode(int n) : data(n), left(0), right(0) {}\n tnode *left, *right;\n int data;\n};\n\nvoid insertnode_recur(tnode *node, int num)\n{\n if(node->data <= num)\n {\n if(node->right == NULL)\n node->right = new tnode(num);\n else\n insertnode(node->right, num);\n }\n else\n {\n if(node->left == NULL)\n node->left = new tnode(num);\n else\n insertnode(node->left, num);\n } \n}\n"
},
{
"answer_id": 18026165,
"author": "Rick Giuly",
"author_id": 2593312,
"author_profile": "https://Stackoverflow.com/users/2593312",
"pm_score": 0,
"selected": false,
"text": "function show(node)\n0. if isleaf(node):\n1. print node.name\n2. else:\n3. show(node.left)\n4. show(node)\n5. show(node.right)\n"
},
{
"answer_id": 27210176,
"author": "eold",
"author_id": 395744,
"author_profile": "https://Stackoverflow.com/users/395744",
"pm_score": 0,
"selected": false,
"text": "function rec(...) {\n for/while loop {\n var x = rec(...)\n // make a side effect involving return value x\n }\n}\n"
},
{
"answer_id": 38264992,
"author": "jxh",
"author_id": 315052,
"author_profile": "https://Stackoverflow.com/users/315052",
"pm_score": 2,
"selected": false,
"text": "typedef struct {\n int32_t type;\n int32_t valueint;\n double valuedouble;\n struct cNODE *next;\n struct cNODE *prev;\n struct cNODE *child;\n} cNODE;\n"
},
{
"answer_id": 45677628,
"author": "slim",
"author_id": 7512,
"author_profile": "https://Stackoverflow.com/users/7512",
"pm_score": 3,
"selected": false,
"text": "if(task can be done directly) {\n return result of doing task directly\n} else {\n split task into two or more parts\n solve for each part (possibly by recursing)\n return result constructed by combining these solutions\n}\n"
},
{
"answer_id": 50857115,
"author": "L_J",
"author_id": 5968255,
"author_profile": "https://Stackoverflow.com/users/5968255",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\n#include <stack>\nusing namespace std;\n\nint GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }\n\nstruct Par\n{\n int a, b;\n Par() : Par(0, 0) {}\n Par(int _a, int _b) : a(_a), b(_b) {}\n};\n\nint GCDIter(int a, int b)\n{\n stack<Par> rcstack;\n\n if (b == 0)\n return a;\n rcstack.push(Par(b, a % b));\n\n Par p;\n while (!rcstack.empty()) \n {\n p = rcstack.top();\n rcstack.pop();\n if (p.b == 0)\n continue;\n rcstack.push(Par(p.b, p.a % p.b));\n }\n\n return p.a;\n}\n\nint main()\n{\n //cout << GCD(24, 36) << endl;\n cout << GCDIter(81, 36) << endl;\n\n cin.get();\n return 0;\n}\n"
},
{
"answer_id": 61473850,
"author": "divs1210",
"author_id": 1163490,
"author_profile": "https://Stackoverflow.com/users/1163490",
"pm_score": 1,
"selected": false,
"text": "StackOverflow"
},
{
"answer_id": 68208998,
"author": "shalom",
"author_id": 6074164,
"author_profile": "https://Stackoverflow.com/users/6074164",
"pm_score": 0,
"selected": false,
"text": "startNode = pos(x,y)\n\nStack stack = new Stack();\n\nDictionary visited<pos, bool> = new Dictionary();\n\nstack.Push(startNode);\n\nwhile(stack.count != 0){\n currentNode = stack.Pop();\n if \"check currentNode if not available\"\n continue;\n if \"check if already handled\"\n continue;\n else if \"run if it must be wanted thing should be handled\" \n // make something with pos currentNode.X and currentNode.X \n \n // then add its neighbor nodes to the stack to iterate\n // but at first check if it has already been visited.\n \n if(!visited.Contains(pos(x-1,y)))\n visited[pos(x-1,y)] = true;\n stack.Push(pos(x-1,y));\n if(!visited.Contains(pos(x+1,y)))\n ...\n if(!visited.Contains(pos(x,y+1)))\n ...\n if(!visited.Contains(pos(x,y-1)))\n ...\n}\n\n"
},
{
"answer_id": 68872963,
"author": "Todd",
"author_id": 7915759,
"author_profile": "https://Stackoverflow.com/users/7915759",
"pm_score": 2,
"selected": false,
"text": "sort()"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8167/"
] |
159,594
|
<p>I've organized my code hierarchically and I find myself crawling up the tree using code like the following.</p>
<pre><code>File clientFolder = task.getActionPlan().getClientFile().getClient().getDocumentsFolder();
</code></pre>
<p>I'm not drilling down into the <code>task</code> object; I'm drilling up to its parents, so I don't think I'm losing anything in terms of encapsulation; but a flag is going off in the back of my mind telling me there's something dirty about doing it this way.</p>
<p>Is this wrong?</p>
|
[
{
"answer_id": 159622,
"author": "Chris Cudmore",
"author_id": 18907,
"author_profile": "https://Stackoverflow.com/users/18907",
"pm_score": 0,
"selected": false,
"text": "ActionPlan AP = task.getActionPlan();\nClientFile CF = AP.getClientFile();\nClient C = CF.getClient();\nDocFolder DF = C.getDocumentsFolder();\n"
},
{
"answer_id": 159630,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 2,
"selected": false,
"text": "ActionPlan taskPlan = task.GetActionPlan();\nClientFile clientFileOfTaskPlan = taskPlan.GetClientFile();\nClient clientOfTaskPlan = clientFileOfTaskPlan.GetClient();\nFile clientFolder = clientOfTaskPlan.getDocumentsFolder();\n"
},
{
"answer_id": 159634,
"author": "Georgi",
"author_id": 13209,
"author_profile": "https://Stackoverflow.com/users/13209",
"pm_score": 0,
"selected": false,
"text": " task.getClientFromActionPlan();\n"
},
{
"answer_id": 159749,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 3,
"selected": false,
"text": "File clientFolder = task.DocumentsFolder;\n"
},
{
"answer_id": 160169,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Object a = b.getA();\ndoSomething(a);\n"
},
{
"answer_id": 162036,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 0,
"selected": false,
"text": "enum FolderType { ActionPlan, ClientFile, Client, etc }\n\ninterface IFolder\n{\n IFolder FindTypeViaParent( FolderType folderType )\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
] |
159,599
|
<p>I have a .net project that has a web reference to a service. I would like to update that web reference as part of every build. Is that possible?</p>
|
[
{
"answer_id": 159751,
"author": "Vivek",
"author_id": 7418,
"author_profile": "https://Stackoverflow.com/users/7418",
"pm_score": 5,
"selected": true,
"text": " <Target Name=\"UpdateWebReference\">\n <Message Text=\"Updating Web Reference...\"/>\n <Exec Command=\"wsdl.exe /o "$(OutDir)" /n "$(WebServiceNamespace)" "$(PathToWebServiceURL)"\"/>\n </Target>\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15903/"
] |
159,615
|
<p>When running command-line queries in MySQL you can optionally use '<strong>\G</strong>' as a statement terminator, and instead of the result set columns being listed horizontally across the screen, it will list each column vertically, which the corresponding data to the right. Is there a way to the same or a similar thing with the DB2 command line utility?</p>
<p>Example regular MySQL result</p>
<pre><code>mysql> select * from tagmap limit 2;
+----+---------+--------+
| id | blog_id | tag_id |
+----+---------+--------+
| 16 | 8 | 1 |
| 17 | 8 | 4 |
+----+---------+--------+
</code></pre>
<p>Example Alternate MySQL result:</p>
<pre><code>mysql> select * from tagmap limit 2\G
*************************** 1. row ***************************
id: 16
blog_id: 8
tag_id: 1
*************************** 2. row ***************************
id: 17
blog_id: 8
tag_id: 4
2 rows in set (0.00 sec)
</code></pre>
<p>Obviously, this is much more useful when the columns are large strings, or when there are many columns in a result set, but this demonstrates the formatting better than I can probably explain it.</p>
|
[
{
"answer_id": 27618935,
"author": "Bimal Jha",
"author_id": 4177130,
"author_profile": "https://Stackoverflow.com/users/4177130",
"pm_score": -1,
"selected": false,
"text": "db2 => connect to coldb\n\n Database Connection Information\n\n Database server = DB2/LINUXX8664 10.5.5\n SQL authorization ID = BIMALJHA\n Local database alias = COLDB\n\ndb2 => create table testtable (c1 int, c2 varchar(10)) organize by column\nDB20000I The SQL command completed successfully.\ndb2 => insert into testtable values (2, 'bimal'),(3, 'kumar')\nDB20000I The SQL command completed successfully.\ndb2 => select * from testtable\n\nC1 C2 \n----------- ----------\n 2 bimal \n 3 kumar \n\n 2 record(s) selected.\n\ndb2 => terminate\nDB20000I The TERMINATE command completed successfully.\n"
},
{
"answer_id": 69814199,
"author": "stoeps",
"author_id": 4946225,
"author_profile": "https://Stackoverflow.com/users/4946225",
"pm_score": 0,
"selected": false,
"text": "db2 -x <query>"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8636/"
] |
159,627
|
<p>We just did a move from storing all files locally to a network drive. Problem is that is where my VS projects are also stored now. (No versioning system yet, working on that.) I know I heard of problems with doing this in the past, but never heard of a work-around. Is there a work around?</p>
<p>So my VS is installed locally. The files are on a network drive. How can I get this to work?</p>
<p>EDIT: I know what SHOULD be done, but is there a band-aid I can put on right now to fix this and maintain the network drive?</p>
<p>EDIT 2: I am sure I am not understanding something, but <a href="https://stackoverflow.com/questions/159627/keeping-visual-studio-projects-on-a-network-drive#159702">Bob King</a> has the right idea. I'll work with the lead web developer when he gets back into the office to figure out a temporary solution until we get some sort of version control setup. Thanks for the ideas.</p>
|
[
{
"answer_id": 10217072,
"author": "fschaper",
"author_id": 1021169,
"author_profile": "https://Stackoverflow.com/users/1021169",
"pm_score": 4,
"selected": false,
"text": "<loadFromRemoteSources enabled=\"true\"/>\n"
},
{
"answer_id": 49927622,
"author": "josh",
"author_id": 2703399,
"author_profile": "https://Stackoverflow.com/users/2703399",
"pm_score": 2,
"selected": false,
"text": "mklink /D \"C:\\Users\\Self\\Documents\" \"\\\\domain.net\\users\\self\\My Documents\"\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2535/"
] |
159,704
|
<p>What options are there for serialization when returning instances of custom classes from a WebService?</p>
<p>We have some classes with a number of child collection class properties as well as other properties that may or may not be set depending on usage. These objects are returned from an ASP.NET .asmx WebService decorated with the ScriptService attribute, so are serialized via JSON serialization when returned by the various WebMethods.</p>
<p>The problem is that the out of the box serialization returns all public properties, regardless of whether or not they are used, as well as returning class name and other information in a more verbose manner than would be desired if you wanted to limit the amount of traffic.</p>
<p>Currently, for the classes being returned we have added custom javascript converters that handle the JSON serializtion, and added them to the web.config as below:</p>
<pre><code><system.web.extensions>
<scripting>
<webServices>
<jsonSerialization>
<converters>
<add name="CustomClassConverter" type="Namespace.CustomClassConverter" />
</converters>
</jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
</code></pre>
<p>But this requires a custom converter for each class. Is there any other way to change the out of the box JSON serialization, either through extending the service, creating a custom serializer or the like?</p>
<p><b>Follow Up</b><br>
@marxidad:</p>
<p>We are using the DataContractJsonSerializer class in other applications, however I have been unable to figure out how to apply it to these services. Here's an example of how the services are set-up:</p>
<pre><code>[ScriptService]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public CustomClass GetCustomClassMethod
{
return new customClass();
}
}
</code></pre>
<p>The WebMethods are called by javascript and return data serialized in JSON. The only method we have been able to change the serialization is to use the javascript converters as referenced above? </p>
<p>Is there a way to tell the WebService to use a custom DataContractJsonSerializer? Whether it be by web.config configuration, decorating the service with attributes, etc.? </p>
<p><b>Update</b><br>
Well, we couldn't find any way to switch the out of the box JavaScriptSerializer except for creating individual JavaScriptConverters as above.</p>
<p>What we did on that end to prevent having to create a separate converter was create a generic JavaScriptConverter. We added an empty interface to the classes we wanted handled and the SupportedTypes which is called on web-service start-up uses reflection to find any types that implement the interface kind of like this:</p>
<pre><code>public override IEnumerable<Type> SupportedTypes
{
get
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
AssemblyBuilder dynamicAssemblyCheck = assembly as AssemblyBuilder;
if (dynamicAssemblyCheck == null)
{
foreach (Type type in assembly.GetExportedTypes())
{
if (typeof(ICustomClass).IsAssignableFrom(type))
{
yield return type;
}
}
}
}
}
}
</code></pre>
<p>The actual implementation is a bit different so that the type are cached, and we will likely refactor it to use custom attributes rather than an empty interface.</p>
<p>However with this, we ran into a slightly different problem when dealing with custom collections. These typically just extend a generic list, but the custom classes are used instead of the List<> itself because there is generally custom logic, sorting etc. in the collection classes.</p>
<p>The problem is that the Serialize method for a JavaScriptConverter returns a dictionary which is serialized into JSON as name value pairs with the associated type, whereas a list is returned as an array. So the collection classes could not be easily serialized using the converter. The solution for this was to just not include those types in the converter's SupportedTypes and they serialize perfectly as lists.</p>
<p>So, serialization works, but when you try to pass these objects the other way as a parameter for a web service call, the deserialization breaks, because they can't be the input is treated as a list of string/object dictionaries, which can't be converted to a list of whatever custom class the collection contains. The only way we could find to deal with this is to create a generic class that is a list of string/object dictionaries which then converts the list to the appropriate custom collection class, and then changing any web service parameters to use the generic class instead.</p>
<p>I'm sure there are tons of issues and violations of "best practices" here, but it gets the job done for us without creating a ton of custom converter classes.</p>
|
[
{
"answer_id": 159811,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 0,
"selected": false,
"text": "System.Runtime.Serialization.Json."
},
{
"answer_id": 159911,
"author": "Ty.",
"author_id": 8873,
"author_profile": "https://Stackoverflow.com/users/8873",
"pm_score": 0,
"selected": false,
"text": "[WebMethod]\n[ScriptMethod(ResponseFormat = ResponseFormat.Json)]\npublic XmlDocument GetXmlDocument()\n{\n XmlDocument xmlDoc = new XmlDocument();\n xmlDoc.LoadXml(_xmlString);\n return xmlDoc;\n}\n"
},
{
"answer_id": 802628,
"author": "ntcolonel",
"author_id": 97730,
"author_profile": "https://Stackoverflow.com/users/97730",
"pm_score": 2,
"selected": false,
"text": "[WebMethod]\n[ScriptMethod]\npublic object GimmieData()\n{\n var dalEntity = dal.GimmieEntity(); //However yours works...\n\n return new\n {\n id = dalEntity.Id,\n description = dalEntity.Desc\n };\n\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4299/"
] |
159,705
|
<p>I am checking whether the new name already exists or not.</p>
<p>Code 1</p>
<pre><code>if(cmbxExistingGroups.Properties.Items.Cast<string>().ToList().Exists(txt => txt==txtNewGroup.Text.Trim())) {
MessageBox.Show("already exists.", "Add new group");
}
</code></pre>
<p>Otherwise I could have written:</p>
<p>Code 2</p>
<pre><code>foreach(var str in cmbxExistingGroups.Properties.Items)
{
if(str==txtNewGroup.Text) {
MessageBox.Show("already exists.", "Add new group");
break;
}
}
</code></pre>
<p>I wrote these two and thought I was exploiting language features in code 1.</p>
<p>...and yes: both of them work for me ... I am wondering about the performance :-/</p>
|
[
{
"answer_id": 159776,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 2,
"selected": false,
"text": "cmbxExistingGroups.Properties.Items.Contains(text) \n"
},
{
"answer_id": 159790,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 4,
"selected": false,
"text": "if (cmbxExistingGroups.Properties.Items\n .Cast<string>().ToList()\n .Exists\n (\n txt => txt==txtNewGroup.Text.Trim()\n )) \n{\n MessageBox.Show(\"already exists.\", \"Add new group\");\n}\n"
},
{
"answer_id": 159794,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "if (cmbxExistingGroups.Properties.Items.Cast<string>.Contains(txtNewGroup.Text))\n{\n // Stuff\n}\n"
},
{
"answer_id": 159815,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 1,
"selected": false,
"text": "if( cmbxExistingGroups.ContainsKey(txtNewGroup.Text) )\n{\n MessageBox.Show(\"Already Exists\");\n}\n"
},
{
"answer_id": 159868,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 1,
"selected": false,
"text": "if (mbxExistingGroups.Properties.Items.Cast<string>().Contains(txtNewGroup.Text)) {\n ...\n}\n"
},
{
"answer_id": 160131,
"author": "Alex Lyman",
"author_id": 5897,
"author_profile": "https://Stackoverflow.com/users/5897",
"pm_score": 2,
"selected": false,
"text": "Enumerable.ToList()"
},
{
"answer_id": 160563,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 0,
"selected": false,
"text": "txtNewGroup.Text.Trim()\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22858/"
] |
159,720
|
<p>Coming from a C# background the naming convention for variables and method names are usually either camelCase or PascalCase:</p>
<pre class="lang-cs prettyprint-override"><code>// C# example
string thisIsMyVariable = "a"
public void ThisIsMyMethod()
</code></pre>
<p>In Python, I have seen the above but I have also seen underscores being used:</p>
<pre class="lang-py prettyprint-override"><code># python example
this_is_my_variable = 'a'
def this_is_my_function():
</code></pre>
<p>Is there a more preferable, definitive coding style for Python?</p>
|
[
{
"answer_id": 159798,
"author": "André",
"author_id": 9683,
"author_profile": "https://Stackoverflow.com/users/9683",
"pm_score": 5,
"selected": false,
"text": "SomeClass.doSomething()"
},
{
"answer_id": 160830,
"author": "unmounted",
"author_id": 11596,
"author_profile": "https://Stackoverflow.com/users/11596",
"pm_score": 8,
"selected": false,
"text": "joined_lower"
},
{
"answer_id": 264226,
"author": "claytron",
"author_id": 34530,
"author_profile": "https://Stackoverflow.com/users/34530",
"pm_score": 5,
"selected": false,
"text": "lower_case_with_underscores"
},
{
"answer_id": 8423697,
"author": "John Slade",
"author_id": 104446,
"author_profile": "https://Stackoverflow.com/users/104446",
"pm_score": 10,
"selected": false,
"text": "module_name"
},
{
"answer_id": 50958547,
"author": "Sufiyan Ghori",
"author_id": 1149423,
"author_profile": "https://Stackoverflow.com/users/1149423",
"pm_score": 5,
"selected": false,
"text": "\\__double_leading_and_trailing_underscore__ names"
},
{
"answer_id": 72603424,
"author": "Kai - Kazuya Ito",
"author_id": 8172439,
"author_profile": "https://Stackoverflow.com/users/8172439",
"pm_score": 2,
"selected": false,
"text": "name = \"John\"\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] |
159,721
|
<p>I would like to handle an OracleException thrown when my network/database connection is interrupted, where can I find out what error codes I might can receive?</p>
<p>I guess since we are talking about a connection interruption these would be technically TNS errors such as ORA-12560 "TNS:protocol adapter error." But I have noticed a couple others depending on where exactly the connection is lost and would like to get a full list.</p>
|
[
{
"answer_id": 159770,
"author": "dacracot",
"author_id": 13930,
"author_profile": "https://Stackoverflow.com/users/13930",
"pm_score": 1,
"selected": false,
"text": "ORA-12154 TNS:could not resolve service name\"\nORA-12203 TNS:unable to connect to destination\"\nORA-12500 TNS:listener failed to start a dedicated server process\"\nORA-12545 TNS:name lookup failure\"\nORA-12560 TNS:protocol adapter error\"\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5056/"
] |
159,769
|
<p>I have a complex query with group by and order by clause and I need a sorted row number (1...2...(n-1)...n) returned with every row. Using a ROWNUM (value is assigned to a row after it passes the predicate phase of the query but before the query does any sorting or aggregation) gives me a non-sorted list (4...567...123...45...). I cannot use application for counting and assigning numbers to each row.</p>
|
[
{
"answer_id": 159779,
"author": "Justin Cave",
"author_id": 10397,
"author_profile": "https://Stackoverflow.com/users/10397",
"pm_score": 5,
"selected": true,
"text": "SELECT rownum, a.* \n FROM (<<your complex query including GROUP BY and ORDER BY>>) a\n"
},
{
"answer_id": 159781,
"author": "Carl",
"author_id": 951280,
"author_profile": "https://Stackoverflow.com/users/951280",
"pm_score": 2,
"selected": false,
"text": "select q.*, rownum from (select... group by etc..) q\n"
},
{
"answer_id": 159782,
"author": "cagcowboy",
"author_id": 19629,
"author_profile": "https://Stackoverflow.com/users/19629",
"pm_score": 0,
"selected": false,
"text": "SELECT cols, ROWNUM\nFROM (your query)\n"
},
{
"answer_id": 159787,
"author": "Mark Roddy",
"author_id": 9940,
"author_profile": "https://Stackoverflow.com/users/9940",
"pm_score": 0,
"selected": false,
"text": "SELECT ROWNUM AS RowOrderNumber, Col1, Col2,Col3...\nFROM (\n [Your Original Query Here]\n)\n"
},
{
"answer_id": 175885,
"author": "Osama Al-Maadeed",
"author_id": 25544,
"author_profile": "https://Stackoverflow.com/users/25544",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM\n(SELECT X,Y FROM MY_TABLE WHERE Z=16 ORDER BY MY_DATE DESC)\nWHERE ROWNUM=1\n"
},
{
"answer_id": 3344626,
"author": "zbonig",
"author_id": 203591,
"author_profile": "https://Stackoverflow.com/users/203591",
"pm_score": 0,
"selected": false,
"text": " select * \n (select rownum rn, a.* from \n (<sorted query>) a))\n where rn between 500 and 1000 \n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4235/"
] |
159,797
|
<p>Wikipedia says Ruby is a functional language, but I'm not convinced. Why or why not?</p>
|
[
{
"answer_id": 35512080,
"author": "Elias Perez",
"author_id": 5712328,
"author_profile": "https://Stackoverflow.com/users/5712328",
"pm_score": 4,
"selected": false,
"text": "mode"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159797",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781/"
] |
159,821
|
<p>In an app I'm working on, I have a plain style UITableView that can contain a section containing zero rows. I want to be able to scroll to this section using scrollToRowAtIndexPath:atScrollPosition:animated: but I get an error when I try to scroll to this section due to the lack of child rows.</p>
<p>Apple's calendar application is able to do this, if you look at your calendar in list view, and there are no events in your calendar for today, an empty section is inserted for today and you can scroll to it using the Today button in the toolbar at the bottom of the screen. As far as I can tell Apple may be using a customized UITableView, or they're using a private API...</p>
<p>The only workaround I can think of is to insert an empty UITableCell in that's 0 pixels high and scroll to that. But it's my understanding that having cells of varying heights is really bad for scrolling performance. Still I'll try it anyway, maybe the performance hit won't be too bad.</p>
<p><strong>Update</strong></p>
<p>Since there seems to be no solution to this, I've filed a bug report with apple. If this affects you too, file a duplicate of rdar://problem/6263339 (<a href="http://openradar.appspot.com/radar?id=283" rel="noreferrer">Open Radar link)</a> if you want this to get this fixed faster.</p>
<p><strong>Update #2</strong></p>
<p>I have a decent workaround to this issue, take a look at my answer below.</p>
|
[
{
"answer_id": 351109,
"author": "Mike Akers",
"author_id": 17188,
"author_profile": "https://Stackoverflow.com/users/17188",
"pm_score": 8,
"selected": true,
"text": "NSIndexPath"
},
{
"answer_id": 10782747,
"author": "Simon Tillson",
"author_id": 1416291,
"author_profile": "https://Stackoverflow.com/users/1416291",
"pm_score": 2,
"selected": false,
"text": "if (rowCount > 0) {\n [self.tableView scrollToRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: sectionIndexForNewFolder] \n atScrollPosition: UITableViewScrollPositionMiddle\n animated: TRUE];\n} else { \n CGRect sectionRect = [self.tableView rectForSection: sectionIndexForNewFolder];\n // Try to get a full-height rect which is centred on the sectionRect\n // This produces a very similar effect to UITableViewScrollPositionMiddle.\n CGFloat extraHeightToAdd = sectionRect.size.height - self.tableView.frame.size.height;\n sectionRect.origin.y -= extraHeightToAdd * 0.5f;\n sectionRect.size.height += extraHeightToAdd;\n [self.tableView scrollRectToVisible:sectionRect animated:YES];\n}\n"
},
{
"answer_id": 48180723,
"author": "Chaitanya Ramji",
"author_id": 4833548,
"author_profile": "https://Stackoverflow.com/users/4833548",
"pm_score": 2,
"selected": false,
"text": "if rows > 0 {\n let indexPath = IndexPath(row: 0, section: section)\n self.tableView.setContentOffset(CGPoint.zero, animated: true)\n self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)\n}\n\nelse {\n let sectionRect : CGRect = tableView.rect(forSection: section)\n tableView.scrollRectToVisible(sectionRect, animated: true)\n}\n"
},
{
"answer_id": 55843309,
"author": "Vladimir Pchelyakov",
"author_id": 9917037,
"author_profile": "https://Stackoverflow.com/users/9917037",
"pm_score": 3,
"selected": false,
"text": "let indexPath = IndexPath(row: NSNotFound, section: section)\ntableView.scrollToRow(at: indexPath, at: .middle, animated: true)\n"
},
{
"answer_id": 60375047,
"author": "Idan Moshe",
"author_id": 1673632,
"author_profile": "https://Stackoverflow.com/users/1673632",
"pm_score": 2,
"selected": false,
"text": "[NSIndexPath indexPathForRow:NSNotFound inSection:EXAMPLE]\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17188/"
] |
159,842
|
<p>Often times when mixing jQuery with asp.net I need to use asp .net angle bracket percent, <% %>, syntax within a jQuery selector.</p>
<p>If I would like to separate the JavaScript from markup into different files is there still a way to evaluate my JavaScript file so the angle bracket percents are interpolated before reaching the client browser?</p>
|
[
{
"answer_id": 159865,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 2,
"selected": false,
"text": "jQuery('#<%=MainPanel.ClientId%>').hide('slow');\n"
},
{
"answer_id": 159871,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": false,
"text": "<% code blocks %>"
},
{
"answer_id": 160086,
"author": "Herb Caudill",
"author_id": 239663,
"author_profile": "https://Stackoverflow.com/users/239663",
"pm_score": 1,
"selected": false,
"text": "<system.webServer>\n <handlers>\n <add name=\"Dynamic JS\" path=\"*.js\" verb=\"*\" type=\"System.Web.UI.PageHandlerFactory\" resourceType=\"Unspecified\"/>\n"
},
{
"answer_id": 167298,
"author": "John Grant",
"author_id": 4521,
"author_profile": "https://Stackoverflow.com/users/4521",
"pm_score": 2,
"selected": false,
"text": "// Ajax Javacsript Code below:\n\nType.registerNamespace('SearchGrid');\n\n// Define the behavior properties\n//\nButtonBehavior = function() {\n ButtonBehavior.initializeBase(this);\n this._lnkSearchID = null;\n}\n\n// Create the prototype for the behavior\n//\n//\nSearchGrid.ButtonBehavior.prototype = {\ninitialize: function() {\n SearchGrid.ButtonBehavior.callBaseMethod(this, 'initialize');\n jQuery('#' + this._lnkSearchID).click(function() { alert('We clicked!'); });\n},\n\ndispose: function() {\n SearchGrid.ButtonBehavior.callBaseMethod(this, 'dispose');\n jQuery('#' + this._lnkSearchID).unbind();\n }\n}\n\n// Register the class as a type that inherits from Sys.Component.\nSearchGrid.ButtonBehavior.registerClass('SearchGrid.ButtonBehavior', Sys.Component);\n\n\nif (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4521/"
] |
159,853
|
<p>I have some local changes to an open source project which uses Subversion as its source control. (I do not have commit access on the original project repository.)</p>
<p>My change adds a file, but this file is not included in the output of "svn diff". (It may be worth noting that the new file is a binary, not plain text.)</p>
<p>How can I make a <a href="http://en.wikipedia.org/wiki/Patch_(Unix)" rel="nofollow noreferrer">patch</a> which includes the new files?</p>
<hr>
<pre><code> $ svn st
A tests/foo.zip
$ svn diff
$
</code></pre>
|
[
{
"answer_id": 1051396,
"author": "Balázs Pozsár",
"author_id": 119797,
"author_profile": "https://Stackoverflow.com/users/119797",
"pm_score": 4,
"selected": false,
"text": "svn diff --force --diff-cmd /usr/bin/diff -x -au\n"
},
{
"answer_id": 2255846,
"author": "Jason Favors",
"author_id": 272196,
"author_profile": "https://Stackoverflow.com/users/272196",
"pm_score": 5,
"selected": false,
"text": "svn diff --force --diff-cmd /usr/bin/diff -x \"-au --binary\" OLD-URL NEW-URL > mybinarydiff.diff\n\npatch -p0 --binary -i mybinarydiff.diff\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17732/"
] |
159,856
|
<p>I am running NUnit with the project named AssemblyTest.nunit. The test calls another assembly which uses the log4net assembly. This is using nunit version 2.4.3 with the .net 2.0 framework.</p>
<p>In TestFixtureSetup I am calling log4net.Config.XmlConfigurator.Configure( ) and am getting the following error:</p>
<pre>
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section log4net. (C:\path\to\assembly.dll.config line 7)
</pre>
<p>Is there a way to fix this without renaming the config file to 'AssemblyTest.config'?</p>
|
[
{
"answer_id": 9032281,
"author": "Christoph Brückmann",
"author_id": 909980,
"author_profile": "https://Stackoverflow.com/users/909980",
"pm_score": 4,
"selected": false,
"text": "<configuration>\n <configSections>\n <section name=\"log4net\" type=\"log4net.Config.Log4NetConfigurationSectionHandler, log4net\" />\n </configSections>\n <log4net>\n ...\n </log4net>\n</configuration>\n"
},
{
"answer_id": 19672646,
"author": "Mubashar",
"author_id": 806076,
"author_profile": "https://Stackoverflow.com/users/806076",
"pm_score": 3,
"selected": false,
"text": "BasicConfigurator.Configure();\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24174/"
] |
159,862
|
<p>Short of cutting and pasting, is there a way to sort the methods in my classes in Visual Studio 2008? I like orderly code.</p>
|
[
{
"answer_id": 2539697,
"author": "Handcraftsman",
"author_id": 102536,
"author_profile": "https://Stackoverflow.com/users/102536",
"pm_score": 2,
"selected": false,
"text": "<!--Fixture Setup/Teardown-->\n<Entry>\n <Match>\n <And>\n <Kind Is=\"method\"/>\n <Or>\n <HasAttribute CLRName=\"NUnit.Framework.TestFixtureSetUpAttribute\" Inherit=\"true\"/>\n <HasAttribute CLRName=\"NUnit.Framework.TestFixtureTearDownAttribute\" Inherit=\"true\"/>\n </Or>\n </And>\n </Match>\n </Entry>\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16415/"
] |
159,864
|
<p>I'm working on a control to tie together the view from one ListView to another so that when the master ListView is scrolled, the child ListView view is updated to match. </p>
<p>So far I've been able to get the child ListViews to update their view when the master scrollbar buttons are clicked. The problem is that when clicking and dragging the ScrollBar itself, the child ListViews are not updated. I've looked at the messages being sent using Spy++ and the correct messages are getting sent. </p>
<p>Here is my current code:</p>
<pre><code>public partial class LinkedListViewControl : ListView
{
[DllImport("User32.dll")]
private static extern bool SendMessage(IntPtr hwnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll")]
private static extern bool ShowScrollBar(IntPtr hwnd, int wBar, bool bShow);
[DllImport("user32.dll")]
private static extern int SetScrollPos(IntPtr hWnd, int wBar, int nPos, bool bRedraw);
private const int WM_HSCROLL = 0x114;
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
private const int SB_CTL = 2;
private const int SB_BOTH = 3;
private const int SB_THUMBPOSITION = 4;
private const int SB_THUMBTRACK = 5;
private const int SB_ENDSCROLL = 8;
public LinkedListViewControl()
{
InitializeComponent();
}
private readonly List<ListView> _linkedListViews = new List<ListView>();
public void AddLinkedView(ListView listView)
{
if (!_linkedListViews.Contains(listView))
{
_linkedListViews.Add(listView);
HideScrollBar(listView);
}
}
public bool RemoveLinkedView(ListView listView)
{
return _linkedListViews.Remove(listView);
}
private void HideScrollBar(ListView listView)
{
//Make sure the list view is scrollable
listView.Scrollable = true;
//Then hide the scroll bar
ShowScrollBar(listView.Handle, SB_BOTH, false);
}
protected override void WndProc(ref Message msg)
{
if (_linkedListViews.Count > 0)
{
//Look for WM_HSCROLL messages
if (msg.Msg == WM_HSCROLL)
{
foreach (ListView view in _linkedListViews)
{
SendMessage(view.Handle, WM_HSCROLL, msg.WParam, IntPtr.Zero);
}
}
}
}
}
</code></pre>
<p>Based on <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3111420&SiteID=1" rel="nofollow noreferrer">this post</a> on the MS Tech Forums I tried to capture and process the SB_THUMBTRACK event:</p>
<pre><code> protected override void WndProc(ref Message msg)
{
if (_linkedListViews.Count > 0)
{
//Look for WM_HSCROLL messages
if (msg.Msg == WM_HSCROLL)
{
Int16 hi = (Int16)((int)msg.WParam >> 16);
Int16 lo = (Int16)msg.WParam;
foreach (ListView view in _linkedListViews)
{
if (lo == SB_THUMBTRACK)
{
SetScrollPos(view.Handle, SB_HORZ, hi, true);
int wParam = 4 + 0x10000 * hi;
SendMessage(view.Handle, WM_HSCROLL, (IntPtr)(wParam), IntPtr.Zero);
}
else
{
SendMessage(view.Handle, WM_HSCROLL, msg.WParam, IntPtr.Zero);
}
}
}
}
// Pass message to default handler.
base.WndProc(ref msg);
}
</code></pre>
<p>This will update the location of the child ListView ScrollBar but does not change the actual view in the child.</p>
<p>So my questions are: </p>
<ol>
<li>Is it possible to update the child ListViews when the master ListView ScrollBar is dragged?</li>
<li>If so, how?</li>
</ol>
|
[
{
"answer_id": 167089,
"author": "Rob Allen",
"author_id": 149,
"author_profile": "https://Stackoverflow.com/users/149",
"pm_score": 1,
"selected": false,
"text": "masterList.Scroll += new ScrollEventHandler(this.masterList_scroll);\n"
},
{
"answer_id": 175553,
"author": "Jeremy",
"author_id": 9266,
"author_profile": "https://Stackoverflow.com/users/9266",
"pm_score": 1,
"selected": false,
"text": "public class MyListView : System.Windows.Forms.ListView\n{\n const int WM_HSCROLL = 0x0114;\n const int WM_VSCROLL = 0x0115;\n\n private ScrollEventHandler evtHScroll_m;\n private ScrollEventHandler evtVScroll_m;\n\n public event ScrollEventHandler OnHScroll\n {\n add\n {\n evtHScroll_m += value;\n }\n remove\n {\n evtHScroll_m -= value;\n }\n }\n\n public event ScrollEventHandler OnHVcroll\n {\n add\n {\n evtVScroll_m += value;\n }\n remove\n {\n evtVScroll_m -= value;\n }\n }\n\n protected override void WndProc(ref System.Windows.Forms.Message msg) \n { \n if (msg.Msg == WM_HSCROLL && evtHScroll_m != null) \n {\n evtHScroll_m(this,new ScrollEventArgs(ScrollEventType.ThumbTrack, msg.WParam.ToInt32()));\n }\n\n if (msg.Msg == WM_VSCROLL && evtVScroll_m != null) \n {\n evtVScroll_m(this, new ScrollEventArgs(ScrollEventType.ThumbTrack, msg.WParam.ToInt32()));\n }\n base.WndProc(ref msg); \n }\n"
},
{
"answer_id": 275954,
"author": "AZDean",
"author_id": 12058,
"author_profile": "https://Stackoverflow.com/users/12058",
"pm_score": 3,
"selected": true,
"text": "public class MyListView : ListView\n{\n public event ScrollEventHandler HScrollEvent;\n\n protected override void WndProc(ref System.Windows.Forms.Message msg) \n {\n if (msg.Msg==WM_HSCROLL && HScrollEvent != null)\n HScrollEvent(this,new ScrollEventArgs(ScrollEventType.ThumbTrack, (int)msg.WParam));\n\n base.WndProc(ref msg);\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1314/"
] |
159,886
|
<p>I've seen this is various codebases, and wanted to know if this generally frowned upon or not.</p>
<p>For example:</p>
<pre><code>public class MyClass
{
public int Id;
public MyClass()
{
Id = new Database().GetIdFor(typeof(MyClass));
}
}
</code></pre>
|
[
{
"answer_id": 159921,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 3,
"selected": false,
"text": "public class MyClass : IDisposable\n{\n private Database db;\n private int? _id;\n\n public MyClass()\n {\n db = new Database();\n }\n\n public int Id\n {\n get\n {\n if (_id == null) _id = db.GetIdFor(typeof(MyClass));\n return _id.Value;\n }\n }\n\n public void Dispose()\n {\n db.Close();\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5619/"
] |
159,888
|
<p>You're stepping through C/C++ code and have just called a Win32 API that has failed (typically by returning some unhelpful generic error code, like 0). Your code doesn't make a subsequent GetLastError() call whose return value you could inspect for further error information.</p>
<p>How can you get the error value without recompiling and reproducing the failure? Entering "GetLastError()" in the Watch window doesn't work ("syntax error").</p>
|
[
{
"answer_id": 159898,
"author": "QBziZ",
"author_id": 11572,
"author_profile": "https://Stackoverflow.com/users/11572",
"pm_score": 3,
"selected": false,
"text": "ERR,hr"
},
{
"answer_id": 160024,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 7,
"selected": true,
"text": "@err"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4994/"
] |
159,889
|
<p>I'm developing an iPhone app that uses the built-in SQLite database. I'm trying to view and open the database via the <code>sqlite3</code> command line tool so I can execute arbitrary SQL against it.</p>
<p>When I run my app in the simulator, the <code>.sqlite</code> file it creates is located at <code>~/Library/Application Support/iPhone Simulator/User/Applications/</code>.</p>
<p>How can I see that file on the physical iPhone?</p>
|
[
{
"answer_id": 14472700,
"author": "abbood",
"author_id": 766570,
"author_profile": "https://Stackoverflow.com/users/766570",
"pm_score": 1,
"selected": false,
"text": "which sqlite3"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49611/"
] |
159,910
|
<p>Is there a way my program can determine when it's running on a Remote Desktop (Terminal Services)?</p>
<p>I'd like to enable an "inactivity timeout" on the program when it's running on a Remote Desktop session. Since users are notorious for leaving Remote Desktop sessions open, I want my program to terminate after a specified period of inactivity. But, I don't want the inactivity timeout enabled for non-RD users.</p>
|
[
{
"answer_id": 241176,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 4,
"selected": false,
"text": "/// <summary>\n/// Indicates if we're running in a remote desktop session.\n/// If we are, then you MUST disable animations and double buffering i.e. Pay your taxes!\n/// \n/// </summary>\n/// <returns></returns>\npublic static Boolean IsRemoteSession\n{\n //This is just a friendly wrapper around the built-in way\n get\n {\n return System.Windows.Forms.SystemInformation.TerminalServerSession;\n }\n}\n"
},
{
"answer_id": 2766161,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 3,
"selected": false,
"text": "BOOL IsRemoteSession(void)\n{\n return GetSystemMetrics( SM_REMOTESESSION );\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8752/"
] |
159,914
|
<p>Does anybody know a way with JavaScript or CSS to basically grey out a certain part of a form/div in HTML?</p>
<p>I have a '<em>User Profile</em>' form where I want to disable part of it for a '<em>Non-Premium</em>' member, but want the user to see what is behind the form and place a '<em>Call to Action</em>' on top of it.</p>
<p>Does anybody know an easy way to do this either via CSS or JavaScript?</p>
<p>Edit: I will make sure that the form doesn't work on server side so CSS or JavaScript will suffice.</p>
|
[
{
"answer_id": 159962,
"author": "dacracot",
"author_id": 13930,
"author_profile": "https://Stackoverflow.com/users/13930",
"pm_score": 6,
"selected": false,
"text": "<div id=\"darkLayer\" class=\"darkClass\" style=\"display:none\"></div>\n"
},
{
"answer_id": 159989,
"author": "Mike",
"author_id": 24316,
"author_profile": "https://Stackoverflow.com/users/24316",
"pm_score": 6,
"selected": true,
"text": "$('div.profileform').block({\n message: '<h1>Premium Users only</h1>',\n});\n"
},
{
"answer_id": 7351362,
"author": "Oscar",
"author_id": 935286,
"author_profile": "https://Stackoverflow.com/users/935286",
"pm_score": 2,
"selected": false,
"text": "With opacity\n\n\n//function to grey out the screen\n$(function() {\n// Create overlay and append to body:\n$('<div id=\"ajax-busy\"/>').css({\n opacity: 0.5, \n position: 'fixed',\n top: 0,\n left: 0,\n width: '100%',\n height: $(window).height() + 'px',\n background: 'white url(../images/loading.gif) no-repeat center'\n }).hide().appendTo('body');\n});\n\n\n$.ajax({\n type: \"POST\",\n url: \"Page\",\n data: JSON.stringify({ parameters: XXXXXXXX }),\n contentType: \"application/json; charset=utf-8\",\n dataType: \"json\",\n beforeSend: function() {\n $('#ajax-busy').show();\n },\n success: function(msg) {\n $('#ajax-busy').hide();\n\n },\n error: function() {\n $(document).ajaxError(function(xhr, ajaxOptions, thrownError) {\n alert('status: ' + ajaxOptions.status + '-' + ajaxOptions.statusText + ' \\n' + 'error:\\n' + ajaxOptions.responseText);\n });\n }\n});\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8534/"
] |
159,924
|
<p>I'm slowly moving all of my <code>LAMP websites</code> from <code>mysql_</code> functions to <code>PDO</code> functions and I've hit my first brick wall. I don't know how to loop through results with a parameter. I am fine with the following:</p>
<pre><code>foreach ($database->query("SELECT * FROM widgets") as $results)
{
echo $results["widget_name"];
}
</code></pre>
<p>However if I want to do something like this:</p>
<pre><code>foreach ($database->query("SELECT * FROM widgets WHERE something='something else'") as $results)
{
echo $results["widget_name"];
}
</code></pre>
<p>Obviously the 'something else' will be dynamic.</p>
|
[
{
"answer_id": 159967,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 3,
"selected": false,
"text": "$sql = \"SELECT * FROM widgets WHERE something='something else'\";\nforeach ($database->query($sql) as $row) {\n echo $row[\"widget_name\"];\n}\n"
},
{
"answer_id": 160365,
"author": "Shabbyrobe",
"author_id": 15004,
"author_profile": "https://Stackoverflow.com/users/15004",
"pm_score": 7,
"selected": true,
"text": "// connect to PDO\n$pdo = new PDO(\"mysql:host=localhost;dbname=test\", \"user\", \"password\");\n\n// the following tells PDO we want it to throw Exceptions for every error.\n// this is far more useful than the default mode of throwing php errors\n$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n\n// prepare the statement. the placeholders allow PDO to handle substituting\n// the values, which also prevents SQL injection\n$stmt = $pdo->prepare(\"SELECT * FROM product WHERE productTypeId=:productTypeId AND brand=:brand\");\n\n// bind the parameters\n$stmt->bindValue(\":productTypeId\", 6);\n$stmt->bindValue(\":brand\", \"Slurm\");\n\n// initialise an array for the results\n$products = array();\n$stmt->execute();\nwhile ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {\n $products[] = $row;\n}\n"
},
{
"answer_id": 17102106,
"author": "John K",
"author_id": 969423,
"author_profile": "https://Stackoverflow.com/users/969423",
"pm_score": 2,
"selected": false,
"text": "// Wrap a PDOStatement to iterate through all result rows. Uses a \n// local cache to allow rewinding.\nclass PDOStatementIterator implements Iterator\n{\n public\n $stmt,\n $cache,\n $next;\n\n public function __construct($stmt)\n {\n $this->cache = array();\n $this->stmt = $stmt;\n }\n\n public function rewind()\n {\n reset($this->cache);\n $this->next();\n }\n\n public function valid()\n {\n return (FALSE !== $this->next);\n }\n\n public function current()\n {\n return $this->next[1];\n }\n\n public function key()\n {\n return $this->next[0];\n }\n\n public function next()\n {\n // Try to get the next element in our data cache.\n $this->next = each($this->cache);\n\n // Past the end of the data cache\n if (FALSE === $this->next)\n {\n // Fetch the next row of data\n $row = $this->stmt->fetch(PDO::FETCH_ASSOC);\n\n // Fetch successful\n if ($row)\n {\n // Add row to data cache\n $this->cache[] = $row;\n }\n\n $this->next = each($this->cache);\n }\n }\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/428190/"
] |
159,926
|
<p>My company unwittingly switched from cvs to subversion and now we're all wishing we had cvs back.
I know there's tools to migrate history and changes from cvs to svn and there's no equivalent to do the reverse.
Any suggestions or ideas on how to do this?</p>
|
[
{
"answer_id": 2641628,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 1,
"selected": false,
"text": "git svn clone http://thesvnserver ourrepo\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12386/"
] |
159,928
|
<p>I want to change/animate the Foreground property of a custom button control template depending on the control's state.</p>
<p>Pre-RC0, I set the Foreground of the ContentPresenter, gave it an x:Name, and referenced it in the VisualStateManager transitions.</p>
<p>Now, ContentPresenter no longer has a Foreground, since it doesn't inherit from Control anymore. Usually, I would set the Foreground in the Style which is applied to the templated control. But I cannot reference that from the VisualStateManager transitions / states. I also cannot wrap it in a TextBlock which has the Foreground property set, and (<strong>edit:</strong>) Border has no Foreground property.</p>
<p>Help is greatly appreciated.</p>
<h3>Update:</h3>
<p>I can solve the problem for some of the removed properties with a Border, but not those relating to font/text, including Foreground.</p>
<p>Since it doesn't seem possible, in my particular case I was able to replace the ContentPresenter with a TextBlock.</p>
|
[
{
"answer_id": 1232348,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<ControlTemplate TargetType=\"{x:Type ButtonBase}\">\n <ContentControl Content=\"{TemplateBinding Content}\" Foreground=\"{Binding Foreground}\" />\n</ControlTemplate>\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159928",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23222/"
] |
159,934
|
<p>How would one structure a table for an entity that can have a one to many relationship to itself? Specifically, I'm working on an app to track animal breeding. Each animal has an ID; it's also got a sire ID and a dame ID. So it's possible to have a one to many from the sire or dame to its offspring. I would be inclined to something like this:</p>
<pre><code>ID INT NOT NULL PRIMARY KEY
SIRE_ID INT
DAME_ID INT
</code></pre>
<p>and record a null value for those animals which were purchased and added to the breeding stock and an ID in the table for the rest. </p>
<p>So:</p>
<ol>
<li>Can someone point me to an
article/web page that discusses
modeling this sort of relationship?</li>
<li>Should the ID be an INT or some sort
of String? A NULL in the INT would
indicate that the animal has no
parents in the database but a String
with special flag values could be
used to indicate the same thing.</li>
<li><p>Would this possibly be best modeled
via two tables? I mean one table
for the animals and a separate
table solely indicating kinship e. g.:</p>
<p>Animal</p>
<p>ID INT NOT NULL PRIMARY KEY</p>
<p>Kinship</p>
<p>ID INT NOT NULL PRIMARY KEY FOREIGN KEY</p>
<p>SIRE_ID INT PRIMARY KEY FOREIGN KEY</p>
<p>DAME_ID INT PRIMARY KEY FOREIGN KEY</p></li>
</ol>
<p>I apologize for the above: my SQL is rusty. I hope it sort of conveys what I'm thinking about. </p>
|
[
{
"answer_id": 159997,
"author": "Thilo",
"author_id": 14955,
"author_profile": "https://Stackoverflow.com/users/14955",
"pm_score": 2,
"selected": false,
"text": "ID INT NOT NULL PRIMARY KEY\nSIRE_ID INT REFERENCES TABLENAME (ID)\nDAME_ID INT REFERENCES TABLENAME (ID)\n"
},
{
"answer_id": 160004,
"author": "borjab",
"author_id": 16206,
"author_profile": "https://Stackoverflow.com/users/16206",
"pm_score": 0,
"selected": false,
"text": " ID Primary Key,\n Parent_ID Foreing_Key\n ( data )\n"
},
{
"answer_id": 160005,
"author": "tsilb",
"author_id": 11112,
"author_profile": "https://Stackoverflow.com/users/11112",
"pm_score": 1,
"selected": false,
"text": "[ID],[Sire_ID],[Dame_ID];\n0,null,null (male)\n1,null,null (female)\n2,null,null (female)\n3,0,1 (male)\n4,0,2 (male)\n5,null,null (female)\n6,3,5\n7,4,5\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159934",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2820/"
] |
159,950
|
<p>How do I change the system-wide short date format in Ubuntu? For example, Thunderbird is showing dates in the DD/MM/YY format, and I would like to change it to MM/DD/YY or YYYY-MM-DD.</p>
<p>The best information I can find so far is in this thread:</p>
<p><a href="http://ubuntuforums.org/showthread.php?t=193916" rel="noreferrer">http://ubuntuforums.org/showthread.php?t=193916</a></p>
<p>Edit: I want to change the system-wide date format, so that all my applications use this new date format.</p>
|
[
{
"answer_id": 160036,
"author": "agnul",
"author_id": 6069,
"author_profile": "https://Stackoverflow.com/users/6069",
"pm_score": 1,
"selected": false,
"text": "LC_TIME"
},
{
"answer_id": 46157865,
"author": "Nishi",
"author_id": 211369,
"author_profile": "https://Stackoverflow.com/users/211369",
"pm_score": 3,
"selected": false,
"text": "time-format"
},
{
"answer_id": 47386424,
"author": "Arya",
"author_id": 2954429,
"author_profile": "https://Stackoverflow.com/users/2954429",
"pm_score": 1,
"selected": false,
"text": "en_US"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159950",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24311/"
] |
159,978
|
<p>What are differences between declaring a method in a base type "<code>virtual</code>" and then overriding it in a child type using the "<code>override</code>" keyword as opposed to simply using the "<code>new</code>" keyword when declaring the matching method in the child type? </p>
|
[
{
"answer_id": 159993,
"author": "albertein",
"author_id": 23020,
"author_profile": "https://Stackoverflow.com/users/23020",
"pm_score": 9,
"selected": true,
"text": "public class Foo\n{\n public bool DoSomething() { return false; }\n}\n\npublic class Bar : Foo\n{\n public new bool DoSomething() { return true; }\n}\n\npublic class Test\n{\n public static void Main ()\n {\n Foo test = new Bar ();\n Console.WriteLine (test.DoSomething ());\n }\n}\n"
},
{
"answer_id": 159994,
"author": "Joseph Daigle",
"author_id": 507,
"author_profile": "https://Stackoverflow.com/users/507",
"pm_score": 4,
"selected": false,
"text": "new"
},
{
"answer_id": 160011,
"author": "Franci Penov",
"author_id": 17028,
"author_profile": "https://Stackoverflow.com/users/17028",
"pm_score": 6,
"selected": false,
"text": "class A\n{\n public void foo()\n {\n Console.WriteLine(\"A::foo()\");\n }\n public virtual void bar()\n {\n Console.WriteLine(\"A::bar()\");\n }\n}\n\nclass B : A\n{\n public new void foo()\n {\n Console.WriteLine(\"B::foo()\");\n }\n public override void bar()\n {\n Console.WriteLine(\"B::bar()\");\n }\n}\n\nclass Program\n{\n static int Main(string[] args)\n {\n B b = new B();\n A a = b;\n a.foo(); // Prints A::foo\n b.foo(); // Prints B::foo\n a.bar(); // Prints B::bar\n b.bar(); // Prints B::bar\n return 0;\n }\n}\n"
},
{
"answer_id": 160034,
"author": "Wedge",
"author_id": 332,
"author_profile": "https://Stackoverflow.com/users/332",
"pm_score": 3,
"selected": false,
"text": "(new SubClass() as BaseClass).VirtualFoo()\n"
},
{
"answer_id": 160095,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 8,
"selected": false,
"text": "public class Foo\n{\n public /*virtual*/ bool DoSomething() { return false; }\n}\n\npublic class Bar : Foo\n{\n public /*override or new*/ bool DoSomething() { return true; }\n}\n"
},
{
"answer_id": 6743287,
"author": "Chetan",
"author_id": 851405,
"author_profile": "https://Stackoverflow.com/users/851405",
"pm_score": 2,
"selected": false,
"text": "new"
},
{
"answer_id": 39343057,
"author": "Dror Weiss",
"author_id": 1006127,
"author_profile": "https://Stackoverflow.com/users/1006127",
"pm_score": 2,
"selected": false,
"text": "override"
},
{
"answer_id": 53639866,
"author": "Emre Tapcı",
"author_id": 8489067,
"author_profile": "https://Stackoverflow.com/users/8489067",
"pm_score": 1,
"selected": false,
"text": "virtual"
},
{
"answer_id": 68192875,
"author": "Mehdi",
"author_id": 12648236,
"author_profile": "https://Stackoverflow.com/users/12648236",
"pm_score": 1,
"selected": false,
"text": "using System; \nusing System.Text; \n \nnamespace OverrideAndNew \n{ \n class Program \n { \n static void Main(string[] args) \n { \n BaseClass bc = new BaseClass(); \n DerivedClass dc = new DerivedClass(); \n BaseClass bcdc = new DerivedClass(); \n \n // The following two calls do what you would expect. They call \n // the methods that are defined in BaseClass. \n bc.Method1(); \n bc.Method2(); \n // Output: \n // Base - Method1 \n // Base - Method2 \n \n // The following two calls do what you would expect. They call \n // the methods that are defined in DerivedClass. \n dc.Method1(); \n dc.Method2(); \n // Output: \n // Derived - Method1 \n // Derived - Method2 \n \n // The following two calls produce different results, depending\n // on whether override (Method1) or new (Method2) is used. \n bcdc.Method1(); \n bcdc.Method2(); \n // Output: \n // Derived - Method1 \n // Base - Method2 \n } \n } \n \n class BaseClass \n { \n public virtual void Method1() \n { \n Console.WriteLine(\"Base - Method1\"); \n } \n \n public virtual void Method2() \n { \n Console.WriteLine(\"Base - Method2\"); \n } \n } \n \n class DerivedClass : BaseClass \n { \n public override void Method1() \n { \n Console.WriteLine(\"Derived - Method1\"); \n } \n \n public new void Method2() \n { \n Console.WriteLine(\"Derived - Method2\"); \n } \n } \n} \n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159978",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9898/"
] |
159,983
|
<p>In C++, on Linux, how can I write a function to return a temporary filename that I can then open for writing?</p>
<p>The filename should be as unique as possible, so that another process using the same function won't get the same name.</p>
|
[
{
"answer_id": 160008,
"author": "twk",
"author_id": 23524,
"author_profile": "https://Stackoverflow.com/users/23524",
"pm_score": 3,
"selected": false,
"text": " #include <stdio.h>\n\n FILE *tmpfile(void);\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16976/"
] |
159,990
|
<p>I've done some Python but have just now starting to use Ruby<br>
I could use a good explanation of the difference between "self" in these two languages. </p>
<p><strong>Obvious on first glance:</strong><br>
Self is not a keyword in Python, but there is a "self-like" value no matter what you call it.<br>
Python methods receive self as an explicit argument, whereas Ruby does not.<br>
Ruby sometimes has methods explicitly defined as part of self using dot notation.</p>
<p><strong>Initial Googling reveals</strong><br>
<a href="http://rubylearning.com/satishtalim/ruby_self.html" rel="noreferrer">http://rubylearning.com/satishtalim/ruby_self.html</a><br>
<a href="http://www.ibiblio.org/g2swap/byteofpython/read/self.html" rel="noreferrer">http://www.ibiblio.org/g2swap/byteofpython/read/self.html</a> </p>
|
[
{
"answer_id": 160017,
"author": "interstar",
"author_id": 8482,
"author_profile": "https://Stackoverflow.com/users/8482",
"pm_score": 3,
"selected": false,
"text": "class X :\n def __init__(a,val) :\n a.x = val\n def p(b) :\n print b.x\n\nx = X(6)\nx.p()\n"
},
{
"answer_id": 160227,
"author": "webmat",
"author_id": 6349,
"author_profile": "https://Stackoverflow.com/users/6349",
"pm_score": 4,
"selected": true,
"text": "class C\n puts \"I am a #{self}\"\n def instance_method\n puts 'instance_method'\n end\n def self.class_method\n puts 'class_method'\n end\nend\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/159990",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2242/"
] |
160,009
|
<p>I went to all the documentation, also I went to the IRC channel (BTW a great community) and they told me that is not possible to create a model and limit choices in a field where the 'current user' is in a ForeignKey.
I will try to explain this with an example:</p>
<pre><code>class Project(models.Model):
name = models.CharField(max_length=100)
employees = models.ManyToManyField(Profile, limit_choices_to={'active': '1'})
class TimeWorked(models.Model):
project = models.ForeignKey(Project, limit_choices_to={'user': user})
hours = models.PositiveIntegerField()
</code></pre>
<p>Of course that code doesn't work because there is no 'user' object, but that was my idea and I was trying to send the object 'user' to the model to just limit the choices where the current user has projects, I don't want to see projects where I'm not in.</p>
<p>Thank you very much if you can help me or give me any advice, I don't want to you write all the app, just a tip how to deal with that. I have 2 days with this in my head and I can't figure it out :(</p>
<p><strong>UPDATE</strong>: The solution is here: <a href="http://collingrady.wordpress.com/2008/07/24/useful-form-tricks-in-django/" rel="noreferrer">http://collingrady.wordpress.com/2008/07/24/useful-form-tricks-in-django/</a> sending <code>request.user</code> to a model.</p>
|
[
{
"answer_id": 160421,
"author": "ilvar",
"author_id": 1215136,
"author_profile": "https://Stackoverflow.com/users/1215136",
"pm_score": 2,
"selected": false,
"text": "choices"
},
{
"answer_id": 161615,
"author": "Dmitry Shevchenko",
"author_id": 7437,
"author_profile": "https://Stackoverflow.com/users/7437",
"pm_score": -1,
"selected": true,
"text": "from threading import local\n\n_thread_locals = local()\ndef get_current_user():\n return getattr(getattr(_thread_locals, 'user', None),'id',None)\n\nclass ThreadLocals(object):\n \"\"\"Middleware that gets various objects from the\n request object and saves them in thread local storage.\"\"\"\n def process_request(self, request):\n _thread_locals.user = getattr(request, 'user', None)\n"
},
{
"answer_id": 4656296,
"author": "Anentropic",
"author_id": 202168,
"author_profile": "https://Stackoverflow.com/users/202168",
"pm_score": 3,
"selected": false,
"text": "from datetime import datetime, timedelta\nfrom django import forms\nfrom mysite.models import Project, TimeWorked\n\nclass TimeWorkedForm(forms.ModelForm):\n def __init__(self, user, *args, **kwargs):\n super(ProjectForm, self).__init__(*args, **kwargs)\n self.fields['project'].queryset = Project.objects.filter(user=user)\n\n class Meta:\n model = TimeWorked\n"
},
{
"answer_id": 55389028,
"author": "Stephen G Tuggy",
"author_id": 5067822,
"author_profile": "https://Stackoverflow.com/users/5067822",
"pm_score": 1,
"selected": false,
"text": "# ...\n\nclass Proposal(models.Model):\n # ...\n\n # Soft foreign key reference to customer\n customer_id = models.PositiveIntegerField()\n\n # ...\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16342/"
] |
160,016
|
<p>Following the development of Ruby very closely I learned that detailed character encoding is implemented in Ruby 1.9. My question for now is: How may Ruby be used at the moment to talk to a database that stores all data in UTF8?</p>
<p>Background: I am involved in a new project where Ruby/RoR is at least an option. But the project needs to rely on an internationalized character set (it's spread over many countries), preferably UTF8.</p>
<p>So how do you deal with that? Thanks in advance.</p>
|
[
{
"answer_id": 160372,
"author": "A. Morrow",
"author_id": 10140,
"author_profile": "https://Stackoverflow.com/users/10140",
"pm_score": 0,
"selected": false,
"text": "file.txt:\n¡Hola! ¿Como estás? Leí el artículo. ¡Fue muy excellente!\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160016",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13209/"
] |
160,022
|
<p>Is there anyway to determine if a ResourceManager contains a named resource? Currently I am catching the MissingManifestResourceException but I hate having to use Exceptions for non-exceptional situations. There must be some way to enumerate the name value pairs of a ResourceManager through reflection, or something?</p>
<p><strong>EDIT</strong>: A little more detail. The resources are not in executing assembly, however the ResourceManager is working just fine. If I try <code>_resourceMan.GetResourceSet(_defaultCuture, false, true)</code> I get null, whereas if I try <code>_resourceMan.GetString("StringExists")</code> I get a string back.</p>
|
[
{
"answer_id": 162013,
"author": "Jonathan C Dickinson",
"author_id": 24064,
"author_profile": "https://Stackoverflow.com/users/24064",
"pm_score": 6,
"selected": true,
"text": " // At startup.\n ResourceManager mgr = Resources.ResourceManager;\n List<string> keys = new List<string>();\n\n ResourceSet set = mgr.GetResourceSet(CultureInfo.CurrentCulture, true, true);\n foreach (DictionaryEntry o in set)\n {\n keys.Add((string)o.Key);\n }\n mgr.ReleaseAllResources();\n\n Console.WriteLine(Resources.A);\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3798/"
] |
160,030
|
<p>Is there a macro that does it? Which DTE objects to use?</p>
|
[
{
"answer_id": 160839,
"author": "Andrei Belogortseff",
"author_id": 17037,
"author_profile": "https://Stackoverflow.com/users/17037",
"pm_score": -1,
"selected": false,
"text": "#define WANT_BREAK_IN_EVERY_FUNCTION\n\n#ifdef WANT_BREAK_IN_EVERY_FUNCTION\n#define DEBUG_BREAK DebugBreak();\n#else\n#define DEBUG_BREAK \n#endif\n"
},
{
"answer_id": 188829,
"author": "Constantin",
"author_id": 20310,
"author_profile": "https://Stackoverflow.com/users/20310",
"pm_score": 1,
"selected": false,
"text": "bm mymodule!CSpam::*\n"
},
{
"answer_id": 357807,
"author": "tfinniga",
"author_id": 9042,
"author_profile": "https://Stackoverflow.com/users/9042",
"pm_score": 3,
"selected": false,
"text": "Sub TemporaryMacro()\n DTE.ActiveDocument.Selection.StartOfDocument()\n Dim returnValue As vsIncrementalSearchResult\n While True\n DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.StartForward()\n returnValue = DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.AppendCharAndSearch(AscW(\"{\"))\n DTE.ActiveDocument.ActiveWindow.Object.ActivePane.IncrementalSearch.Exit()\n If Not (returnValue = vsIncrementalSearchResult.vsIncrementalSearchResultFound) Then\n Return\n End If\n DTE.ExecuteCommand(\"Debug.ToggleBreakpoint\")\n DTE.ExecuteCommand(\"Edit.GotoBrace\")\n DTE.ActiveDocument.Selection.CharRight()\n End While\nEnd Sub\n"
},
{
"answer_id": 3370624,
"author": "RichieHindle",
"author_id": 21886,
"author_profile": "https://Stackoverflow.com/users/21886",
"pm_score": 4,
"selected": false,
"text": "CMyClass::*\n"
},
{
"answer_id": 20211467,
"author": "alexkovelsky",
"author_id": 2874220,
"author_profile": "https://Stackoverflow.com/users/2874220",
"pm_score": 0,
"selected": false,
"text": "Sub BreakAtEveryFunction()\nFor Each project In DTE.Solution.Projects\n SetBreakpointOnEveryFunction(project)\nNext project\nEnd Sub\n\n\nSub SetBreakpointOnEveryFunction(ByVal project As Project)\nDim cm = project.CodeModel\n\n' Look for all the namespaces and classes in the \n' project.\nDim list As List(Of CodeFunction)\nlist = New List(Of CodeFunction)\nDim ce As CodeElement\nFor Each ce In cm.CodeElements\n If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then\n ' Determine whether that namespace or class \n ' contains other classes.\n GetClass(ce, list)\n End If\nNext\n\nFor Each cf As CodeFunction In list\n\n DTE.Debugger.Breakpoints.Add(cf.FullName)\nNext\n\nEnd Sub\n\nSub GetClass(ByVal ct As CodeElement, ByRef list As List(Of CodeFunction))\n\n' Determine whether there are nested namespaces or classes that \n' might contain other classes.\nDim aspace As CodeNamespace\nDim ce As CodeElement\nDim cn As CodeNamespace\nDim cc As CodeClass\nDim elements As CodeElements\nIf (TypeOf ct Is CodeNamespace) Then\n cn = CType(ct, CodeNamespace)\n elements = cn.Members\nElse\n cc = CType(ct, CodeClass)\n elements = cc.Members\nEnd If\nTry\n For Each ce In elements\n If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then\n GetClass(ce, list)\n End If\n If (TypeOf ce Is CodeFunction) Then\n list.Add(ce)\n End If\n Next\nCatch\nEnd Try\nEnd Sub\n"
},
{
"answer_id": 37243519,
"author": "joshcomley",
"author_id": 64519,
"author_profile": "https://Stackoverflow.com/users/64519",
"pm_score": 0,
"selected": false,
"text": "EnvDTE.TextSelection textSelection = (EnvDTE.TextSelection)dte.ActiveWindow.Selection;\n// I'm sure there's a better way to get the line count than this...\nvar lines = File.ReadAllLines(dte.ActiveDocument.FullName).Length;\nvar methods = new List<CodeElement>();\nvar oldLine = textSelection.AnchorPoint.Line;\nvar oldLineOffset = textSelection.AnchorPoint.LineCharOffset;\nEnvDTE.CodeElement codeElement = null;\nfor (var i = 0; i < lines; i++)\n{\n try\n {\n textSelection.MoveToLineAndOffset(i, 1);\n // I'm sure there's a better way to get a code element by point than this...\n codeElement = textSelection.ActivePoint.CodeElement[vsCMElement.vsCMElementFunction];\n if (codeElement != null)\n {\n if (!methods.Contains(codeElement))\n {\n methods.Add(codeElement);\n }\n }\n }\n catch\n {\n //MessageBox.Show(\"Add error handling here.\");\n }\n}\n\n// Restore cursor position\ntextSelection.MoveToLineAndOffset(oldLine, oldLineOffset);\n\n// This could be in the for-loop above, but it's here instead just for\n// clarity of the two separate jobs; find all methods, then add the\n// breakpoints\nforeach (var method in methods)\n{\n dte.Debugger.Breakpoints.Add(\n Line: method.StartPoint.Line,\n File: dte.ActiveDocument.FullName);\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20310/"
] |
160,045
|
<p>Is there a way to place a watch on variable and only have Visual Studio break when that value changes?</p>
<p>It would make it so much easier to find tricky state issues.</p>
<p>Can this be done?</p>
<p>Breakpoint conditions still need a breakpoint set, and I'd rather set a watch and let Visual Studio set the breakpoints at state changes.</p>
|
[
{
"answer_id": 160074,
"author": "AShelly",
"author_id": 10396,
"author_profile": "https://Stackoverflow.com/users/10396",
"pm_score": 8,
"selected": true,
"text": "&myVariable\n"
},
{
"answer_id": 160107,
"author": "Michael Petrotta",
"author_id": 23897,
"author_profile": "https://Stackoverflow.com/users/23897",
"pm_score": 5,
"selected": false,
"text": "// Assuming C#\nif (condition)\n{\n System.Diagnostics.Debugger.Break();\n}\n"
},
{
"answer_id": 5206696,
"author": "momboco",
"author_id": 646316,
"author_profile": "https://Stackoverflow.com/users/646316",
"pm_score": 4,
"selected": false,
"text": "class A \n{ \n public: \n A();\n\n private:\n int m_value;\n};\n"
},
{
"answer_id": 18616729,
"author": "Marcello",
"author_id": 2531142,
"author_profile": "https://Stackoverflow.com/users/2531142",
"pm_score": 4,
"selected": false,
"text": "private bool m_Var = false;\nprotected bool var\n{\n get { \n return m_var;\n }\n\n set { \n m_var = value;\n }\n}\n"
},
{
"answer_id": 37869667,
"author": "Craig",
"author_id": 525558,
"author_profile": "https://Stackoverflow.com/users/525558",
"pm_score": 5,
"selected": false,
"text": "set"
},
{
"answer_id": 54180293,
"author": "R Risack",
"author_id": 4559295,
"author_profile": "https://Stackoverflow.com/users/4559295",
"pm_score": 2,
"selected": false,
"text": "myVariable"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160045",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
160,051
|
<p>I'm working on a database that needs to represent computers and their users. Each computer can have multiple users and each user can be associated with multiple computers, so it's a classic many-to-many relationship. However, there also needs to be a concept of a "primary" user. I have to be able to join against the primary user to list all computers with their primary users. I'm not sure what the best way structure this in the database:</p>
<p>1) As I'm currently doing: linking table with a boolean IsPrimary column. Joining requires something like ON (c.computer_id = l.computer_id AND l.is_primary = 1). It works, but it feels wrong because it's not easy to constrain the data to only have one primary user per computer.</p>
<p>2) A field on the computer table that points directly at a user row, all rows in the user table represent non-primary users. This represents the one-primary-per-computer constraint better, but makes getting a list of computer-users harder.</p>
<p>3) A field on the computer table linking to a row in the linking table. Feels strange...</p>
<p>4) Something else?</p>
<p>What is the 'relational' way to describe this relationship?</p>
<p>EDIT:
@Mark Brackett: The third option seems a lot less strange to me now that you've shown how nice it can look. For some reason I didn't even think of using a compound foreign key, so I was thinking I'd have to add an identity column on the linking table to make it work. Looks great, thanks! </p>
<p>@j04t: Cool, I'm glad we agree on #3 now.</p>
|
[
{
"answer_id": 160073,
"author": "Swati",
"author_id": 12682,
"author_profile": "https://Stackoverflow.com/users/12682",
"pm_score": 0,
"selected": false,
"text": "computer_id"
},
{
"answer_id": 160108,
"author": "Simurr",
"author_id": 3478,
"author_profile": "https://Stackoverflow.com/users/3478",
"pm_score": 1,
"selected": false,
"text": "user id (pk)\n"
},
{
"answer_id": 160123,
"author": "Mark",
"author_id": 5904,
"author_profile": "https://Stackoverflow.com/users/5904",
"pm_score": 0,
"selected": false,
"text": "LEFT JOIN c.computer_id = l.computer_id AND l.sequence = 1\n"
},
{
"answer_id": 160129,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 4,
"selected": true,
"text": "User { \n UserId \n PRIMARY KEY (UserId) \n}\n\nComputer { \n ComputerId, PrimaryUserId\n PRIMARY KEY (UserId) \n FOREIGN KEY (ComputerId, PrimaryUserId) \n REFERENCES Computer_User (ComputerId, UserId) \n}\n\nComputer_User { \n ComputerId, UserId \n PRIMARY KEY (ComputerId, UserId)\n FOREIGN KEY (ComputerId) \n REFERENCES Computer (ComputerId)\n FOREIGN KEY (UserId) \n REFERENCES User (UserId)\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9617/"
] |
160,082
|
<p>There are a ton of drivers & famous applications that are not available in 64-bit. Adobe for instance does not provider a 64-bit Flash player plugin for Internet Explorer. And because of that, even though I am running 64-bit Vista, I have to run 32-bit IE. Microsoft Office, Visual Studio also don't ship in 64-bit AFAIK.</p>
<p>Now personally, I haven't had much problems building my applications in 64-bit. I just have to remember a few rules of thumb, e.g. always use SIZE_T instead of UINT32 for string lengths etc.</p>
<p>So my question is, what is preventing people from building for 64-bit?</p>
|
[
{
"answer_id": 160139,
"author": "jvasak",
"author_id": 5840,
"author_profile": "https://Stackoverflow.com/users/5840",
"pm_score": 4,
"selected": false,
"text": "long"
},
{
"answer_id": 160192,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 3,
"selected": false,
"text": "\"LARGE_ADDRESS_AWARE\""
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15071/"
] |
160,097
|
<p>Pardon my ASP ignorance, but what's the difference?</p>
|
[
{
"answer_id": 160117,
"author": "Swati",
"author_id": 12682,
"author_profile": "https://Stackoverflow.com/users/12682",
"pm_score": 5,
"selected": true,
"text": "<%# %>"
},
{
"answer_id": 160205,
"author": "wangzq",
"author_id": 10564,
"author_profile": "https://Stackoverflow.com/users/10564",
"pm_score": 2,
"selected": false,
"text": "<asp:SqlDataSource ... Runat=\"server\"\n ConnectionString=\"<%$ ConnectionStrings:Northwind %>\"\n/>\n\n<asp:Literal Runat=\"server\"\n Text=\"<%$ Resources:MyResources, MyText %>\"\n/>\n"
},
{
"answer_id": 512061,
"author": "mangokun",
"author_id": 59389,
"author_profile": "https://Stackoverflow.com/users/59389",
"pm_score": 0,
"selected": false,
"text": "var e = document.getElementById('<%= lblDescription.ClientID %>');\ne.innerHTML = 'getElementById(\\'lblDescription\\') will be null';\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781/"
] |
160,104
|
<p>I've been using this long command:</p>
<pre><code>svn st | awk '/\?/ {print $2}' | xargs svn add
</code></pre>
<p>Similarly, to svn rm files I accidentally deleted with normal rm with :</p>
<pre><code>svn st | awk '/\!/ {print $2}' | xargs svn rm --force
</code></pre>
<p>I guess I can write a bash function to do these two, but I'd prefer an interactive add/rm like the one git has.</p>
|
[
{
"answer_id": 160177,
"author": "Brandon DuRette",
"author_id": 17834,
"author_profile": "https://Stackoverflow.com/users/17834",
"pm_score": 3,
"selected": false,
"text": "svnapply.sh"
},
{
"answer_id": 1515401,
"author": "Mark Shust",
"author_id": 183810,
"author_profile": "https://Stackoverflow.com/users/183810",
"pm_score": 3,
"selected": false,
"text": "svn add `svn status | grep ?`\n"
},
{
"answer_id": 18706236,
"author": "Johnny Utahh",
"author_id": 605356,
"author_profile": "https://Stackoverflow.com/users/605356",
"pm_score": 3,
"selected": false,
"text": "svn add --force ./*\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13200/"
] |
160,105
|
<p>How do you change controls' Z-order in MFC <strong>at design time</strong> - i.e. I can't use SetWindowPos or do this at runtime - I want to see the changed z-order in the designer (even if I have to resort to direct-editing the .rc code).</p>
<p>I have an MFC dialog to which I am adding controls. If there is overlap between the edges of the controls, I want to bring one to the front of the other. In Windows Forms or WPF, etc. I can Bring to Front, Send to Back, Bring Forward, Send Back. I don't find these options in MFC, nor can I tell how it determines what is in front, as a control just added is often behind a control that was there previously. How can I manipulate the Z-order in MFC? Even if I have to manipulate the .rc file code directly (i.e. end-run around the designer).</p>
|
[
{
"answer_id": 160119,
"author": "Adam Pierce",
"author_id": 5324,
"author_profile": "https://Stackoverflow.com/users/5324",
"pm_score": 3,
"selected": false,
"text": "GetDlgItem(IDC_MYCONTROL)->SetWindowPos(HWND_TOP,\n 0, 0, 0, 0,\n SWP_NOMOVE | SWP_NOSIZE);\n"
},
{
"answer_id": 22186511,
"author": "linquize",
"author_id": 1031218,
"author_profile": "https://Stackoverflow.com/users/1031218",
"pm_score": 1,
"selected": false,
"text": "GetDlgItem(IDC_CONTROL1)->SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE)\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8787/"
] |
160,106
|
<p>What is the correct way to implement the "find as you type" behavior on a TComboBox descendant component whose style is csOwnerDrawFixed?</p>
|
[
{
"answer_id": 161065,
"author": "John Thomas",
"author_id": 22599,
"author_profile": "https://Stackoverflow.com/users/22599",
"pm_score": 1,
"selected": false,
"text": "with timIncSearch do\n begin\n Enabled:=False;\n Enabled:=True;\n end;"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16120/"
] |
160,118
|
<p>I have a class with both a static and a non-static interface in C#. Is it possible to have a static and a non-static method in a class with the same name and signature?</p>
<p>I get a compiler error when I try to do this, but for some reason I thought there was a way to do this. Am I wrong or is there no way to have both static and non-static methods in the same class?</p>
<p>If this is not possible, is there a good way to implement something like this that can be applied generically to any situation?</p>
<p><strong>EDIT</strong><br>
From the responses I've received, it's clear that there is no way to do this. I'm going with a different naming system to work around this problem.</p>
|
[
{
"answer_id": 160133,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 4,
"selected": false,
"text": "class Foo\n{\n static void Bar()\n {\n }\n\n void Fizz()\n {\n Bar();\n }\n}\n"
},
{
"answer_id": 9365897,
"author": "andasa",
"author_id": 1221686,
"author_profile": "https://Stackoverflow.com/users/1221686",
"pm_score": 6,
"selected": false,
"text": "interface IFoo\n{\n void Bar();\n}\n\nclass Foo : IFoo\n{\n static void Bar()\n {\n }\n\n void IFoo.Bar()\n {\n Bar();\n }\n}\n"
},
{
"answer_id": 43697391,
"author": "Nick Sotiros",
"author_id": 1429446,
"author_profile": "https://Stackoverflow.com/users/1429446",
"pm_score": 3,
"selected": false,
"text": "class Logger {\n public static Logger instance;\n\n public static void Log(string message) {\n instance.Log(message); // currently the compiler thinks this is ambiguous, but really its not at all. Clearly we want the non-static method\n }\n\n public void Log(string message) {\n\n }\n\n public void DoStuff() {\n Log(\"doing instance stuff\"); // this could be ambiguous, but in my opinion it should default to a call to this.Log()\n Logger.Log(\"doing global stuff\"); // if you want the global qualify it explicitly\n }\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392/"
] |
160,141
|
<p>C# novice here, when the int 'max' below is 0 I get a divide by zero error, I can see why this happens but how should I handle this when max is 0? position is also an int.</p>
<pre><code> private void SetProgressBar(string text, int position, int max)
{
try
{
int percent = (100 * position) / max; //when max is 0 bug hits
string txt = text + String.Format(". {0}%", percent);
SetStatus(txt);
}
catch
{
}
}
</code></pre>
|
[
{
"answer_id": 160146,
"author": "Simon",
"author_id": 24039,
"author_profile": "https://Stackoverflow.com/users/24039",
"pm_score": 4,
"selected": false,
"text": "int percent = 0\nif (max != 0) percent = (100*position) / max\n"
},
{
"answer_id": 160148,
"author": "palehorse",
"author_id": 312,
"author_profile": "https://Stackoverflow.com/users/312",
"pm_score": 2,
"selected": false,
"text": "if ( max == 0 ) {\n txt = \"0%\";\n} else {\n // Do the other stuff....\n"
},
{
"answer_id": 160150,
"author": "Swati",
"author_id": 12682,
"author_profile": "https://Stackoverflow.com/users/12682",
"pm_score": 3,
"selected": false,
"text": "int percent = ( max > 0 ) ? (100 * position) / max : 0;"
},
{
"answer_id": 160157,
"author": "Bob King",
"author_id": 6897,
"author_profile": "https://Stackoverflow.com/users/6897",
"pm_score": 0,
"selected": false,
"text": "if (max == 0) \n{\n //do special handling here\n}\nelse\n{\n //do normal code here\n}\n"
},
{
"answer_id": 160158,
"author": "ckramer",
"author_id": 20504,
"author_profile": "https://Stackoverflow.com/users/20504",
"pm_score": 0,
"selected": false,
"text": "private void SetProgressBar(string text, int position, int max)\n{\n if(max == 0)\n return;\n int percent = (100 * position) / max; //when max is 0 bug hits\n string txt = text + String.Format(\". {0}%\", percent);\n SetStatus(txt);\n}\n"
},
{
"answer_id": 160160,
"author": "Dre",
"author_id": 23033,
"author_profile": "https://Stackoverflow.com/users/23033",
"pm_score": 0,
"selected": false,
"text": "int percent = 0;\nif (max != 0)\n ...;\n"
},
{
"answer_id": 160161,
"author": "tzot",
"author_id": 6899,
"author_profile": "https://Stackoverflow.com/users/6899",
"pm_score": 1,
"selected": false,
"text": "int percent = (100 * position) / max;\n"
},
{
"answer_id": 66557189,
"author": "Stephen85",
"author_id": 11224134,
"author_profile": "https://Stackoverflow.com/users/11224134",
"pm_score": 0,
"selected": false,
"text": "int percent = max != 0 ? (100 * position) / max : 0;\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
160,144
|
<p>How can I find the XY coordinates of an HTML element (DIV) from JavaScript if they were not explicitly set?</p>
|
[
{
"answer_id": 160189,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 3,
"selected": false,
"text": "myPos = findPos(document.getElementById('something'))\nx = myPos[0]\ny = myPos[1]\n\nfunction findPos(obj) {\n var curleft = curtop = 0;\n if (obj.offsetParent) {\n curleft = obj.offsetLeft\n curtop = obj.offsetTop\n while (obj = obj.offsetParent) {\n curleft += obj.offsetLeft\n curtop += obj.offsetTop\n }\n }\n return [curleft,curtop];\n}\n"
},
{
"answer_id": 160428,
"author": "Andrew Hedges",
"author_id": 11577,
"author_profile": "https://Stackoverflow.com/users/11577",
"pm_score": 5,
"selected": false,
"text": "// Based on: http://www.quirksmode.org/js/findpos.html\nvar getCumulativeOffset = function (obj) {\n var left, top;\n left = top = 0;\n if (obj.offsetParent) {\n do {\n left += obj.offsetLeft;\n top += obj.offsetTop;\n } while (obj = obj.offsetParent);\n }\n return {\n x : left,\n y : top\n };\n};\n"
},
{
"answer_id": 5004338,
"author": "jjthrash",
"author_id": 218026,
"author_profile": "https://Stackoverflow.com/users/218026",
"pm_score": 2,
"selected": false,
"text": "function findPos(element) {\n if (element) {\n var parentPos = findPos(element.offsetParent);\n return [\n parentPos.X + element.offsetLeft,\n parentPos.Y + element.offsetTop\n ];\n } else {\n return [0,0];\n }\n}\n"
},
{
"answer_id": 8861193,
"author": "ThinkingStiff",
"author_id": 918414,
"author_profile": "https://Stackoverflow.com/users/918414",
"pm_score": 2,
"selected": false,
"text": "Element.prototype"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
160,147
|
<p>Here's a curious one. I have a class A. It has an item of class B, which I want to initialize in the constructor of A using an initializer list, like so:</p>
<pre><code>class A {
public:
A(const B& b): mB(b) { };
private:
B mB;
};
</code></pre>
<p>Is there a way to catch exceptions that might be thrown by mB's copy-constructor while still using the initializer list method? Or would I have to initialize mB within the constructor's braces in order to have a try/catch?</p>
|
[
{
"answer_id": 160164,
"author": "Adam Wright",
"author_id": 1200,
"author_profile": "https://Stackoverflow.com/users/1200",
"pm_score": 8,
"selected": true,
"text": "C::C()\ntry : init1(), ..., initn()\n{\n // Constructor\n}\ncatch(...)\n{\n // Handle exception\n}\n"
},
{
"answer_id": 160171,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 4,
"selected": false,
"text": "A::A(const B& b) try : mB(b) \n{ \n // constructor stuff\n}\ncatch (/* exception type */) \n{\n // handle the exception\n}\n"
},
{
"answer_id": 6676341,
"author": "Mikhail Semenov",
"author_id": 653772,
"author_profile": "https://Stackoverflow.com/users/653772",
"pm_score": 2,
"selected": false,
"text": "#include <iostream>\n#include <exception>\n#include <string>\n\nusing namespace std;\n\nclass my_exception: public exception\n{\n string message;\npublic:\n my_exception(const char* message1)\n {\n message = message1;\n }\n\n virtual const char* what() const throw()\n {\n cout << message << endl;\n return message.c_str();\n }\n\n virtual ~my_exception() throw() {};\n};\n\nclass E\n{\npublic:\n E(const char* message) { throw my_exception(message);}\n};\n\nclass A\n{\n E p;\npublic:\n A()\n try :p(\"E failure\")\n {\n cout << \"A constructor\" << endl;\n }\n catch (const exception& ex)\n {\n cout << \"Inside A. Constructor failure: \" << ex.what() << endl;\n }\n};\n\n\nint main()\n{\n try\n {\n A z;\n }\n catch (const exception& ex)\n {\n cout << \"In main. Constructor failure: \" << ex.what() << endl;\n }\n return 0;\n}\n"
},
{
"answer_id": 35265504,
"author": "IceFire",
"author_id": 2573127,
"author_profile": "https://Stackoverflow.com/users/2573127",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\n#include <memory>\nusing namespace std;\n\nclass MyOtherClass\n{\npublic:\n MyOtherClass()\n {\n throw std::runtime_error(\"not working\");\n }\n};\n\nclass MyClass\n{\npublic:\n typedef std::unique_ptr<MyOtherClass> MyOtherClassPtr;\n\n MyClass()\n {\n try\n {\n other = std::make_unique<MyOtherClass>();\n }\n catch(...)\n {\n cout << \"initialization failed.\" << endl;\n }\n\n cout << \"other is initialized: \" << (other ? \"yes\" : \"no\");\n }\n\nprivate:\n std::unique_ptr<MyOtherClass> other;\n};\n\nint main()\n{\n MyClass c;\n\n return 0;\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12193/"
] |
160,175
|
<p>If you have a hash (or reference to a hash) in perl with many dimensions and you want to iterate across all values, what's the best way to do it. In other words, if we have
$f->{$x}{$y}, I want something like</p>
<pre><code>foreach ($x, $y) (deep_keys %{$f})
{
}
</code></pre>
<p>instead of </p>
<pre><code>foreach $x (keys %f)
{
foreach $y (keys %{$f->{$x})
{
}
}
</code></pre>
|
[
{
"answer_id": 160210,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 1,
"selected": false,
"text": "\"$level1_key.$level2_key.$level3_key\""
},
{
"answer_id": 160270,
"author": "Zan Lynx",
"author_id": 13422,
"author_profile": "https://Stackoverflow.com/users/13422",
"pm_score": 2,
"selected": false,
"text": "sub f($) {\n my $x = shift;\n if( ref $x eq 'HASH' ) {\n foreach( values %$x ) {\n f($_);\n }\n } elsif( ref $x eq 'ARRAY' ) {\n foreach( @$x ) {\n f($_);\n }\n }\n}\n"
},
{
"answer_id": 160321,
"author": "bmdhacks",
"author_id": 14032,
"author_profile": "https://Stackoverflow.com/users/14032",
"pm_score": 5,
"selected": true,
"text": "sub deep_keys_foreach\n{\n my ($hashref, $code, $args) = @_;\n\n while (my ($k, $v) = each(%$hashref)) {\n my @newargs = defined($args) ? @$args : ();\n push(@newargs, $k);\n if (ref($v) eq 'HASH') {\n deep_keys_foreach($v, $code, \\@newargs);\n }\n else {\n $code->(@newargs);\n }\n }\n}\n\ndeep_keys_foreach($f, sub {\n my ($k1, $k2) = @_;\n print \"inside deep_keys, k1=$k1, k2=$k2\\n\";\n});\n"
},
{
"answer_id": 160513,
"author": "Michael Carman",
"author_id": 8233,
"author_profile": "https://Stackoverflow.com/users/8233",
"pm_score": 1,
"selected": false,
"text": "foreach"
},
{
"answer_id": 160886,
"author": "Greg Cottman",
"author_id": 10496,
"author_profile": "https://Stackoverflow.com/users/10496",
"pm_score": 2,
"selected": false,
"text": "$arr{\"foo\",1} = \"one\";\n$arr{\"bar\",2} = \"two\";\n\nwhile(($key, $value) = each(%arr))\n{\n @keyValues = split($;, $key);\n print \"key = [\", join(\",\", @keyValues), \"] : value = [\", $value, \"]\\n\";\n}\n"
},
{
"answer_id": 161370,
"author": "Penfold",
"author_id": 11952,
"author_profile": "https://Stackoverflow.com/users/11952",
"pm_score": 4,
"selected": false,
"text": "use Data::Walk;\n\nmy $data = { # some complex hash/array mess };\n\nsub process {\n print \"current node $_\\n\";\n}\n\nwalk \\&process, $data;\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14167/"
] |
160,204
|
<p>I'm a Linux guy and I'm used to copying directory trees with <code>cp -a</code>. OS X doesn't have <code>-a</code> option on <code>cp</code>... but it does have the <code>ditto</code> command. I'm reading the man on <code>ditto</code> now, but is there anything I should specifically be looking out for?</p>
|
[
{
"answer_id": 160242,
"author": "wprl",
"author_id": 17847,
"author_profile": "https://Stackoverflow.com/users/17847",
"pm_score": 0,
"selected": false,
"text": "cp -pR"
},
{
"answer_id": 160260,
"author": "joelhardi",
"author_id": 11438,
"author_profile": "https://Stackoverflow.com/users/11438",
"pm_score": 2,
"selected": false,
"text": "rsync -a"
},
{
"answer_id": 160268,
"author": "Simurr",
"author_id": 3478,
"author_profile": "https://Stackoverflow.com/users/3478",
"pm_score": 4,
"selected": true,
"text": "-p = preserve mode,ownership,timestamps\n-R = recursive\n-d = no dereference and preserve links\n"
},
{
"answer_id": 18368741,
"author": "Liyan Chang",
"author_id": 664345,
"author_profile": "https://Stackoverflow.com/users/664345",
"pm_score": 2,
"selected": false,
"text": "cp -a"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2601671/"
] |
160,214
|
<p>I am trying to get the value of some ListViewSubItems, but I have no idea what values it uses for its keys. I have some simple code:</p>
<pre><code> protected override void OnItemDrag(ItemDragEventArgs e)
{
base.OnItemDrag(e);
ListViewItem item = e.Item as ListViewItem;
string val = item.SubItems[???].ToString();
}
</code></pre>
<p>The ??? part is where I am having a problem. I cannot figure out what the keys are. I have tried the column names of the ListView with no luck. I would like to use this method instead of using numeric indices. </p>
|
[
{
"answer_id": 160235,
"author": "dguaraglia",
"author_id": 2384,
"author_profile": "https://Stackoverflow.com/users/2384",
"pm_score": 0,
"selected": false,
"text": "protected override void OnItemDrag(ItemDragEventArgs e)\n{\n base.OnItemDrag(e); \n ListViewItem item = e.Item as ListViewItem;\n string val = item.SubItems[0].ToString(); \n}\n"
},
{
"answer_id": 160344,
"author": "Matt Nelson",
"author_id": 788,
"author_profile": "https://Stackoverflow.com/users/788",
"pm_score": 2,
"selected": true,
"text": "ListViewSubItem"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1053/"
] |
160,216
|
<p>I'd like something like this:</p>
<pre><code>each[i_, {1,2,3},
Print[i]
]
</code></pre>
<p>Or, more generally, to destructure arbitrary stuff in the list you're looping over, like:</p>
<pre><code>each[{i_, j_}, {{1,10}, {2,20}, {3,30}},
Print[i*j]
]
</code></pre>
<p>Usually you want to use <code>Map</code> or other purely functional constructs and eschew a non-functional programming style where you use side effects. But here's an example where I think a for-each construct is supremely useful: </p>
<p>Say I have a list of options (rules) that pair symbols with expressions, like</p>
<pre><code>attrVals = {a -> 7, b -> 8, c -> 9}
</code></pre>
<p>Now I want to make a hash table where I do the obvious mapping of those symbols to those numbers. I don't think there's a cleaner way to do that than</p>
<pre><code>each[a_ -> v_, attrVals, h[a] = v]
</code></pre>
<h2>Additional test cases</h2>
<p>In this example, we transform a list of variables:</p>
<pre><code>a = 1;
b = 2;
c = 3;
each[i_, {a,b,c}, i = f[i]]
</code></pre>
<p>After the above, <code>{a,b,c}</code> should evaluate to <code>{f[1],f[2],f[3]}</code>. Note that that means the second argument to <code>each</code> should be held unevaluated if it's a list.</p>
<p>If the unevaluated form is not a list, it should evaluate the second argument. For example:</p>
<pre><code>each[i_, Rest[{a,b,c}], Print[i]]
</code></pre>
<p>That should print the values of <code>b</code> and <code>c</code>.</p>
<p><strong>Addendum</strong>: To do for-each properly, it should support <code>Break[]</code> and <code>Continue[]</code>. I'm not sure how to implement that. Perhaps it will need to somehow be implemented in terms of For, While, or Do since those are the only loop constructs that support <code>Break[]</code> and <code>Continue[]</code>.</p>
<p>And another problem with the answers so far: they eat <code>Return[]</code>s. That is, if you are using a ForEach loop in a function and want to return from the function from within the loop, you can't. Issuing Return inside the ForEach loop seems to work like <code>Continue[]</code>. This just (wait for it) threw me for a loop.</p>
|
[
{
"answer_id": 160219,
"author": "dreeves",
"author_id": 4234,
"author_profile": "https://Stackoverflow.com/users/4234",
"pm_score": 3,
"selected": false,
"text": "Scan"
},
{
"answer_id": 1260797,
"author": "Pillsy",
"author_id": 85467,
"author_profile": "https://Stackoverflow.com/users/85467",
"pm_score": 3,
"selected": false,
"text": "Do[\n Print[i],\n {i, {1, 2, 3}}]\n"
},
{
"answer_id": 1323505,
"author": "Per Alexandersson",
"author_id": 152109,
"author_profile": "https://Stackoverflow.com/users/152109",
"pm_score": 1,
"selected": false,
"text": "Func"
},
{
"answer_id": 2390686,
"author": "Michael Pilat",
"author_id": 272923,
"author_profile": "https://Stackoverflow.com/users/272923",
"pm_score": 4,
"selected": false,
"text": "ForEach[i_, {1,2,3},\n Print[i]\n]\n"
},
{
"answer_id": 4700704,
"author": "dreeves",
"author_id": 4234,
"author_profile": "https://Stackoverflow.com/users/4234",
"pm_score": 2,
"selected": true,
"text": "SetAttributes[each, HoldAll]; (* each[pattern, list, body] *)\neach[pat_, lst_List, bod_] := (* converts pattern to body for *)\n (Cases[Unevaluated@lst, pat:>bod]; Null); (* each element of list. *)\neach[p_, l_, b_] := (Cases[l, p:>b]; Null); (* (Break/Continue not supported) *)\n"
},
{
"answer_id": 7259824,
"author": "faysou",
"author_id": 884752,
"author_profile": "https://Stackoverflow.com/users/884752",
"pm_score": 2,
"selected": false,
"text": "SetAttributes[ForEach,HoldAll];\nForEach[patt_/; FreeQ[patt, Pattern],list_,expr_,level_:1] :=\n Module[{pattWithBlanks,pattern},\n pattWithBlanks = patt/.(x_Symbol/;!MemberQ[{\"System`\"},Context[x]] :> pattern[x,Blank[]]);\n pattWithBlanks = pattWithBlanks/.pattern->Pattern;\n\n Cases[Unevaluated@list, pattWithBlanks :> expr, {level}];\n Null\n ];\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4234/"
] |
160,218
|
<p>I'm personally an advocate of the <a href="https://en.wikipedia.org/wiki/%3F:" rel="nofollow noreferrer">ternary operator</a>: <code>() ? : </code></p>
<p>I do realize that it has its place, but I have come across many programmers that are completely against ever using it, and some that use it too often.</p>
<p>What are your feelings on it? What interesting code have you seen using it?</p>
|
[
{
"answer_id": 160231,
"author": "Erik Forbes",
"author_id": 16942,
"author_profile": "https://Stackoverflow.com/users/16942",
"pm_score": 3,
"selected": false,
"text": "var e = new XElement(\"Something\",\n param == null ? new XElement(\"Value\", \"Default\")\n : new XElement(\"Value\", param.ToString())\n);\n"
},
{
"answer_id": 160240,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 3,
"selected": false,
"text": "if"
},
{
"answer_id": 160253,
"author": "PierreBdR",
"author_id": 7136,
"author_profile": "https://Stackoverflow.com/users/7136",
"pm_score": 3,
"selected": false,
"text": "return (a>0)?a:0;\n"
},
{
"answer_id": 160275,
"author": "Keith Williams",
"author_id": 20376,
"author_profile": "https://Stackoverflow.com/users/20376",
"pm_score": 5,
"selected": false,
"text": "foo = (bar > baz) ? true : false"
},
{
"answer_id": 160280,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 2,
"selected": false,
"text": "String name = firstName;\n\nif (middleName != null) {\n name += \" \" + middleName;\n}\n\nname += \" \" + lastName;\n"
},
{
"answer_id": 160291,
"author": "indiv",
"author_id": 19719,
"author_profile": "https://Stackoverflow.com/users/19719",
"pm_score": 2,
"selected": false,
"text": "int result = do_something();\nif( result != 0 )\n{\n debug_printf(\"Error while doing something, code %x (%s)\\n\", result,\n result == 7 ? \"ERROR_YES\" :\n result == 8 ? \"ERROR_NO\" :\n result == 9 ? \"ERROR_FILE_NOT_FOUND\" :\n \"Unknown\");\n}\n"
},
{
"answer_id": 160293,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": -1,
"selected": false,
"text": "$y = ($x == \"a\" ? \"apple\"\n : ($x == \"b\" ? \"banana\"\n : ($x == \"c\" ? \"carrot\"\n : \"default\")));\n"
},
{
"answer_id": 160295,
"author": "marcospereira",
"author_id": 4600,
"author_profile": "https://Stackoverflow.com/users/4600",
"pm_score": 9,
"selected": true,
"text": "int a = (b > 10) ? c : d;\n"
},
{
"answer_id": 160337,
"author": "pilsetnieks",
"author_id": 6615,
"author_profile": "https://Stackoverflow.com/users/6615",
"pm_score": 2,
"selected": false,
"text": "var Result = [CaseIfFalse, CaseIfTrue][(boolean expression)]\n"
},
{
"answer_id": 160415,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "$var = (simple > test ? simple_result_1 : simple_result_2);\n"
},
{
"answer_id": 160460,
"author": "Ryan Delucchi",
"author_id": 9931,
"author_profile": "https://Stackoverflow.com/users/9931",
"pm_score": 5,
"selected": false,
"text": "?:"
},
{
"answer_id": 160492,
"author": "Don Neufeld",
"author_id": 13097,
"author_profile": "https://Stackoverflow.com/users/13097",
"pm_score": 0,
"selected": false,
"text": "int getSomething()\n{\n return m_t ? m_t->v : 0;\n}\n"
},
{
"answer_id": 160744,
"author": "KPexEA",
"author_id": 13676,
"author_profile": "https://Stackoverflow.com/users/13676",
"pm_score": 2,
"selected": false,
"text": "before:\n\nif(isheader)\n drawtext(x, y, WHITE, string);\nelse\n drawtext(x, y, BLUE, string);\n\nafter:\n\n drawtext(x, y, isheader == true ? WHITE : BLUE, string);\n"
},
{
"answer_id": 160887,
"author": "rampion",
"author_id": 9859,
"author_profile": "https://Stackoverflow.com/users/9859",
"pm_score": 6,
"selected": false,
"text": "x = (y < 100) ? \"dog\" :\n (y < 150) ? \"cat\" :\n (y < 300) ? \"bar\" : \"baz\";\n"
},
{
"answer_id": 161172,
"author": "mar10",
"author_id": 19166,
"author_profile": "https://Stackoverflow.com/users/19166",
"pm_score": 0,
"selected": false,
"text": "int i;\nif( piVal ) {\n i = *piVal;\n} else {\n i = *piDefVal;\n}\n"
},
{
"answer_id": 162525,
"author": "Steve Losh",
"author_id": 13498,
"author_profile": "https://Stackoverflow.com/users/13498",
"pm_score": 2,
"selected": false,
"text": "expr ?: default\n"
},
{
"answer_id": 168412,
"author": "Ricardo Villamil",
"author_id": 19314,
"author_profile": "https://Stackoverflow.com/users/19314",
"pm_score": 0,
"selected": false,
"text": "int x = something == somethingElse ? 0 : -1;\n"
},
{
"answer_id": 422478,
"author": "Julien Chastang",
"author_id": 32174,
"author_profile": "https://Stackoverflow.com/users/32174",
"pm_score": 0,
"selected": false,
"text": " int[] iArr = {1, 2, 3};\n StringBuilder sb = new StringBuilder();\n for (int i = 0; i < iArr.length; i++) {\n sb.append(i == 0 ? iArr[i] : \", \" + iArr[i]);\n }\n System.out.println(sb.toString());\n"
},
{
"answer_id": 535096,
"author": "Ian P",
"author_id": 10853,
"author_profile": "https://Stackoverflow.com/users/10853",
"pm_score": 6,
"selected": false,
"text": "int count = (condition) ? 1 : 0;\n"
},
{
"answer_id": 535106,
"author": "joel.neely",
"author_id": 3525,
"author_profile": "https://Stackoverflow.com/users/3525",
"pm_score": 0,
"selected": false,
"text": "int c = a < b ? a : b;\n"
},
{
"answer_id": 535107,
"author": "Sean Bright",
"author_id": 21926,
"author_profile": "https://Stackoverflow.com/users/21926",
"pm_score": 4,
"selected": false,
"text": "return x ? \"Yes\" : \"No\";\n"
},
{
"answer_id": 535124,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 3,
"selected": false,
"text": "isLeapYear =\n ((yyyy % 400) == 0)\n ? 1\n : ((yyyy % 100) == 0)\n ? 0\n : ((yyyy % 4) == 0)\n ? 1\n : 0;\n"
},
{
"answer_id": 535142,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": false,
"text": "if"
},
{
"answer_id": 535191,
"author": "Onion-Knight",
"author_id": 64708,
"author_profile": "https://Stackoverflow.com/users/64708",
"pm_score": 0,
"selected": false,
"text": " __CRT_INLINE int __cdecl getchar (void)\n{\n return (--stdin->_cnt >= 0)\n ? (int) (unsigned char) *stdin->_ptr++\n : _filbuf (stdin);\n}\n"
},
{
"answer_id": 535195,
"author": "maccullt",
"author_id": 4945,
"author_profile": "https://Stackoverflow.com/users/4945",
"pm_score": 2,
"selected": false,
"text": "int repCount = pRepCountIn ? *pRepCountIn : defaultRepCount;\n"
},
{
"answer_id": 535231,
"author": "staticsan",
"author_id": 28832,
"author_profile": "https://Stackoverflow.com/users/28832",
"pm_score": 2,
"selected": false,
"text": "if"
},
{
"answer_id": 535490,
"author": "Adam Hawes",
"author_id": 54415,
"author_profile": "https://Stackoverflow.com/users/54415",
"pm_score": 0,
"selected": false,
"text": "char* c = NULL;\nif(x) {\n c = \"true\";\n}else {\n c = \"false\";\n}\n"
},
{
"answer_id": 1697086,
"author": "dsimcha",
"author_id": 23903,
"author_profile": "https://Stackoverflow.com/users/23903",
"pm_score": 0,
"selected": false,
"text": "auto myVariable = fun();\n// typeof(myVariable) == Foo!(Bar, Baz, Waldo!(Stuff, OtherStuff)).\n\n// Now I want to declare a variable and assign a value depending on some\n// conditional to it.\nauto myOtherVariable = (someCondition) ? fun() : gun();\n\n// If I didn't use the ternary I'd have to do:\nFoo!(Bar, Baz, Waldo!(Stuff, OtherStuff)) myLastVariable; // Ugly.\nif(someCondition) {\n myLastVariable = fun();\n} else {\n myLastVariable = gun():\n}\n"
},
{
"answer_id": 2389733,
"author": "Tim",
"author_id": 280564,
"author_profile": "https://Stackoverflow.com/users/280564",
"pm_score": 0,
"selected": false,
"text": " (active == null ? true :\n ((bool)active ? p.active : !p.active)) &&...\n"
},
{
"answer_id": 2389942,
"author": "bta",
"author_id": 79566,
"author_profile": "https://Stackoverflow.com/users/79566",
"pm_score": 0,
"selected": false,
"text": "int direction = read_or_write(io_command);\n\n// Send an I/O\nio_command.size = (direction==WRITE) ? (32 * 1024) : (128 * 1024);\nio_command.data = &buffer;\ndispatch_request(io_command);\n"
},
{
"answer_id": 2473019,
"author": "jeremysawesome",
"author_id": 296889,
"author_profile": "https://Stackoverflow.com/users/296889",
"pm_score": 1,
"selected": false,
"text": "$isLeapYear =\n (($year % 400) == 0)\n ? 1\n : ((($year % 100) == 0)\n ? 0\n : ((($year % 4) == 0)\n ? 1\n : 0));\n"
},
{
"answer_id": 3946860,
"author": "John John",
"author_id": 477577,
"author_profile": "https://Stackoverflow.com/users/477577",
"pm_score": 3,
"selected": false,
"text": "#define IF(x) x ?\n#define ELSE :\n"
},
{
"answer_id": 5275297,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 1,
"selected": false,
"text": "if( object.testSomeCondition()) {\n System.exec( \"format c:\" );\n}\nelse {\n a++;\n}\n"
},
{
"answer_id": 5509999,
"author": "SoSo",
"author_id": 667105,
"author_profile": "https://Stackoverflow.com/users/667105",
"pm_score": 0,
"selected": false,
"text": "($var)?1:0;\n"
},
{
"answer_id": 5970245,
"author": "gion_13",
"author_id": 491075,
"author_profile": "https://Stackoverflow.com/users/491075",
"pm_score": 1,
"selected": false,
"text": "var status = statuses[error == null ? 'working' : 'stopped'];\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21804/"
] |
160,222
|
<p>I have a simple web form that has a several fields and a gridview on it. I also have a save and cancel button. </p>
<p>I would like a way to undo what was done to the data on the form when the user presses cancel. This is simple enough with the fields however since changes to the gridview happen in real time against the database I do not know how to get undo functionality.</p>
<p>I have thought of storing the changes to gridview in viewstate but I would rather not because of the extra space requirement. </p>
<p>I have also thought of a temporary table that would stored the changes then roll them back as needed.</p>
<p>Does anyone have an idea how to get undo functionality from the form?</p>
|
[
{
"answer_id": 160285,
"author": "Keith Williams",
"author_id": 20376,
"author_profile": "https://Stackoverflow.com/users/20376",
"pm_score": 0,
"selected": false,
"text": "(MyObject)Session[\"MyObject\"]"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22264/"
] |
160,233
|
<p>I tried this in mysql:</p>
<pre><code>mysql> alter table region drop column country_id;
</code></pre>
<p>And got this:</p>
<pre><code>ERROR 1025 (HY000): Error on rename of './product/#sql-14ae_81' to
'./product/region' (errno: 150)
</code></pre>
<p>Any ideas? Foreign key stuff?</p>
|
[
{
"answer_id": 179501,
"author": "Harrison Fisk",
"author_id": 16111,
"author_profile": "https://Stackoverflow.com/users/16111",
"pm_score": 7,
"selected": false,
"text": "shell$ perror 150\nMySQL error code 150: Foreign key constraint is incorrectly formed\n"
},
{
"answer_id": 1605819,
"author": "Jeroen",
"author_id": 194409,
"author_profile": "https://Stackoverflow.com/users/194409",
"pm_score": 4,
"selected": false,
"text": "SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;\nSET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;\nSET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';\n"
},
{
"answer_id": 5615783,
"author": "Jeshurun",
"author_id": 473637,
"author_profile": "https://Stackoverflow.com/users/473637",
"pm_score": 9,
"selected": true,
"text": "region_ibfk_1"
},
{
"answer_id": 14223419,
"author": "iltaf khalid",
"author_id": 1209409,
"author_profile": "https://Stackoverflow.com/users/1209409",
"pm_score": 1,
"selected": false,
"text": "alter table table_name drop foreign_key_col_name;\n"
},
{
"answer_id": 14997309,
"author": "Muhammad Sohail",
"author_id": 1006905,
"author_profile": "https://Stackoverflow.com/users/1006905",
"pm_score": 3,
"selected": false,
"text": "ALTER TABLE slide_image_sub DROP KEY FK_slide_image_sub;\n"
},
{
"answer_id": 34722679,
"author": "youngdero",
"author_id": 5543469,
"author_profile": "https://Stackoverflow.com/users/5543469",
"pm_score": 1,
"selected": false,
"text": "SHOW ENGINE INNODB"
},
{
"answer_id": 41543786,
"author": "Baccata",
"author_id": 5627467,
"author_profile": "https://Stackoverflow.com/users/5627467",
"pm_score": 2,
"selected": false,
"text": "SET FOREIGN_KEY_CHECKS = 0;\n"
},
{
"answer_id": 41652252,
"author": "Jan Tchärmän",
"author_id": 3018891,
"author_profile": "https://Stackoverflow.com/users/3018891",
"pm_score": 0,
"selected": false,
"text": "SET FOREIGN_KEY_CHECKS=0;\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2601671/"
] |
160,245
|
<p>I'm trying:</p>
<pre><code>import commands
print commands.getoutput("ps -u 0")
</code></pre>
<p>But it doesn't work on os x.
os instead of commands gives the same output:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND</p>
<p>nothing more</p>
|
[
{
"answer_id": 160271,
"author": "jmissao",
"author_id": 20883,
"author_profile": "https://Stackoverflow.com/users/20883",
"pm_score": 0,
"selected": false,
"text": "import os\nprint os.system(\"ps -u 0\")\n"
},
{
"answer_id": 160284,
"author": "Thomas Wouters",
"author_id": 17624,
"author_profile": "https://Stackoverflow.com/users/17624",
"pm_score": 3,
"selected": false,
"text": "commands"
},
{
"answer_id": 160316,
"author": "Dana",
"author_id": 7856,
"author_profile": "https://Stackoverflow.com/users/7856",
"pm_score": 1,
"selected": false,
"text": "print commands.getoutput(\"ps -u 0\")\n\nUID PID TTY TIME CMD\n0 1 ?? 0:01.62 /sbin/launchd\n0 10 ?? 0:00.57 /usr/libexec/kextd\n"
},
{
"answer_id": 160375,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 4,
"selected": true,
"text": "import subprocess\nps = subprocess.Popen(\"ps -U 0\", shell=True, stdout=subprocess.PIPE)\nprint ps.stdout.read()\nps.stdout.close()\nps.wait()\n"
},
{
"answer_id": 6265416,
"author": "Giampaolo Rodolà",
"author_id": 376587,
"author_profile": "https://Stackoverflow.com/users/376587",
"pm_score": 3,
"selected": false,
"text": ">>> import os\n>>> pids = [int(x) for x in os.listdir('/proc') if x.isdigit()]\n>>> pids\n[1, 2, 3, 6, 7, 9, 11, 12, 13, 15, ... 9406, 9414, 9428, 9444]\n>>>\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7883/"
] |
160,250
|
<p>Just that, if you embed an icon:</p>
<pre><code>[Embed(source='icons/checkmark.png')]
private static var CheckMark:Class;
</code></pre>
<p>You end up with a dynamic class. You can pretty easily assign the icon to a button at runtime by calling the setStyle method:</p>
<pre><code>var btn:Button = new Button();
btn.setStyle("icon", CheckMark);
</code></pre>
<p>But what if you wanted to alter the icon at runtime, like changing it's alpha value or even redrawing pixels, before assigning it to the button?</p>
<p>So far I can't find a satisfactory answer...</p>
|
[
{
"answer_id": 163586,
"author": "Aaron",
"author_id": 23965,
"author_profile": "https://Stackoverflow.com/users/23965",
"pm_score": 0,
"selected": false,
"text": "button.setStyle(\"customIconAlpha\", .4);\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16258/"
] |
160,290
|
<p>After I call <code>getpwuid(uid)</code>, I have a reference to a pointer. Should I free that pointer when I don't use it anymore? Reading the man pages, it says that it makes reference to some static area, that may be overwritten by subsequent calls to the same functions, so I'm not sure if I should touch that memory area.</p>
<p>Thanks.</p>
|
[
{
"answer_id": 162233,
"author": "Steve Baker",
"author_id": 13566,
"author_profile": "https://Stackoverflow.com/users/13566",
"pm_score": 3,
"selected": false,
"text": "*_r"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11384/"
] |
160,292
|
<p>I'm writing a library which is to be dynamically loaded in C++. </p>
<p>I'd like to read argc and argv (for debugging reasons) from within my code, however I do not have access to the main function. Is there any way to retrieve the command line (both Windows and Linux solution would be nice).</p>
<p>Thanks,
Dan</p>
|
[
{
"answer_id": 160632,
"author": "Shadow2531",
"author_id": 1697,
"author_profile": "https://Stackoverflow.com/users/1697",
"pm_score": 1,
"selected": false,
"text": "\n#include <windows.h>\n#include <string>\n#include <vector>\n#include <cwchar>\n#include <cstdio>\n#include <clocale>\nusing namespace std;\n\nvector<wstring> getArgs() {\n int argc;\n wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc);\n vector<wstring> args;\n if (argv) {\n args.assign(argv, argv + argc);\n LocalFree(argv);\n }\n return args;\n}\n\nint main() {\n const vector<wstring> argv = getArgs();\n setlocale(LC_CTYPE, \".OCP\");\n for (vector<wstring>::const_iterator i = argv.begin(); i != argv.end(); ++i) {\n wprintf(L\"%s\\n\", i->c_str());\n }\n}\n"
},
{
"answer_id": 13981773,
"author": "serbaut",
"author_id": 84760,
"author_profile": "https://Stackoverflow.com/users/84760",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include <unistd.h>\n\nvoid findargs(int *argc, char ***argv) {\n size_t i;\n char **p = &__environ[-2];\n for (i = 1; i != *(size_t*)(p-1); i++) {\n p--;\n }\n *argc = (int)i;\n *argv = p;\n}\n\nint main(int argc, char **argv) {\n printf(\"got argc=%d, argv=%p\\n\", argc, argv);\n findargs(&argc, &argv);\n printf(\"found argc=%d, argv=%p\\n\", argc, argv);\n return 0;\n}\n"
}
] |
2008/10/01
|
[
"https://Stackoverflow.com/questions/160292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4697/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.