qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
307,502 | <p>When you run <code>top</code> and see all running processes, I've always wanted to know just what everything actually means. e.g. all the various single-letter state codes for a running process (R = Running, S = Sleeping, etc...)</p>
<p>Where can I find this?</p>
| [
{
"answer_id": 307506,
"author": "SMB",
"author_id": 26029,
"author_profile": "https://Stackoverflow.com/users/26029",
"pm_score": 4,
"selected": false,
"text": "man top"
},
{
"answer_id": 307529,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 8,
"selected": true,
"text": "top"
},
{
"answer_id": 64705975,
"author": "congusbongus",
"author_id": 2038264,
"author_profile": "https://Stackoverflow.com/users/2038264",
"pm_score": 3,
"selected": false,
"text": "top"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307502",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39529/"
] |
307,503 | <p>I've got a few Unix shell scripts where I need to check that certain environment variables are set before I start doing stuff, so I do this sort of thing:</p>
<pre><code>if [ -z "$STATE" ]; then
echo "Need to set STATE"
exit 1
fi
if [ -z "$DEST" ]; then
echo "Need to set DEST"
exit 1
fi
</code></pre>
<p>which is a lot of typing. Is there a more elegant idiom for checking that a set of environment variables is set?</p>
<p>EDIT: I should mention that these variables have no meaningful default value - the script should error out if any are unset.</p>
| [
{
"answer_id": 307527,
"author": "Vincent Van Den Berghe",
"author_id": 39259,
"author_profile": "https://Stackoverflow.com/users/39259",
"pm_score": 5,
"selected": false,
"text": "${MyVariable:=SomeDefault}\n"
},
{
"answer_id": 307540,
"author": "David Schlosnagle",
"author_id": 1750,
"author_profile": "https://Stackoverflow.com/users/1750",
"pm_score": 7,
"selected": false,
"text": "[ -z \"$STATE\" ] && echo \"Need to set STATE\" && exit 1;\n"
},
{
"answer_id": 307571,
"author": "Rob Wells",
"author_id": 2974,
"author_profile": "https://Stackoverflow.com/users/2974",
"pm_score": 6,
"selected": false,
"text": "${MyVariable:=SomeDefault}\n"
},
{
"answer_id": 307635,
"author": "Mr.Ree",
"author_id": 37946,
"author_profile": "https://Stackoverflow.com/users/37946",
"pm_score": 4,
"selected": false,
"text": "if [ \"x$STATE\" == \"x\" ]; then echo \"Need to set State\"; exit 1; fi\n"
},
{
"answer_id": 307735,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 10,
"selected": true,
"text": ": ${STATE?\"Need to set STATE\"}\n: ${DEST:?\"Need to set DEST non-empty\"}\n"
},
{
"answer_id": 434253,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "if (set -u; : $HOME) 2> /dev/null\n...\n...\n"
},
{
"answer_id": 2832155,
"author": "Graeme",
"author_id": 278461,
"author_profile": "https://Stackoverflow.com/users/278461",
"pm_score": -1,
"selected": false,
"text": "$?"
},
{
"answer_id": 7904901,
"author": "Paul Makkar",
"author_id": 1014848,
"author_profile": "https://Stackoverflow.com/users/1014848",
"pm_score": 6,
"selected": false,
"text": "-u"
},
{
"answer_id": 26317390,
"author": "Adriano",
"author_id": 262650,
"author_profile": "https://Stackoverflow.com/users/262650",
"pm_score": 5,
"selected": false,
"text": "if [ \"$MYVAR\" = \"\" ]\nthen\n echo \"Does not exist\"\nelse\n echo \"Exists\"\nfi\n"
},
{
"answer_id": 39621322,
"author": "chepner",
"author_id": 1126841,
"author_profile": "https://Stackoverflow.com/users/1126841",
"pm_score": 4,
"selected": false,
"text": "bash"
},
{
"answer_id": 42697421,
"author": "Gudlaugur Egilsson",
"author_id": 969889,
"author_profile": "https://Stackoverflow.com/users/969889",
"pm_score": 2,
"selected": false,
"text": "mapfile -t arr < variables.txt\n\nEXITCODE=0\n\nfor i in \"${arr[@]}\"\ndo\n ISSET=$(env | grep ^${i}= | wc -l)\n if [ \"${ISSET}\" = \"0\" ];\n then\n EXITCODE=-1\n echo \"ENV variable $i is required.\"\n fi\ndone\n\nexit ${EXITCODE}\n"
},
{
"answer_id": 43992889,
"author": "codeforester",
"author_id": 6862601,
"author_profile": "https://Stackoverflow.com/users/6862601",
"pm_score": 2,
"selected": false,
"text": "#\n# assert if variables are set (to a non-empty string)\n# if any variable is not set, exit 1 (when -f option is set) or return 1 otherwise\n#\n# Usage: assert_var_not_null [-f] variable ...\n#\nfunction assert_var_not_null() {\n local fatal var num_null=0\n [[ \"$1\" = \"-f\" ]] && { shift; fatal=1; }\n for var in \"$@\"; do\n [[ -z \"${!var}\" ]] &&\n printf '%s\\n' \"Variable '$var' not set\" >&2 &&\n ((num_null++))\n done\n\n if ((num_null > 0)); then\n [[ \"$fatal\" ]] && exit 1\n return 1\n fi\n return 0\n}\n"
},
{
"answer_id": 44707000,
"author": "ichigolas",
"author_id": 1740079,
"author_profile": "https://Stackoverflow.com/users/1740079",
"pm_score": 3,
"selected": false,
"text": "#!/bin/bash\ndeclare -a vars=(NAME GITLAB_URL GITLAB_TOKEN)\n\nfor var_name in \"${vars[@]}\"\ndo\n if [ -z \"$(eval \"echo \\$$var_name\")\" ]; then\n echo \"Missing environment variable $var_name\"\n exit 1\n fi\ndone\n"
},
{
"answer_id": 46990007,
"author": "nafdef",
"author_id": 5817860,
"author_profile": "https://Stackoverflow.com/users/5817860",
"pm_score": -1,
"selected": false,
"text": "is_this_an_env_variable ()\n local var=\"$1\"\n if env |grep -q \"^$var\"; then\n return 0\n else\n return 1\n fi\n }\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2994/"
] |
307,512 | <pre><code>public static IQueryable<TResult> ApplySortFilter<T, TResult>(this IQueryable<T> query, string columnName)
where T : EntityObject
{
var param = Expression.Parameter(typeof(T), "o");
var body = Expression.PropertyOrField(param,columnName);
var sortExpression = Expression.Lambda(body, param);
return query.OrderBy(sortExpression);
}
</code></pre>
<p>Because the type for OrderBy is not inferred from sortExpression I need to specify it something like this at run time:</p>
<pre><code>var sortExpression = Expression.Lambda<T, TSortColumn>(body, param);
</code></pre>
<p>Or</p>
<pre><code>return query.OrderBy<T, TSortColumn>(sortExpression);
</code></pre>
<p>I don't think this is possible however as TSortColumn can only be determined during runtime.</p>
<p>Is there a way around this?</p>
| [
{
"answer_id": 307599,
"author": "JTew",
"author_id": 25372,
"author_profile": "https://Stackoverflow.com/users/25372",
"pm_score": 3,
"selected": false,
"text": "// ***** OrderBy(company => company) *****\n// Create an expression tree that represents the expression\n// 'whereCallExpression.OrderBy(company => company)'\nMethodCallExpression orderByCallExpression = Expression.Call(\n typeof(Queryable),\n \"OrderBy\",\n new Type[] { queryableData.ElementType, queryableData.ElementType },\n whereCallExpression,\n Expression.Lambda<Func<string, string>>(pe, new ParameterExpression[] { pe }));\n// ***** End OrderBy *****\n"
},
{
"answer_id": 307600,
"author": "Aaron Powell",
"author_id": 11388,
"author_profile": "https://Stackoverflow.com/users/11388",
"pm_score": 8,
"selected": true,
"text": "public static IQueryable<T> OrderBy<T>(this IQueryable<T> source, string ordering, params object[] values) {\n var type = typeof(T);\n var property = type.GetProperty(ordering);\n var parameter = Expression.Parameter(type, \"p\");\n var propertyAccess = Expression.MakeMemberAccess(parameter, property);\n var orderByExp = Expression.Lambda(propertyAccess, parameter);\n MethodCallExpression resultExp = Expression.Call(typeof(Queryable), \"OrderBy\", new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp));\n return source.Provider.CreateQuery<T>(resultExp);\n}\n"
},
{
"answer_id": 308863,
"author": "Davy Landman",
"author_id": 11098,
"author_profile": "https://Stackoverflow.com/users/11098",
"pm_score": 4,
"selected": false,
"text": "private static LambdaExpression GenerateSelector<TEntity>(String propertyName, out Type resultType) where TEntity : class\n{\n // Create a parameter to pass into the Lambda expression (Entity => Entity.OrderByField).\n var parameter = Expression.Parameter(typeof(TEntity), \"Entity\");\n // create the selector part, but support child properties\n PropertyInfo property;\n Expression propertyAccess;\n if (propertyName.Contains('.'))\n {\n // support to be sorted on child fields.\n String[] childProperties = propertyName.Split('.');\n property = typeof(TEntity).GetProperty(childProperties[0]);\n propertyAccess = Expression.MakeMemberAccess(parameter, property);\n for (int i = 1; i < childProperties.Length; i++)\n {\n property = property.PropertyType.GetProperty(childProperties[i]);\n propertyAccess = Expression.MakeMemberAccess(propertyAccess, property);\n }\n }\n else\n {\n property = typeof(TEntity).GetProperty(propertyName);\n propertyAccess = Expression.MakeMemberAccess(parameter, property);\n }\n resultType = property.PropertyType; \n // Create the order by expression.\n return Expression.Lambda(propertyAccess, parameter);\n}\n\nprivate static MethodCallExpression GenerateMethodCall<TEntity>(IQueryable<TEntity> source, string methodName, String fieldName) where TEntity : class\n{\n Type type = typeof(TEntity);\n Type selectorResultType;\n LambdaExpression selector = GenerateSelector<TEntity>(fieldName, out selectorResultType);\n MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName,\n new Type[] { type, selectorResultType },\n source.Expression, Expression.Quote(selector));\n return resultExp;\n}\n"
},
{
"answer_id": 853627,
"author": "Jeremy Coenen",
"author_id": 7798,
"author_profile": "https://Stackoverflow.com/users/7798",
"pm_score": 5,
"selected": false,
"text": "return query.OrderBy(\"StringColumnName\");\n"
},
{
"answer_id": 1670085,
"author": "Slobodan",
"author_id": 202074,
"author_profile": "https://Stackoverflow.com/users/202074",
"pm_score": 3,
"selected": false,
"text": "public static IQueryable<TEntity> OrderBy<TEntity>(this IQueryable<TEntity> source, string orderByValues) where TEntity : class\n{\n IQueryable<TEntity> returnValue = null;\n\n string orderPair = orderByValues.Trim().Split(',')[0];\n string command = orderPair.ToUpper().Contains(\"DESC\") ? \"OrderByDescending\" : \"OrderBy\";\n\n var type = typeof(TEntity);\n var parameter = Expression.Parameter(type, \"p\");\n\n string propertyName = (orderPair.Split(' ')[0]).Trim();\n\n System.Reflection.PropertyInfo property;\n MemberExpression propertyAccess;\n\n if (propertyName.Contains('.'))\n {\n // support to be sorted on child fields. \n String[] childProperties = propertyName.Split('.');\n property = typeof(TEntity).GetProperty(childProperties[0]);\n propertyAccess = Expression.MakeMemberAccess(parameter, property);\n\n for (int i = 1; i < childProperties.Length; i++)\n {\n Type t = property.PropertyType;\n if (!t.IsGenericType)\n {\n property = t.GetProperty(childProperties[i]);\n }\n else\n {\n property = t.GetGenericArguments().First().GetProperty(childProperties[i]);\n }\n\n propertyAccess = Expression.MakeMemberAccess(propertyAccess, property);\n }\n }\n else\n {\n property = type.GetProperty(propertyName);\n propertyAccess = Expression.MakeMemberAccess(parameter, property);\n }\n\n var orderByExpression = Expression.Lambda(propertyAccess, parameter);\n\n var resultExpression = Expression.Call(typeof(Queryable), command, new Type[] { type, property.PropertyType },\n\n source.Expression, Expression.Quote(orderByExpression));\n\n returnValue = source.Provider.CreateQuery<TEntity>(resultExpression);\n\n if (orderByValues.Trim().Split(',').Count() > 1)\n {\n // remove first item\n string newSearchForWords = orderByValues.ToString().Remove(0, orderByValues.ToString().IndexOf(',') + 1);\n return source.OrderBy(newSearchForWords);\n }\n\n return returnValue;\n}\n"
},
{
"answer_id": 42190974,
"author": "dush88c",
"author_id": 5097602,
"author_profile": "https://Stackoverflow.com/users/5097602",
"pm_score": 2,
"selected": false,
"text": "public IQueryable<TEntity> GetWithInclude(Expression<Func<TEntity, bool>> predicate,\n List<string> sortBy, int pageNo, int pageSize = 12, params string[] include)\n {\n try\n {\n var numberOfRecordsToSkip = pageNo * pageSize;\n var dynamic = DbSet.AsQueryable();\n\n foreach (var s in include)\n {\n dynamic.Include(s);\n }\n return dynamic.OrderBy(\"CreatedDate\").Skip(numberOfRecordsToSkip).Take(pageSize);\n\n\n }\n catch (Exception e)\n {\n throw new Exception(e.Message);\n }\n }\n"
},
{
"answer_id": 43783637,
"author": "SeroJah",
"author_id": 5852630,
"author_profile": "https://Stackoverflow.com/users/5852630",
"pm_score": 2,
"selected": false,
"text": "public static IQueryable<TEntity> OrderBy<TEntity>(this IQueryable<TEntity> source, string orderByValues) where TEntity : class\n{\n IQueryable<TEntity> returnValue = null;\n\n string[] orderPairs = orderByValues.Trim().Split(',');\n\n Expression resultExpression = source.Expression;\n\n string strAsc = \"OrderBy\";\n string strDesc = \"OrderByDescending\";\n\n foreach (string orderPair in orderPairs)\n {\n if (string.IsNullOrWhiteSpace(orderPair))\n continue;\n\n string[] orderPairArr = orderPair.Trim().Split(' ');\n\n string propertyName = orderPairArr[0].Trim();\n string orderNarrow = orderPairArr.Length > 1 ? orderPairArr[1].Trim() : string.Empty;\n\n string command = orderNarrow.ToUpper().Contains(\"DESC\") ? strDesc : strAsc;\n\n Type type = typeof(TEntity);\n ParameterExpression parameter = Expression.Parameter(type, \"p\");\n\n System.Reflection.PropertyInfo property;\n Expression propertyAccess;\n\n if (propertyName.Contains('.'))\n {\n // support to be sorted on child fields. \n String[] childProperties = propertyName.Split('.');\n property = typeof(TEntity).GetProperty(childProperties[0]);\n propertyAccess = Expression.MakeMemberAccess(parameter, property);\n\n for (int i = 1; i < childProperties.Length; i++)\n {\n Type t = property.PropertyType;\n if (!t.IsGenericType)\n {\n property = t.GetProperty(childProperties[i]);\n }\n else\n {\n property = t.GetGenericArguments().First().GetProperty(childProperties[i]);\n }\n\n propertyAccess = Expression.MakeMemberAccess(propertyAccess, property);\n }\n }\n else\n {\n property = type.GetProperty(propertyName);\n propertyAccess = Expression.MakeMemberAccess(parameter, property);\n }\n\n if (property.PropertyType == typeof(object))\n {\n propertyAccess = Expression.Call(propertyAccess, \"ToString\", null);\n }\n\n LambdaExpression orderByExpression = Expression.Lambda(propertyAccess, parameter);\n\n resultExpression = Expression.Call(typeof(Queryable), command, new Type[] { type, property.PropertyType == typeof(object) ? typeof(string) : property.PropertyType },\n resultExpression, Expression.Quote(orderByExpression));\n\n strAsc = \"ThenBy\";\n strDesc = \"ThenByDescending\";\n }\n\n returnValue = source.Provider.CreateQuery<TEntity>(resultExpression);\n\n return returnValue;\n}\n"
},
{
"answer_id": 52653848,
"author": "M Granja",
"author_id": 613438,
"author_profile": "https://Stackoverflow.com/users/613438",
"pm_score": 1,
"selected": false,
"text": "public static IQueryable<T> SortBy<T>(this IQueryable<T> source, \n String propertyName, \n WebControls.SortDirection direction)\n {\n if (source == null) throw new ArgumentNullException(\"source\");\n if (String.IsNullOrEmpty(propertyName)) return source;\n\n // Create a parameter to pass into the Lambda expression\n //(Entity => Entity.OrderByField).\n var parameter = Expression.Parameter(typeof(T), \"Entity\");\n\n // create the selector part, but support child properties (it works without . too)\n String[] childProperties = propertyName.Split('.');\n MemberExpression property = Expression.Property(parameter, childProperties[0]);\n for (int i = 1; i < childProperties.Length; i++)\n {\n property = Expression.Property(property, childProperties[i]);\n }\n\n LambdaExpression selector = Expression.Lambda(property, parameter);\n\n string methodName = (direction > 0) ? \"OrderByDescending\" : \"OrderBy\";\n\n MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName,\n new Type[] { source.ElementType, property.Type },\n source.Expression, Expression.Quote(selector));\n\n return source.Provider.CreateQuery<T>(resultExp);\n }\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25372/"
] |
307,514 | <p>Can you program/configure Visual Studio to produce custom intellisense for your own server controls.</p>
<p>eg can you get it to do this:</p>
<p><a href="http://www.yart.com.au/test/vs.gif" rel="nofollow noreferrer">alt text http://www.yart.com.au/test/vs.gif</a></p>
<p>for a tag of your own like:</p>
<pre><code><MyCompany:MyTag ...
</code></pre>
| [
{
"answer_id": 307585,
"author": "HectorMac",
"author_id": 1400,
"author_profile": "https://Stackoverflow.com/users/1400",
"pm_score": 3,
"selected": true,
"text": "[EditorBrowsableAttribute (EditorBrowsableState.Never)] \n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24696/"
] |
307,531 | <p>With code like the following, sometimes the child controls correctly finish their animation and sometimes they stop at random places in the middle. Why don't they work correctly?</p>
<pre><code>var t:Tween;
t = new Tween(child1,"x",Elastic.easeOut,0,100,2,true);
t = new Tween(child1,"y", Elastic.easeOut,0,100,2,true);
t = new Tween(child2,"x",Strong.easeOut,300,400,1,true);
t = new Tween(child2,"y", Strong.easeOut,300,400,1,true);
</code></pre>
| [
{
"answer_id": 307535,
"author": "Eric",
"author_id": 4540,
"author_profile": "https://Stackoverflow.com/users/4540",
"pm_score": 2,
"selected": false,
"text": "var t1:Tween = new Tween(child1,\"x\",Elastic.easeOut,0,100,2,true);\nvar t2:Tween = new Tween(child1,\"y\", Elastic.easeOut,0,100,2,true);\nvar t3:Tween = new Tween(child2,\"x\",Strong.easeOut,300,400,1,true);\nvar t4:Tween = new Tween(child2,\"y\", Strong.easeOut,300,400,1,true);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4540/"
] |
307,579 | <p>I've got two branches that are fully merged together.</p>
<p>However, after the merge is done, I realise that one file has been messed up by the merge (someone else did an auto-format, gah), and it would just be easier to change to the new version in the other branch, and then reinsert my one line change after bringing it over into my branch.</p>
<p>So what's the easiest way in Git to do this?</p>
| [
{
"answer_id": 307872,
"author": "madlep",
"author_id": 14160,
"author_profile": "https://Stackoverflow.com/users/14160",
"pm_score": 12,
"selected": true,
"text": "git checkout otherbranch myfile.txt\n"
},
{
"answer_id": 2392772,
"author": "RzR",
"author_id": 149841,
"author_profile": "https://Stackoverflow.com/users/149841",
"pm_score": 6,
"selected": false,
"text": " git diff --stat \"$branch\"\n git checkout --merge \"$branch\" \"$file\"\n git diff --stat \"$branch\"\n"
},
{
"answer_id": 7099164,
"author": "lkraav",
"author_id": 35946,
"author_profile": "https://Stackoverflow.com/users/35946",
"pm_score": 7,
"selected": false,
"text": "git show TREEISH:path/to/file > path/to/local/file\n"
},
{
"answer_id": 30687751,
"author": "6ft Dan",
"author_id": 1500195,
"author_profile": "https://Stackoverflow.com/users/1500195",
"pm_score": 4,
"selected": false,
"text": "git checkout other-branch app/**\n"
},
{
"answer_id": 44820377,
"author": "Mohideen bin Mohammed",
"author_id": 4453737,
"author_profile": "https://Stackoverflow.com/users/4453737",
"pm_score": 5,
"selected": false,
"text": "git checkout master"
},
{
"answer_id": 56045704,
"author": "user151841",
"author_id": 151841,
"author_profile": "https://Stackoverflow.com/users/151841",
"pm_score": 3,
"selected": false,
"text": "git add ..."
},
{
"answer_id": 60855504,
"author": "Mariusz Pawelski",
"author_id": 350384,
"author_profile": "https://Stackoverflow.com/users/350384",
"pm_score": 7,
"selected": false,
"text": "git restore"
},
{
"answer_id": 71859166,
"author": "Sławomir Lenart",
"author_id": 1416144,
"author_profile": "https://Stackoverflow.com/users/1416144",
"pm_score": 2,
"selected": false,
"text": "git diff <other-branch-name> -- <filename>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14160/"
] |
307,581 | <p>Relatively new to rails and trying to model a very simple family "tree" with a single Person model that has a name, gender, father_id and mother_id (2 parents). Below is basically what I want to do, but obviously I can't repeat the :children in a has_many (the first gets overwritten).</p>
<pre><code>class Person < ActiveRecord::Base
belongs_to :father, :class_name => 'Person'
belongs_to :mother, :class_name => 'Person'
has_many :children, :class_name => 'Person', :foreign_key => 'mother_id'
has_many :children, :class_name => 'Person', :foreign_key => 'father_id'
end
</code></pre>
<p>Is there a simple way to use has_many with 2 foreign keys, or maybe change the foreign key based on the object's gender? Or is there another/better way altogether?</p>
<p>Thanks!</p>
| [
{
"answer_id": 307660,
"author": "Gordon Wilson",
"author_id": 23071,
"author_profile": "https://Stackoverflow.com/users/23071",
"pm_score": 3,
"selected": false,
"text": "class Person < ActiveRecord::Base\n has_one :father, :class_name => 'Person', :foreign_key => 'father_id'\n has_one :mother, :class_name => 'Person', :foreign_key => 'mother_id'\n has_many :children, :class_name => 'Person'\nend\n"
},
{
"answer_id": 307724,
"author": "Kenzie",
"author_id": 13636,
"author_profile": "https://Stackoverflow.com/users/13636",
"pm_score": 7,
"selected": true,
"text": "class Person < ActiveRecord::Base\n belongs_to :father, :class_name => 'Person'\n belongs_to :mother, :class_name => 'Person'\n has_many :children_of_father, :class_name => 'Person', :foreign_key => 'father_id'\n has_many :children_of_mother, :class_name => 'Person', :foreign_key => 'mother_id'\n def children\n children_of_mother + children_of_father\n end\nend\n"
},
{
"answer_id": 2529570,
"author": "Zando",
"author_id": 178779,
"author_profile": "https://Stackoverflow.com/users/178779",
"pm_score": 3,
"selected": false,
"text": "class Person < ActiveRecord::Base\n\n def children\n Person.with_parent(id)\n end\n\n named_scope :with_parent, lambda{ |pid| \n\n { :conditions=>[\"father_id = ? or mother_id=?\", pid, pid]}\n }\n end\n"
},
{
"answer_id": 16449704,
"author": "squiter",
"author_id": 937506,
"author_profile": "https://Stackoverflow.com/users/937506",
"pm_score": 2,
"selected": false,
"text": "class Person < ActiveRecord::Base\n belongs_to :father, :class_name => 'Person'\n belongs_to :mother, :class_name => 'Person'\n has_many :children_of_father, :class_name => 'Person', :foreign_key => 'father_id'\n has_many :children_of_mother, :class_name => 'Person', :foreign_key => 'mother_id'\n\n scope :children_for, lambda {|father_id, mother_id| where('father_id = ? AND mother_id = ?', father_id, mother_id) }\nend\n"
},
{
"answer_id": 25342501,
"author": "stevenspiel",
"author_id": 1411004,
"author_profile": "https://Stackoverflow.com/users/1411004",
"pm_score": 4,
"selected": false,
"text": "Person#children"
},
{
"answer_id": 27440160,
"author": "Tom Locke",
"author_id": 790621,
"author_profile": "https://Stackoverflow.com/users/790621",
"pm_score": 2,
"selected": false,
"text": "gender"
},
{
"answer_id": 37688343,
"author": "Anthony Mangiavellano",
"author_id": 6437132,
"author_profile": "https://Stackoverflow.com/users/6437132",
"pm_score": 2,
"selected": false,
"text": "ActiveRecord::AssociationRelation"
},
{
"answer_id": 40428054,
"author": "sunsoft",
"author_id": 5678119,
"author_profile": "https://Stackoverflow.com/users/5678119",
"pm_score": 2,
"selected": false,
"text": "class Person < ActiveRecord::Base\n belongs_to :father, :class_name => 'Person'\n belongs_to :mother, :class_name => 'Person'\n has_many :children, ->(person) { unscope(where: :person_id).where(\"father_id = ? OR mother_id = ?\", person.id, person.id) }, class_name: 'Person'\nend\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307581",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13636/"
] |
307,582 | <p>I have code running in a loop and it's saving state based on the current time. Sometimes this can be just milliseconds apart, but for some reason it seems that DateTime.Now will always return values of at least 10 ms apart even if it's only 2 or 3 ms later. This presents a major problem since the state i'm saving depends on the time it was saved (e.g. recording something)</p>
<p>My test code that returns each value 10 ms apart:</p>
<pre><code>public static void Main()
{
var dt1 = DateTime.Now;
System.Threading.Thread.Sleep(2);
var dt2 = DateTime.Now;
// On my machine the values will be at least 10 ms apart
Console.WriteLine("First: {0}, Second: {1}", dt1.Millisecond, dt2.Millisecond);
}
</code></pre>
<p>Is there another solution on how to get the accurate current time up to the millisecond ?</p>
<p>Someone suggested to look at the Stopwatch class. Although the Stopwatch class is very accurate it does not tell me the current time, something i need in order to save the state of my program.</p>
| [
{
"answer_id": 4962857,
"author": "Roman Starkov",
"author_id": 33080,
"author_profile": "https://Stackoverflow.com/users/33080",
"pm_score": 5,
"selected": false,
"text": "Thread.Sleep(1)"
},
{
"answer_id": 28867997,
"author": "Hesein Burg",
"author_id": 4302185,
"author_profile": "https://Stackoverflow.com/users/4302185",
"pm_score": 0,
"selected": false,
"text": "int timer = 0;\n"
},
{
"answer_id": 35225971,
"author": "noontz",
"author_id": 2050637,
"author_profile": "https://Stackoverflow.com/users/2050637",
"pm_score": 0,
"selected": false,
"text": "static FileTime time; \n\npublic static DateTime Now()\n{\n GetSystemTimePreciseAsFileTime(out time);\n var newTime = (ulong)time.dwHighDateTime << (8 * 4) | time.dwLowDateTime;\n var newTimeSigned = Convert.ToInt64(newTime);\n return new DateTime(newTimeSigned).AddYears(1600).ToLocalTime();\n} \n\npublic struct FileTime\n{\n public uint dwLowDateTime;\n public uint dwHighDateTime;\n}\n\n[DllImport(\"Kernel32.dll\")]\npublic static extern void GetSystemTimePreciseAsFileTime(out FileTime lpSystemTimeAsFileTime);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,596 | <p>Does anyone know how to calculate time difference in C++ in milliseconds?
I used <a href="http://linux.die.net/man/3/difftime" rel="noreferrer"><code>difftime</code></a> but it doesn't have enough precision for what I'm trying to measure.</p>
| [
{
"answer_id": 307604,
"author": "SoapBox",
"author_id": 36384,
"author_profile": "https://Stackoverflow.com/users/36384",
"pm_score": 2,
"selected": false,
"text": "gettimeofday"
},
{
"answer_id": 307607,
"author": "Tyler McHenry",
"author_id": 39375,
"author_profile": "https://Stackoverflow.com/users/39375",
"pm_score": 5,
"selected": true,
"text": "#include <time.h>\n\nint diff_ms(timeval t1, timeval t2)\n{\n return (((t1.tv_sec - t2.tv_sec) * 1000000) + \n (t1.tv_usec - t2.tv_usec))/1000;\n}\n"
},
{
"answer_id": 307609,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 3,
"selected": false,
"text": "#include <time.h>\n\nint clo = clock();\n//do stuff\ncout << (clock() - clo) << endl;\n"
},
{
"answer_id": 307661,
"author": "Peter",
"author_id": 22517,
"author_profile": "https://Stackoverflow.com/users/22517",
"pm_score": 0,
"selected": false,
"text": "QueryPerformanceCounter()"
},
{
"answer_id": 471343,
"author": "Nuno",
"author_id": 15422,
"author_profile": "https://Stackoverflow.com/users/15422",
"pm_score": 3,
"selected": false,
"text": "UINT64 getTime()\n{\n SYSTEMTIME st;\n GetSystemTime(&st);\n\n FILETIME ft;\n SystemTimeToFileTime(&st, &ft); // converts to file time format\n ULARGE_INTEGER ui;\n ui.LowPart=ft.dwLowDateTime;\n ui.HighPart=ft.dwHighDateTime;\n\n return ui.QuadPart;\n}\n\nint _tmain(int argc, TCHAR* argv[], TCHAR* envp[])\n{\n //! Start counting time\n UINT64 start, finish;\n\n start=getTime();\n\n //do something...\n\n //! Stop counting elapsed time\n finish = getTime();\n\n //now you can calculate the difference any way that you want\n //in seconds:\n _tprintf(_T(\"Time elapsed executing this code: %.03f seconds.\"), (((float)(finish-start))/((float)10000))/1000 );\n //or in miliseconds\n _tprintf(_T(\"Time elapsed executing this code: %I64d seconds.\"), (finish-start)/10000 );\n}\n"
},
{
"answer_id": 4974588,
"author": "Howard Hinnant",
"author_id": 576911,
"author_profile": "https://Stackoverflow.com/users/576911",
"pm_score": 6,
"selected": false,
"text": "<chrono>"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23084/"
] |
307,610 | <p>I keep seeing people say that exceptions are slow, but I never see any proof. So, instead of asking if they are, I will ask how do exceptions work behind the scenes, so I can make decisions of when to use them and whether they are slow.</p>
<p>From what I know, exceptions are the same as doing a return bunch of times, except that it also checks after each return whether it needs to do another one or to stop. How does it check when to stop returning? I guess there is a second stack that holds the type of the exception and a stack location, it then does returns until it gets there. I am also guessing that the only time this second stack is touched is on a throw and on each try/catch. AFAICT implementing a similar behaviour with return codes would take the same amount of time. But this is all just a guess, so I want to know what really happens.</p>
<p>How do exceptions really work?</p>
| [
{
"answer_id": 307716,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 8,
"selected": true,
"text": "class MyException\n{\npublic:\n MyException() { }\n ~MyException() { }\n};\n\nvoid my_throwing_function(bool throwit)\n{\n if (throwit)\n throw MyException();\n}\n\nvoid another_function();\nvoid log(unsigned count);\n\nvoid my_catching_function()\n{\n log(0);\n try\n {\n log(1);\n another_function();\n log(2);\n }\n catch (const MyException& e)\n {\n log(3);\n }\n log(4);\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,619 | <p>My code works (yeah!) which sends json to a server.. would appreciate any thoughts on refactoring</p>
<p>1) My C# code sends this json to the server</p>
<p>{\"firstName\":\"Bill\",\"lastName\":\"Gates\",\"email\":\"asdf@hotmail.com\",\"deviceUUID\":\"abcdefghijklmnopqrstuvwxyz\"}</p>
<p>Which I have to get rid of the slashes on the server side....not good.</p>
<p>2) I'm using application/x-www-form-urlencoded and probably want to be using application/json</p>
<pre><code>Person p = new Person();
p.firstName = "Bill";
p.lastName = "Gates";
p.email = "asdf@hotmail.com";
p.deviceUUID = "abcdefghijklmnopqrstuvwxyz";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUri + "newuser.php");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
//TODO request.ContentType = "application/json";
JavaScriptSerializer serializer = new JavaScriptSerializer();
string s = serializer.Serialize(p);
textBox3.Text = s;
string postData = "json=" + HttpUtility.UrlEncode(s);
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close ();
WebResponse response = request.GetResponse();
//textBox4.Text = (((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream ();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd ();
textBox4.Text += responseFromServer;
reader.Close ();
dataStream.Close ();
response.Close ();
</code></pre>
<p>PHP Code on Server:</p>
<pre><code>$inbound = $_POST['json'];
// this strips out the \
$stripped = stripslashes($inbound);
$json_object = json_decode($stripped);
echo $json_object->{'firstName'};
echo $json_object->{'lastName'};
echo $json_object->{'email'};
echo $json_object->{'deviceUUID'};
</code></pre>
| [
{
"answer_id": 307683,
"author": "Dave Mateer",
"author_id": 26086,
"author_profile": "https://Stackoverflow.com/users/26086",
"pm_score": 0,
"selected": false,
"text": "$inbound = $_POST['json'];\nvar_dump($inbound);\n"
},
{
"answer_id": 307878,
"author": "Dave Mateer",
"author_id": 26086,
"author_profile": "https://Stackoverflow.com/users/26086",
"pm_score": 0,
"selected": false,
"text": "Debug.Write(s);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26086/"
] |
307,623 | <p>I'm writing some RSS feeds in PHP and stuggling with character-encoding issues. Should I utf8_encode() before or after htmlentities() encoding? For example, I've got both ampersands and Chinese characters in a description element, and I'm not sure which of these is proper:</p>
<pre><code>$output = utf8_encode(htmlentities($source)); or
$output = htmlentities(utf8_encode($source));
</code></pre>
<p>And why?</p>
| [
{
"answer_id": 307630,
"author": "SoapBox",
"author_id": 36384,
"author_profile": "https://Stackoverflow.com/users/36384",
"pm_score": 1,
"selected": false,
"text": "$output = htmlentities(utf8_encode($source));"
},
{
"answer_id": 307641,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 5,
"selected": true,
"text": "utf8_encode(htmlentities($source,ENT_COMPAT,'utf-8'));\n"
},
{
"answer_id": 322253,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": false,
"text": "htmlentities()"
},
{
"answer_id": 479032,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<title><![CDATA[News & Updates \" > » ☂ ☺ ☹ ☃ Test!]]></title>\n"
},
{
"answer_id": 479275,
"author": "Gumbo",
"author_id": 53114,
"author_profile": "https://Stackoverflow.com/users/53114",
"pm_score": 4,
"selected": false,
"text": "utf8_encode"
},
{
"answer_id": 900504,
"author": "katy lavallee",
"author_id": 111362,
"author_profile": "https://Stackoverflow.com/users/111362",
"pm_score": 0,
"selected": false,
"text": "$output = '<![CDATA['.utf8_encode(htmlentities($string)).']]>';\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17307/"
] |
307,636 | <p>I am able to create and execute a DTS package that copies tables from a remote Oracle database to a local SQL server, but want to setup the connection to the Oracle database as a linked server.</p>
<p>The DTS package currently uses the <em>Microsoft OLE DB Provider for Oracle</em> with the following properties:</p>
<ul>
<li>Data Source: <code>SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.3.42)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=acc)));uid=*UserName*;pwd=*UserPassword*;</code></li>
<li>Password: <em>UserPassword</em></li>
<li>User ID: <em>UserName</em></li>
<li>Allow saving password: true</li>
</ul>
<p>How do I go about setting a linked server to an Oracle database using the data source defined above?</p>
| [
{
"answer_id": 319018,
"author": "Oppositional",
"author_id": 2029,
"author_profile": "https://Stackoverflow.com/users/2029",
"pm_score": 6,
"selected": true,
"text": "C:\\Oracle"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2029/"
] |
307,640 | <p><strong>Edited:</strong>
What is the easiest way to <s>scrape</s> extract SharePoint list data to a separate SQL Server table? One condition: you're in a work environment where you don't control the SQL Server behind the SharePoint Server, so you can't just pull from the <em>UserData</em> table. </p>
<p>Is there there any utilities that you can use to schedule a nightly extract? </p>
<p>Is Microsoft planning any improvement here for "SharePoint 4"?</p>
<p><strong>Update Jan 06, 2009:</strong><br>
<a href="http://connectionstrings.com/sharepoint" rel="noreferrer">http://connectionstrings.com/sharepoint</a><br>
For servers where office is not installed you will need:<br>
<a href="http://www.microsoft.com/downloads/details.aspx?familyid=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en" rel="noreferrer">this download</a></p>
| [
{
"answer_id": 4301806,
"author": "Ulf",
"author_id": 523618,
"author_profile": "https://Stackoverflow.com/users/523618",
"pm_score": 2,
"selected": false,
"text": "My Custom SharePoint List"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
307,650 | <p>How can I remove duplicate values from an array in PHP?</p>
| [
{
"answer_id": 307655,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 9,
"selected": true,
"text": "$array = array(1, 2, 2, 3);\n$array = array_unique($array); // Array is now (1, 2, 3)\n"
},
{
"answer_id": 2397157,
"author": "Ashishdmc4",
"author_id": 288286,
"author_profile": "https://Stackoverflow.com/users/288286",
"pm_score": -1,
"selected": false,
"text": "$arr = array(\"1\", \"2\", \"3\", \"4\", \"5\", \"4\", \"2\", \"1\");\n\n$len = count($arr);\nfor ($i = 0; $i < $len; $i++) {\n $temp = $arr[$i];\n $j = $i;\n for ($k = 0; $k < $len; $k++) {\n if ($k != $j) {\n if ($temp == $arr[$k]) {\n echo $temp.\"<br>\";\n $arr[$k]=\" \";\n }\n }\n }\n}\n\nfor ($i = 0; $i < $len; $i++) {\n echo $arr[$i] . \" <br><br>\";\n}\n"
},
{
"answer_id": 3512161,
"author": "Deb",
"author_id": 303802,
"author_profile": "https://Stackoverflow.com/users/303802",
"pm_score": 2,
"selected": false,
"text": "explode(\",\", implode(\",\", array_unique(explode(\",\", $YOUR_ARRAY))));"
},
{
"answer_id": 5998555,
"author": "AgelessEssence",
"author_id": 209797,
"author_profile": "https://Stackoverflow.com/users/209797",
"pm_score": 3,
"selected": false,
"text": "array_unique()"
},
{
"answer_id": 8119319,
"author": "user1045247",
"author_id": 1045247,
"author_profile": "https://Stackoverflow.com/users/1045247",
"pm_score": 0,
"selected": false,
"text": "$arrDuplicate = array (\"\",\"\",1,3,\"\",5);\n foreach(array_unique($arrDuplicate) as $v){\n if($v != \"\" ){$arrRemoved = $v; }}\nprint_r($arrRemoved);\n"
},
{
"answer_id": 8399118,
"author": "chim",
"author_id": 673282,
"author_profile": "https://Stackoverflow.com/users/673282",
"pm_score": 5,
"selected": false,
"text": "//Find duplicates \n\n$arr = array( \n 'unique', \n 'duplicate', \n 'distinct', \n 'justone', \n 'three3', \n 'duplicate', \n 'three3', \n 'three3', \n 'onlyone' \n);\n\n$unique = array_unique($arr); \n$dupes = array_diff_key( $arr, $unique ); \n // array( 5=>'duplicate', 6=>'three3' 7=>'three3' )\n\n// count duplicates\n\narray_count_values($dupes); // array( 'duplicate'=>1, 'three3'=>2 )\n"
},
{
"answer_id": 11880798,
"author": "Dries B",
"author_id": 479154,
"author_profile": "https://Stackoverflow.com/users/479154",
"pm_score": 1,
"selected": false,
"text": "$arrDuplicate = array (\"\",\"\",1,3,\"\",5);\n\nforeach (array_unique($arrDuplicate) as $v){\n if($v != \"\") { $arrRemoved[] = $v; }\n}\nprint_r ($arrRemoved);\n"
},
{
"answer_id": 13230890,
"author": "V A S",
"author_id": 1702285,
"author_profile": "https://Stackoverflow.com/users/1702285",
"pm_score": -1,
"selected": false,
"text": "function arrayUnique($myArray)\n{\n $newArray = Array();\n if (is_array($myArray))\n {\n foreach($myArray as $key=>$val)\n {\n if (is_array($val))\n {\n $val2 = arrayUnique($val);\n }\n else\n {\n $val2 = $val;\n $newArray=array_unique($myArray);\n $newArray=deleteEmpty($newArray);\n break;\n }\n if (!empty($val2))\n {\n $newArray[$key] = $val2;\n }\n }\n }\n return ($newArray);\n}\n\nfunction deleteEmpty($myArray)\n{\n $retArray= Array();\n foreach($myArray as $key=>$val)\n {\n if (($key<>\"\") && ($val<>\"\"))\n {\n $retArray[$key] = $val;\n }\n }\n return $retArray;\n}\n"
},
{
"answer_id": 22782196,
"author": "Rohit Suthar",
"author_id": 1732454,
"author_profile": "https://Stackoverflow.com/users/1732454",
"pm_score": 0,
"selected": false,
"text": "$array = array (1,4,2,1,7,4,9,7,5,9);\n$unique = array();\n\nforeach($array as $v){\n isset($k[$v]) || ($k[$v]=1) && $unique[] = $v;\n }\n\nvar_dump($unique);\n"
},
{
"answer_id": 31646505,
"author": "Mirza Obaid",
"author_id": 5154741,
"author_profile": "https://Stackoverflow.com/users/5154741",
"pm_score": 0,
"selected": false,
"text": "function duplicate($arr) {\n $duplicate;\n $count = array_count_values($arr);\n foreach($arr as $key => $value) {\n if ($count[$value] > 1) {\n $duplicate[$value] = $value;\n }\n }\n return $duplicate;\n}\nfunction single($arr) {\n $single;\n $count = array_count_values($arr);\n foreach($arr as $key => $value) {\n if ($count[$value] == 1) {\n $single[$value] = $value;\n }\n }\n return $single;\n}\nfunction full($arr, $arry) {\n $full = $arr + $arry;\n sort($full);\n return $full;\n}\n"
},
{
"answer_id": 38558718,
"author": "Bollis",
"author_id": 2453789,
"author_profile": "https://Stackoverflow.com/users/2453789",
"pm_score": 2,
"selected": false,
"text": "$array = array_values( array_flip( array_flip( $array ) ) );\n"
},
{
"answer_id": 41620895,
"author": "iniravpatel",
"author_id": 3430657,
"author_profile": "https://Stackoverflow.com/users/3430657",
"pm_score": 4,
"selected": false,
"text": "$array = array_unique($array, SORT_REGULAR);\n"
},
{
"answer_id": 41823458,
"author": "sumityadavbadli",
"author_id": 6497511,
"author_profile": "https://Stackoverflow.com/users/6497511",
"pm_score": 0,
"selected": false,
"text": "<?php\n$arr1 = [1,1,2,3,4,5,6,3,1,3,5,3,20]; \nprint_r(arr_unique($arr1));\n\n\nfunction arr_unique($arr) {\n sort($arr);\n $curr = $arr[0];\n $uni_arr[] = $arr[0];\n for($i=0; $i<count($arr);$i++){\n if($curr != $arr[$i]) {\n $uni_arr[] = $arr[$i];\n $curr = $arr[$i];\n }\n }\n return $uni_arr;\n}\n"
},
{
"answer_id": 42251212,
"author": "nimey sara thomas",
"author_id": 3716927,
"author_profile": "https://Stackoverflow.com/users/3716927",
"pm_score": 6,
"selected": false,
"text": "array_values(array_unique($array));"
},
{
"answer_id": 44559404,
"author": "Alpesh Navadiya",
"author_id": 7755384,
"author_profile": "https://Stackoverflow.com/users/7755384",
"pm_score": 1,
"selected": false,
"text": " if (@!in_array($classified->category,$arr)){ \n $arr[] = $classified->category;\n ?>\n\n <?php } endwhile; wp_reset_query(); ?>\n"
},
{
"answer_id": 44820548,
"author": "harsh kumar",
"author_id": 6299038,
"author_profile": "https://Stackoverflow.com/users/6299038",
"pm_score": 2,
"selected": false,
"text": "$array = array (1,3,4,2,1,7,4,9,7,5,9);\n $data=array();\n foreach($array as $value ){\n\n $data[$value]= $value;\n\n }\n\n array_keys($data);\n OR\n array_values($data);\n"
},
{
"answer_id": 48755154,
"author": "Shivivanand",
"author_id": 9351857,
"author_profile": "https://Stackoverflow.com/users/9351857",
"pm_score": 1,
"selected": false,
"text": "$arrDup = Array ('0' => 'aaa-aaa' , 'SKU' => 'aaa-aaa' , '1' => '12/1/1' , 'date' => '12/1/1' , '2' => '1.15' , 'cost' => '1.15' );\n\nforeach($arrDup as $k => $v){\n if(!( isset ($hold[$v])))\n $hold[$v]=1;\n else\n unset($arrDup[$k]);\n}\n"
},
{
"answer_id": 48755493,
"author": "Amr Berag",
"author_id": 6281135,
"author_profile": "https://Stackoverflow.com/users/6281135",
"pm_score": 4,
"selected": false,
"text": "$result = array();\nforeach ($array as $key => $value){\n if(!in_array($value, $result))\n $result[$key]=$value;\n}\n"
},
{
"answer_id": 50695653,
"author": "Shahrukh Anwar",
"author_id": 8473036,
"author_profile": "https://Stackoverflow.com/users/8473036",
"pm_score": 2,
"selected": false,
"text": "//first method\n$filter = array_map(\"unserialize\", array_unique(array_map(\"serialize\", $arr)));\n\n//second method\n$array = array_unique($arr, SORT_REGULAR);\n"
},
{
"answer_id": 52591730,
"author": "michal.jakubeczy",
"author_id": 2470765,
"author_profile": "https://Stackoverflow.com/users/2470765",
"pm_score": 1,
"selected": false,
"text": "array_keys(array_flip($array));\n"
},
{
"answer_id": 53607799,
"author": "Aladin Banwal",
"author_id": 10742699,
"author_profile": "https://Stackoverflow.com/users/10742699",
"pm_score": 0,
"selected": false,
"text": "for"
},
{
"answer_id": 55612783,
"author": "pawan kumar",
"author_id": 9067214,
"author_profile": "https://Stackoverflow.com/users/9067214",
"pm_score": 2,
"selected": false,
"text": "$a = array(1, 2, 3, 4); \n$b = array(1, 6, 5, 2, 9); \n$c = array_merge($a, $b);\n$unique = array_keys(array_flip($c));\nprint_r($unique);\n"
},
{
"answer_id": 56903941,
"author": "nageen nayak",
"author_id": 3996624,
"author_profile": "https://Stackoverflow.com/users/3996624",
"pm_score": -1,
"selected": false,
"text": "$array = array(\"a\" => \"moon\", \"star\", \"b\" => \"moon\", \"star\", \"sky\");\n\n// Deleting the duplicate items\n$result = array_unique($array);\nprint_r($result);\n"
},
{
"answer_id": 60686354,
"author": "Richard Ramos",
"author_id": 9606216,
"author_profile": "https://Stackoverflow.com/users/9606216",
"pm_score": -1,
"selected": false,
"text": "if(array_search($matches[$i], $arr) === false){\n\n array_push($arr,$matches[$i]);\n}\n}\n\n//print the array $arr.\nprint_r($arr);\n\n//Result: Array\n(\n[0] => jorge\n[1] => melvin\n[2] => chelsy\n[3] => smith\n)\n"
},
{
"answer_id": 65527595,
"author": "Majid shiri",
"author_id": 13643802,
"author_profile": "https://Stackoverflow.com/users/13643802",
"pm_score": -1,
"selected": false,
"text": "<?php\n$a=array(\"1\"=>\"302\",\"2\"=>\"302\",\"3\"=>\"276\",\"4\"=>\"301\",\"5\"=>\"302\");\nprint_r(array_values(array_unique($a)));\n?>//`output -> Array ( [0] => 302 [1] => 276 [2] => 301 )`\n"
},
{
"answer_id": 68292865,
"author": "Rishi Chowdhury",
"author_id": 16402248,
"author_profile": "https://Stackoverflow.com/users/16402248",
"pm_score": 3,
"selected": false,
"text": "arrar_unique($array);"
},
{
"answer_id": 73202362,
"author": "heymynameisfoo",
"author_id": 19637635,
"author_profile": "https://Stackoverflow.com/users/19637635",
"pm_score": 2,
"selected": false,
"text": " <?php\n $numbers = [1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,65776567567,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1,1,3,4,5,6,2,5,7,1];\n $unique_numbers = [];\n \n foreach($numbers as $number)\n {\n if(!in_array($number,$unique_numbers)){\n $unique_numbers[] = $number;\n }\n }\n print(json_encode($unique_numbers)); //// Array is now 1,3,4,5,6,2,7, ....\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39539/"
] |
307,656 | <p>I have a C#.net winform program which runs with a SQL Server database. I am using LINQ-to-SQL. Is it possible to rollback the call to one or more stored procedures inside a transaction within my program using LINQ-to-SQL? </p>
<p>Initially I thought it would make sense to manage the transaction inside the stored procedure but if I need to rollback more than one stored procedure call as part of a single transaction it would need to be done in my C# program.</p>
<p>Can someone point me to a code snippet on how to do this or provide some insight into an alternative?</p>
| [
{
"answer_id": 307682,
"author": "Andre Gallo",
"author_id": 14401,
"author_profile": "https://Stackoverflow.com/users/14401",
"pm_score": -1,
"selected": false,
"text": " public Response<SomeObject> SaveSomething(Object yourObject)\n {\n DbTransaction dbTransaction = null;\n try\n {\n using (DataContext context = new DataContext())\n {\n //Creates a new DB transaction\n if (context.Connection.State == System.Data.ConnectionState.Closed)\n {\n context.Connection.Open();\n }\n dbTransaction = context.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable);\n context.Transaction = dbTransaction;\n\n context.SaveYourObject(yourObject);\n //Commit the transaction\n dbTransaction.Commit();\n response.ResponseObject = yourObject;\n response.Messages.AddSuccessfulSave(\"Saved!\");\n }\n }\n }\n catch (ChangeConflictException cex)\n {\n if (dbTransaction != null) dbTransaction.Rollback();\n response.Errors.AddConcurrencyError();\n response.IsSuccessful = false;\n }\n catch (SqlException sqlEx)\n {\n if (dbTransaction != null) dbTransaction.Rollback();\n if (sqlEx.Class == 14 && (sqlEx.Number == 2601 || sqlEx.Number == 2627)) //Duplicated key\n {\n response.Errors.Add(new Error\n {\n Name = \"Duplicate item\",\n Description = \"This object already exists.\"\n });\n ExceptionPolicy.HandleException(sqlEx, SERVICE_EXCEPTION_POLICY);\n response.IsSuccessful = false;\n }\n else //other SQL errors\n {\n response.Errors.AddSavingError(\"Your object\", yourObjectId);\n ExceptionPolicy.HandleException(sqlEx, SERVICE_EXCEPTION_POLICY);\n response.IsSuccessful = false;\n }\n }\n"
},
{
"answer_id": 307947,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": false,
"text": "DbTransaction"
},
{
"answer_id": 892374,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "private string RollBack_fn()\n{\n int sal = 0;\n OracleConnection myconn = new OracleConnection(ConfigurationManager.AppSettings[\"con\"].ToString());\n cmd = new OracleCommand(\"SP_student_MAST\", myconn);\n cmd.CommandType = CommandType.StoredProcedure;\n OracleParameter param1 = null, param2 = null, param3 = null, param4 = null, param5 = null;\n\n try\n {\n myconn.Open();\n trans = myconn.BeginTransaction();\n cmd.Transaction = trans;\n //param1 = new OracleParameter(\"pSNo\", OracleType.VarChar, 5);\n //param1.Value =\"\";\n //cmd.Parameters.Add(param1);\n\n param2 = new OracleParameter(\"pSName\", OracleType.VarChar, 10);\n // param2.Value = \"Saravanan\";\n param2.Value = TextBox1.Text;\n cmd.Parameters.Add(param2);\n\n param3 = new OracleParameter(\"pENo\", OracleType.VarChar,5);\n param3.Value = TextBox2.Text;\n cmd.Parameters.Add(param3);\n\n param4 = new OracleParameter(\"pEName\", OracleType.VarChar,10);\n // param4.Value = \"Sangeetha\";\n param4.Value = TextBox3.Text;\n cmd.Parameters.Add(param4);\n\n param5 = new OracleParameter(\"pSENo\", OracleType.Char, 5);\n param5.Value = \"\";\n cmd.Parameters.Add(param5);\n sal = cmd.ExecuteNonQuery();\n trans.Commit();\n Response.Write(\"Record Saved\");\n myconn.Close();\n // rollbackvalue = 0;\n }\n catch (Exception ex)\n {\n Response.Write(\"Not saved.RollBacked\");\n trans.Rollback();\n //rollbackvalue = 1;\n }\n string cs = Convert.ToString(sal);\n return cs;\n\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,658 | <p>I find myself running scripts and copy-pasting the output of these runs into emails or into some other documents. Is there a way such that I can make the copy-to-clipboard step a part of the script itself? Most of my scripts are either Perl or bat files and I work on Windows. </p>
<p>Thanks.</p>
| [
{
"answer_id": 307668,
"author": "digitalsanctum",
"author_id": 22436,
"author_profile": "https://Stackoverflow.com/users/22436",
"pm_score": 0,
"selected": false,
"text": "somescript.bat > output.txt\n"
},
{
"answer_id": 307690,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": true,
"text": "c:\\Windows\\system32"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27928/"
] |
307,664 | <p>Say I have a user control like the one below, how would I bind something to the <code>ActualWidth</code> of the "G1" grid from outside of the control?</p>
<pre><code><UserControl x:Class="Blah">
<WrapPanel>
<Grid x:Name="G1">
...
</Grid>
<Grid>
...
</Grid>
</WrapPanel>
</UserControl>
</code></pre>
| [
{
"answer_id": 307677,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 1,
"selected": false,
"text": "DependencyProperty"
},
{
"answer_id": 308385,
"author": "Arcturus",
"author_id": 900,
"author_profile": "https://Stackoverflow.com/users/900",
"pm_score": 2,
"selected": false,
"text": "ElementName"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36074/"
] |
307,669 | <p>I am trying to write an rspec test for a controller that accesses a
model Group.</p>
<pre>
@request.env['HTTP_REFERER'] = group_url(@mock_group) ### Line 49
</pre>
<p>I get this:</p>
<pre>
NoMethodError in 'ActsController responding to create should redirect to :back'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.rewrite
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:621:in `url_for'
(eval):17:in `group_url'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:464:in `send!'
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/test_process.rb:464:in `method_missing'
</pre>
<p>This line in url_for is the problem; specfically @url is nil.</p>
<pre>
@url.rewrite(rewrite_options(options))
</pre>
<p>And it seems that @url is initialized here:</p>
<pre>
def initialize_current_url
@url = UrlRewriter.new(request, params.clone)
end
</pre>
| [
{
"answer_id": 344892,
"author": "Matt Burke",
"author_id": 29691,
"author_profile": "https://Stackoverflow.com/users/29691",
"pm_score": 2,
"selected": false,
"text": "it \"should do whatever when referrer is group thing\" do\n @request.env[\"HTTP_REFERER\"] = url_for(@mock_group)\n get :some_action\n \"something\".should == \"something\"\nend\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,674 | <p>How can I remove duplicate values from a multi-dimensional array in PHP?</p>
<p>Example array:</p>
<pre><code>Array
(
[0] => Array
(
[0] => abc
[1] => def
)
[1] => Array
(
[0] => ghi
[1] => jkl
)
[2] => Array
(
[0] => mno
[1] => pql
)
[3] => Array
(
[0] => abc
[1] => def
)
[4] => Array
(
[0] => ghi
[1] => jkl
)
[5] => Array
(
[0] => mno
[1] => pql
)
)
</code></pre>
| [
{
"answer_id": 307701,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 4,
"selected": false,
"text": "\nfunction multi_unique($array) {\n foreach ($array as $k=>$na)\n $new[$k] = serialize($na);\n $uniq = array_unique($new);\n foreach($uniq as $k=>$ser)\n $new1[$k] = unserialize($ser);\n return ($new1);\n}"
},
{
"answer_id": 308955,
"author": "OIS",
"author_id": 36175,
"author_profile": "https://Stackoverflow.com/users/36175",
"pm_score": 6,
"selected": false,
"text": "function array_unique_multidimensional($input)\n{\n $serialized = array_map('serialize', $input);\n $unique = array_unique($serialized);\n return array_intersect_key($input, $unique);\n}\n"
},
{
"answer_id": 946300,
"author": "daveilers",
"author_id": 105596,
"author_profile": "https://Stackoverflow.com/users/105596",
"pm_score": 11,
"selected": true,
"text": "$input = array_map(\"unserialize\", array_unique(array_map(\"serialize\", $input)));\n"
},
{
"answer_id": 1019732,
"author": "pixeline",
"author_id": 53960,
"author_profile": "https://Stackoverflow.com/users/53960",
"pm_score": 1,
"selected": false,
"text": "function arrayUnique($myArray){\n if(!is_array($myArray))\n return $myArray;\n\n foreach ($myArray as &$myvalue){\n $myvalue=serialize($myvalue);\n }\n\n $myArray=array_unique($myArray);\n\n foreach ($myArray as &$myvalue){\n $myvalue=unserialize($myvalue);\n }\n\n return $myArray;\n\n} \n"
},
{
"answer_id": 10514539,
"author": "Rajendrasinh",
"author_id": 1384371,
"author_profile": "https://Stackoverflow.com/users/1384371",
"pm_score": 6,
"selected": false,
"text": "<?php\n function super_unique($array,$key)\n {\n $temp_array = [];\n foreach ($array as &$v) {\n if (!isset($temp_array[$v[$key]]))\n $temp_array[$v[$key]] =& $v;\n }\n $array = array_values($temp_array);\n return $array;\n\n }\n\n\n$arr=\"\";\n$arr[0]['id']=0;\n$arr[0]['titel']=\"ABC\";\n$arr[1]['id']=1;\n$arr[1]['titel']=\"DEF\";\n$arr[2]['id']=2;\n$arr[2]['titel']=\"ABC\";\n$arr[3]['id']=3;\n$arr[3]['titel']=\"XYZ\";\n\necho \"<pre>\";\nprint_r($arr);\necho \"unique*********************<br/>\";\nprint_r(super_unique($arr,'titel'));\n\n?>\n"
},
{
"answer_id": 18373723,
"author": "Ja͢ck",
"author_id": 1338292,
"author_profile": "https://Stackoverflow.com/users/1338292",
"pm_score": 8,
"selected": false,
"text": "array_unique()"
},
{
"answer_id": 26791100,
"author": "Denis Laliberté",
"author_id": 1318727,
"author_profile": "https://Stackoverflow.com/users/1318727",
"pm_score": 0,
"selected": false,
"text": "$test = [\n ['abc','def'],\n ['ghi','jkl'],\n ['mno','pql'],\n ['abc','def'],\n ['ghi','jkl'],\n ['mno','pql'],\n];\n\n$result = array_reduce(\n $test,\n function($carry,$item){\n if(!in_array($item,$carry)) {\n array_push($carry,$item);\n }\n return $carry;\n },\n []\n);\n\nvar_dump($result);\n\n/*\n php unique.php\narray(3) {\n [0] =>\n array(2) {\n [0] =>\n string(3) \"abc\"\n [1] =>\n string(3) \"def\"\n }\n [1] =>\n array(2) {\n [0] =>\n string(3) \"ghi\"\n [1] =>\n string(3) \"jkl\"\n }\n [2] =>\n array(2) {\n [0] =>\n string(3) \"mno\"\n [1] =>\n string(3) \"pql\"\n }\n}\n"
},
{
"answer_id": 26814820,
"author": "r3wt",
"author_id": 2401804,
"author_profile": "https://Stackoverflow.com/users/2401804",
"pm_score": 2,
"selected": false,
"text": "function search_array_compact($data,$key){\n $compact = [];\n foreach($data as $row){\n if(!in_array($row[$key],$compact)){\n $compact[] = $row;\n }\n }\n return $compact;\n}\n"
},
{
"answer_id": 28879677,
"author": "Snake",
"author_id": 1809824,
"author_profile": "https://Stackoverflow.com/users/1809824",
"pm_score": 0,
"selected": false,
"text": "$count_array = count($input);\nfor ($i = 0; $i < $count_array; $i++) {\n if (isset($input[$i])) {\n for ($j = $i+1; $j < $count_array; $j++) {\n if (isset($input[$j])) {\n //this is where you do your comparison for dupes\n if ($input[$i]['checksum'] == $input[$j]['checksum']) {\n unset($input[$j]);\n }\n }\n }\n }\n}\n"
},
{
"answer_id": 29721540,
"author": "Anuj",
"author_id": 816802,
"author_profile": "https://Stackoverflow.com/users/816802",
"pm_score": 1,
"selected": false,
"text": "array_unique()"
},
{
"answer_id": 31884637,
"author": "Limon",
"author_id": 2689507,
"author_profile": "https://Stackoverflow.com/users/2689507",
"pm_score": 2,
"selected": false,
"text": "Array=>\n [0] => (array)\n 'user' => 'john'\n 'age' => '23'\n [1] => (array)\n 'user' => 'jane'\n 'age' => '20'\n [2]=> (array)\n 'user' => 'john'\n 'age' => '23'\n"
},
{
"answer_id": 37356624,
"author": "automatix",
"author_id": 2019043,
"author_profile": "https://Stackoverflow.com/users/2019043",
"pm_score": 5,
"selected": false,
"text": "array_unique(...)"
},
{
"answer_id": 39270353,
"author": "Manish",
"author_id": 1578402,
"author_profile": "https://Stackoverflow.com/users/1578402",
"pm_score": 2,
"selected": false,
"text": "$input = array_map(\"unserialize\", array_unique(array_map(\"serialize\", $input)));\n"
},
{
"answer_id": 48342133,
"author": "Anand agrawal",
"author_id": 4608794,
"author_profile": "https://Stackoverflow.com/users/4608794",
"pm_score": 2,
"selected": false,
"text": "Array\n(\n [Key1] => Array\n (\n [0] => Value1\n [1] => Value2\n [2] => Value1\n [3] => Value3\n [4] => Value1\n )\n [Key2] => Array\n (\n [0] => Value1\n [1] => Value2\n [2] => Value1\n [3] => Value3\n [4] => Value4\n )\n)\n"
},
{
"answer_id": 48942412,
"author": "Mahak Choudhary",
"author_id": 2472157,
"author_profile": "https://Stackoverflow.com/users/2472157",
"pm_score": 5,
"selected": false,
"text": "Array\n(\n [0] => Array\n (\n [id] => 1\n [name] => john\n )\n\n [1] => Array\n (\n [id] => 2\n [name] => smith\n )\n\n [2] => Array\n (\n [id] => 3\n [name] => john\n )\n\n [3] => Array\n (\n [id] => 4\n [name] => robert\n )\n\n)\n\n$temp = array_unique(array_column($array, 'name'));\n$unique_arr = array_intersect_key($array, $temp);\n"
},
{
"answer_id": 60225040,
"author": "Gagan",
"author_id": 3719636,
"author_profile": "https://Stackoverflow.com/users/3719636",
"pm_score": -1,
"selected": false,
"text": "$input = array_values(array_map(\"unserialize\", array_unique(array_map(\"serialize\", $inputArray))));\n"
},
{
"answer_id": 72392856,
"author": "Hassan Elshazly Eida",
"author_id": 11430151,
"author_profile": "https://Stackoverflow.com/users/11430151",
"pm_score": 0,
"selected": false,
"text": "$arr= [\n0 => [0=>\"a\" , 1=>\"b\" , 2=>\"c\" ] ,\n1 => [0=>\"x\" , 1=>\"b\" , 2=>\"a\", 3=>\"p\"],\n2=> [\n [ \n 0=>\"y\" ,\n 1=>\"b\" ,\n 2=> [0=>\"x\" , 1=>\"m\" , 2=>\"a\"]\n ],\n 1=>\"z\" ,\n 2=>\"v\"\n ]\n ];\n"
},
{
"answer_id": 74496450,
"author": "Baraka",
"author_id": 7841955,
"author_profile": "https://Stackoverflow.com/users/7841955",
"pm_score": 0,
"selected": false,
"text": "<?php\n\n$list = [\n ['abc', 'def'],\n ['ghi', 'jkl'],\n ['mno', 'pql'],\n ['abc', 'def'],\n ['ghi', 'jkl'],\n ['mno', 'pql']\n];\n\n$list = array_filter($list, function ($item) {\n static $values = [];\n if (!in_array($item[0], $values)) {\n $values[] = $item[0];\n return true;\n } else {\n return false;\n }\n});\n\nvar_dump($list);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39539/"
] |
307,679 | <p>On PHP, they have a way to restrict file size AFTER uploading, but not BEFORE uploading. I use the <a href="http://malsup.com/jquery/form/" rel="noreferrer">Malsup jQuery Form Plugin</a> for my form posting, and it supports image file posting.</p>
<p>I was wondering if perhaps there's a restriction where I can set how many bytes can pass through that AJAX stream up to the server? That could permit me to check that file size and return an error if the file is too big. </p>
<p>By doing this on the client side, it blocks those newbies who take a 10MB photo shot from their Pentax and try to upload that.</p>
| [
{
"answer_id": 307861,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Requested content-length of 4000107 is larger than the configured limit of 2097152\n"
},
{
"answer_id": 3243161,
"author": "Adrian",
"author_id": 391141,
"author_profile": "https://Stackoverflow.com/users/391141",
"pm_score": 0,
"selected": false,
"text": "getimagesize()"
},
{
"answer_id": 5444716,
"author": "Abhilash RS",
"author_id": 678317,
"author_profile": "https://Stackoverflow.com/users/678317",
"pm_score": 3,
"selected": false,
"text": "<img id=\"myImage\" src=\"\" style=\"display:none;\"><br>\n<button onclick=\"findSize();\">Image Size</button>\n<input type=\"file\" id=\"loadfile\" />\n<input type=\"button\" value=\"find size\" onclick=\"findSize()\" />\n<script type=\"text/javascript\">\nfunction findSize() {\n if ( $.browser.msie ) {\n var a = document.getElementById('loadfile').value;\n $('#myImage').attr('src',a);\n var imgbytes = document.getElementById('myImage').size;\n var imgkbytes = Math.round(parseInt(imgbytes)/1024);\n alert(imgkbytes+' KB');\n }else {\n var fileInput = $(\"#loadfile\")[0];\n var imgbytes = fileInput.files[0].fileSize; // Size returned in bytes.\n var imgkbytes = Math.round(parseInt(imgbytes)/1024);\n alert(imgkbytes+' KB');\n }\n} \n</script>\n"
},
{
"answer_id": 9106313,
"author": "Felipe Sabino",
"author_id": 429521,
"author_profile": "https://Stackoverflow.com/users/429521",
"pm_score": 6,
"selected": false,
"text": "<input type=\"file\" id=\"myFile\" />\n"
},
{
"answer_id": 25737654,
"author": "Shemeemsha R A",
"author_id": 3442459,
"author_profile": "https://Stackoverflow.com/users/3442459",
"pm_score": 2,
"selected": false,
"text": " $(\".jq_fileUploader\").change(function () {\n var fileSize = this.files[0];\n var sizeInMb = fileSize.size/1024;\n var sizeLimit= 1024*10;\n if (sizeInMb > sizeLimit) {\n\n\n }\n else {\n\n\n }\n });\n"
},
{
"answer_id": 51706320,
"author": "Bablu Ahmed",
"author_id": 6836495,
"author_profile": "https://Stackoverflow.com/users/6836495",
"pm_score": 2,
"selected": false,
"text": "var sizeInKB = input.files[0].size/1024; //Normally files are in bytes but for KB divide by 1024 and so on\nvar sizeLimit= 30;\n\nif (sizeInKB >= sizeLimit) {\n alert(\"Max file size 30KB\");\n return false;\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,688 | <p>What is a simple way of downloading a file from a URL path?</p>
| [
{
"answer_id": 307697,
"author": "vbroto",
"author_id": 20837,
"author_profile": "https://Stackoverflow.com/users/20837",
"pm_score": 7,
"selected": false,
"text": "System.Net.WebClient.DownloadFile"
},
{
"answer_id": 308336,
"author": "Raj Kumar",
"author_id": 38931,
"author_profile": "https://Stackoverflow.com/users/38931",
"pm_score": 9,
"selected": false,
"text": "using (var client = new WebClient())\n{\n client.DownloadFile(\"http://example.com/file/song/a.mpeg\", \"a.mpeg\");\n}\n"
},
{
"answer_id": 17382193,
"author": "petrzjunior",
"author_id": 2534697,
"author_profile": "https://Stackoverflow.com/users/2534697",
"pm_score": 6,
"selected": false,
"text": "using System.Net;\n\nWebClient webClient = new WebClient();\nwebClient.DownloadFile(\"http://mysite.com/myfile.txt\", @\"c:\\myfile.txt\");\n"
},
{
"answer_id": 24237428,
"author": "turgay",
"author_id": 3686840,
"author_profile": "https://Stackoverflow.com/users/3686840",
"pm_score": 4,
"selected": false,
"text": " webClient.DownloadFileAsync(new Uri(\"http://www.example.com/file/test.jpg\"), \"test.jpg\");\n"
},
{
"answer_id": 29185200,
"author": "Abdul Saleem",
"author_id": 1879188,
"author_profile": "https://Stackoverflow.com/users/1879188",
"pm_score": 8,
"selected": false,
"text": "using System.Net;\n"
},
{
"answer_id": 35416599,
"author": "haZya",
"author_id": 4936590,
"author_profile": "https://Stackoverflow.com/users/4936590",
"pm_score": 3,
"selected": false,
"text": "GetIsNetworkAvailable()"
},
{
"answer_id": 35936119,
"author": "Jonas_Hess",
"author_id": 4508899,
"author_profile": "https://Stackoverflow.com/users/4508899",
"pm_score": 5,
"selected": false,
"text": "using System;\nusing System.ComponentModel;\nusing System.IO;\nusing System.Net;\nusing System.Threading;\n\nclass FileDownloader\n{\n private readonly string _url;\n private readonly string _fullPathWhereToSave;\n private bool _result = false;\n private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(0);\n\n public FileDownloader(string url, string fullPathWhereToSave)\n {\n if (string.IsNullOrEmpty(url)) throw new ArgumentNullException(\"url\");\n if (string.IsNullOrEmpty(fullPathWhereToSave)) throw new ArgumentNullException(\"fullPathWhereToSave\");\n\n this._url = url;\n this._fullPathWhereToSave = fullPathWhereToSave;\n }\n\n public bool StartDownload(int timeout)\n {\n try\n {\n System.IO.Directory.CreateDirectory(Path.GetDirectoryName(_fullPathWhereToSave));\n\n if (File.Exists(_fullPathWhereToSave))\n {\n File.Delete(_fullPathWhereToSave);\n }\n using (WebClient client = new WebClient())\n {\n var ur = new Uri(_url);\n // client.Credentials = new NetworkCredential(\"username\", \"password\");\n client.DownloadProgressChanged += WebClientDownloadProgressChanged;\n client.DownloadFileCompleted += WebClientDownloadCompleted;\n Console.WriteLine(@\"Downloading file:\");\n client.DownloadFileAsync(ur, _fullPathWhereToSave);\n _semaphore.Wait(timeout);\n return _result && File.Exists(_fullPathWhereToSave);\n }\n }\n catch (Exception e)\n {\n Console.WriteLine(\"Was not able to download file!\");\n Console.Write(e);\n return false;\n }\n finally\n {\n this._semaphore.Dispose();\n }\n }\n\n private void WebClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)\n {\n Console.Write(\"\\r --> {0}%.\", e.ProgressPercentage);\n }\n\n private void WebClientDownloadCompleted(object sender, AsyncCompletedEventArgs args)\n {\n _result = !args.Cancelled;\n if (!_result)\n {\n Console.Write(args.Error.ToString());\n }\n Console.WriteLine(Environment.NewLine + \"Download finished!\");\n _semaphore.Release();\n }\n\n public static bool DownloadFile(string url, string fullPathWhereToSave, int timeoutInMilliSec)\n {\n return new FileDownloader(url, fullPathWhereToSave).StartDownload(timeoutInMilliSec);\n }\n}\n"
},
{
"answer_id": 45637304,
"author": "Kreshnik",
"author_id": 1548596,
"author_profile": "https://Stackoverflow.com/users/1548596",
"pm_score": 1,
"selected": false,
"text": "using System.Net;\n// ...\n\nusing (WebClient client = new WebClient()) {\n Uri ur = new Uri(\"http://remotehost.do/images/img.jpg\");\n\n //client.Credentials = new NetworkCredential(\"username\", \"password\");\n String credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(\"Username\" + \":\" + \"MyNewPassword\"));\n client.Headers[HttpRequestHeader.Authorization] = $\"Basic {credentials}\";\n\n client.DownloadProgressChanged += (o, e) =>\n {\n Console.WriteLine($\"Download status: {e.ProgressPercentage}%.\");\n\n // updating the UI\n Dispatcher.Invoke(() => {\n progressBar.Value = e.ProgressPercentage;\n });\n };\n\n client.DownloadDataCompleted += (o, e) => \n {\n Console.WriteLine(\"Download finished!\");\n };\n\n client.DownloadFileAsync(ur, @\"C:\\path\\newImage.jpg\");\n}\n"
},
{
"answer_id": 47017311,
"author": "Darshit Gandhi",
"author_id": 6532692,
"author_profile": "https://Stackoverflow.com/users/6532692",
"pm_score": 2,
"selected": false,
"text": "private string DownloadFile(string url)\n {\n\n HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);\n string filename = \"\";\n string destinationpath = Environment;\n if (!Directory.Exists(destinationpath))\n {\n Directory.CreateDirectory(destinationpath);\n }\n using (HttpWebResponse response = (HttpWebResponse)request.GetResponseAsync().Result)\n {\n string path = response.Headers[\"Content-Disposition\"];\n if (string.IsNullOrWhiteSpace(path))\n {\n var uri = new Uri(url);\n filename = Path.GetFileName(uri.LocalPath);\n }\n else\n {\n ContentDisposition contentDisposition = new ContentDisposition(path);\n filename = contentDisposition.FileName;\n\n }\n\n var responseStream = response.GetResponseStream();\n using (var fileStream = File.Create(System.IO.Path.Combine(destinationpath, filename)))\n {\n responseStream.CopyTo(fileStream);\n }\n }\n\n return Path.Combine(destinationpath, filename);\n }\n"
},
{
"answer_id": 48205877,
"author": "Surendra Shrestha",
"author_id": 5540715,
"author_profile": "https://Stackoverflow.com/users/5540715",
"pm_score": 4,
"selected": false,
"text": "private void downloadFile(string url)\n{\n string file = System.IO.Path.GetFileName(url);\n WebClient cln = new WebClient();\n cln.DownloadFile(url, file);\n}\n"
},
{
"answer_id": 58060551,
"author": "Kiran Shahi",
"author_id": 5740382,
"author_profile": "https://Stackoverflow.com/users/5740382",
"pm_score": 2,
"selected": false,
"text": "WebClient.DownloadFileAsync"
},
{
"answer_id": 67168467,
"author": "Cryptc",
"author_id": 4427457,
"author_profile": "https://Stackoverflow.com/users/4427457",
"pm_score": 1,
"selected": false,
"text": "// Pass in the HTTPGET URL, Full Path w/Filename, and a populated Cookie Container (optional)\nprivate async Task DownloadFileRequiringHeadersAndCookies(string getUrl, string fullPath, CookieContainer cookieContainer, CancellationToken cancellationToken)\n{\n cookieContainer ??= new CookieContainer(); // TODO: FILL ME AND PASS ME IN\n\n using (var handler = new HttpClientHandler()\n {\n UseCookies = true,\n CookieContainer = cookieContainer, // This will, both, use the cookies passed in, and update/create cookies from the response\n ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true, // use only if it gets angry about the SSL endpoints\n AllowAutoRedirect = true,\n })\n {\n using (var client = new HttpClient(handler))\n {\n SetHeaders(client);\n\n using (var response = await client.GetAsync(getUrl, cancellationToken))\n {\n if (response.IsSuccessStatusCode)\n {\n var bytes = await response.Content.ReadAsByteArrayAsync(cancellationToken);\n await File.WriteAllBytesAsync(fullPath, bytes, cancellationToken); // This overwrites the file\n }\n else\n {\n // TODO: HANDLE ME\n throw new FileNotFoundException();\n }\n }\n }\n }\n}\n"
},
{
"answer_id": 67225309,
"author": "kofifus",
"author_id": 460084,
"author_profile": "https://Stackoverflow.com/users/460084",
"pm_score": 3,
"selected": false,
"text": "ResponseHeadersRead"
},
{
"answer_id": 67660340,
"author": "M22",
"author_id": 11704057,
"author_profile": "https://Stackoverflow.com/users/11704057",
"pm_score": 0,
"selected": false,
"text": "static void Main(string[] args)\n {\n DownloadFileAsync().GetAwaiter();\n \n Console.WriteLine(\"File was downloaded\");\n Console.Read();\n }\n \n private static async Task DownloadFileAsync()\n {\n WebClient client = new WebClient();\n await client.DownloadFileTaskAsync(new Uri(\"http://somesite.com/myfile.txt\"), \"mytxtFile.txt\");\n }\n"
},
{
"answer_id": 69752068,
"author": "O Thạnh Ldt",
"author_id": 5600152,
"author_profile": "https://Stackoverflow.com/users/5600152",
"pm_score": 0,
"selected": false,
"text": "public static void DownloadFile(string url, string pathToSaveFile)\n {\n ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;\n // or: ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;\n\n using (WebDownload client = new WebDownload())\n {\n client.Headers[\"User-Agent\"] = \"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36\";\n client.DownloadFile(new Uri(url), pathToSaveFile);\n }\n }\n \n public class WebDownload : WebClient\n {\n protected override WebRequest GetWebRequest(Uri address)\n {\n HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);\n if (request != null)\n {\n request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;\n }\n return request;\n }\n }\n"
},
{
"answer_id": 71229341,
"author": "Cryptc",
"author_id": 4427457,
"author_profile": "https://Stackoverflow.com/users/4427457",
"pm_score": 0,
"selected": false,
"text": "public async Task<ActionResult> DownloadUrl(string url) {\n return Redirect(url);\n}\n"
},
{
"answer_id": 71949994,
"author": "Davide Briscese",
"author_id": 5172807,
"author_profile": "https://Stackoverflow.com/users/5172807",
"pm_score": 5,
"selected": false,
"text": "WebRequest"
},
{
"answer_id": 72634285,
"author": "Kevin Smith",
"author_id": 4079967,
"author_profile": "https://Stackoverflow.com/users/4079967",
"pm_score": 1,
"selected": false,
"text": "using var httpClient = new HttpClient();\n\nvar tempPath = Path.GetTempFileName();\n\nawait using var s = await HttpClient.GetStreamAsync(pdfFilePath);\n\nawait using var fs = File.OpenWrite(tempPath);\n\nawait s.CopyToAsync(fs);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20837/"
] |
307,692 | <p>I would like to know the simplest and most effective way to open and write data to a socket in the C programming language for network programming.</p>
| [
{
"answer_id": 35681089,
"author": "Ciro Santilli OurBigBook.com",
"author_id": 895245,
"author_profile": "https://Stackoverflow.com/users/895245",
"pm_score": 3,
"selected": false,
"text": "./server.out\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2128/"
] |
307,695 | <p>Being new to Cocoa, and probably not knowing all of the potential classes available that already have this functionality neatly wrapped in an OO class, here's an algorithm inquiry. What's the best bet to count how many times a particular key occurs in an array of multiple <code>NSDictionary</code> instances?</p>
<p>Essentially my data structure (in this case an <code>NSArray</code>) might contain several <code>NSDictionary</code> instances at any given time, each one having the same keys, potentially different values. Some values repeat. I'd like to be able to know how many times a particular key/value appears. Example:</p>
<pre><code>{
foo => 1,
bar => 2
}
{
foo => 1,
bar => 3
}
{
foo => 2,
bar => 1
}
</code></pre>
<p>In this case I'm interested that <code>foo=>1</code> occured 2 times and <code>foo=>2</code> occured 1 time. Is building an instance of <code>NSCountedSet</code> the best way to go about this? Perhaps a C linked-list?</p>
| [
{
"answer_id": 307824,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 3,
"selected": true,
"text": "NSDictionary * dict1 = [[NSDictionary alloc] initWithObjectsAndKeys:\n [NSNumber numberWithInt:1], @\"foo\",\n [NSNumber numberWithInt:2], @\"bar\", nil];\nNSDictionary * dict2 = [[NSDictionary alloc] initWithObjectsAndKeys:\n [NSNumber numberWithInt:1], @\"foo\",\n [NSNumber numberWithInt:3], @\"bar\", nil];\nNSDictionary * dict3 = [[NSDictionary alloc] initWithObjectsAndKeys:\n [NSNumber numberWithInt:2], @\"foo\",\n [NSNumber numberWithInt:1], @\"bar\", nil];\nNSArray * arrayOfDictionaries = [[NSArray alloc] initWithObjects:\n dict1, dict2, dict3, nil];\n\n// count all keys in an array of dictionaries (arrayOfDictionaries):\n\nNSMutableDictionary * countKeys = [[NSMutableDictionary alloc] initWithCapacity:0];\nNSCountedSet * counts = [[NSCountedSet alloc] initWithCapacity:0];\n\nNSArray * keys;\nNSString * pairString;\nNSString * countKey;\nfor (NSDictionary * dictionary in arrayOfDictionaries)\n{\n keys = [dictionary allKeys];\n for (NSString * key in keys)\n {\n pairString = [NSString stringWithFormat:@\"%@->%@\", key, [dictionary valueForKey:key]];\n if ([countKeys valueForKey:pairString] == nil)\n {\n [countKeys setValue:[NSString stringWithString:pairString] forKey:pairString];\n }\n countKey = [countKeys valueForKey:pairString];\n { [counts addObject:countKey]; }\n }\n}\n\nNSLog(@\"%@\", counts);\n\n[counts release];\n[countKeys release];\n\n[arrayOfDictionaries release];\n[dict1 release];\n[dict2 release];\n[dict3 release];"
},
{
"answer_id": 307898,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 1,
"selected": false,
"text": "NSCountedSet *keyCounts = [NSCountedSet set];\nfor (NSDictionary *dict in myDictionaries)\n [keyCounts unionSet:[NSSet setWithArray:[dict allKeys]]];\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,706 | <p>Is there any easy way to add a using statement to every class I create in a project without having to write</p>
<pre><code>using SomeNamespace;
</code></pre>
<p>in every file?</p>
<p>[edit]
I could add a template I realise but I'm talking about doing it for every file in an existing project.</p>
| [
{
"answer_id": 307710,
"author": "EndangeredMassa",
"author_id": 106,
"author_profile": "https://Stackoverflow.com/users/106",
"pm_score": 0,
"selected": false,
"text": "<system.web>\n <pages>\n <namespaces>\n <add namespace=\"System.IO\" />\n <add namespace=\"System.Text\"/>\n <add namespace=\"Westwind.Tools\"/>\n </namespaces>\n </pages>\n</system.web>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6084/"
] |
307,709 | <p>When working with Silverlight, I've noticed that Firefox will cache the XAP file, so if I do an update, a user may be stuck using an outdated version. Is there a way to force the browser to either re-download the XAP file every time, or maybe only force it to after an update has been published? Or is there a setting in the Silverlight config that stops the browser from caching the XAP file altogether?</p>
<p>Thanks,
jeff</p>
| [
{
"answer_id": 307781,
"author": "Jarett Millard",
"author_id": 15882,
"author_profile": "https://Stackoverflow.com/users/15882",
"pm_score": 2,
"selected": false,
"text": "Cache-control: no-cache\nPragma: no-cache\n"
},
{
"answer_id": 310523,
"author": "Kevin Moore",
"author_id": 39827,
"author_profile": "https://Stackoverflow.com/users/39827",
"pm_score": 0,
"selected": false,
"text": "<param name=\"source\" value=\"app.xap?r12345\"/>\n"
},
{
"answer_id": 1367670,
"author": "Andy Mehalick",
"author_id": 98736,
"author_profile": "https://Stackoverflow.com/users/98736",
"pm_score": 4,
"selected": false,
"text": "<param name=\"source\" value=\"ClientBin/App.xap?<%= DateTime.Now.Ticks %>\" />\n"
},
{
"answer_id": 1469414,
"author": "Romain",
"author_id": 51473,
"author_profile": "https://Stackoverflow.com/users/51473",
"pm_score": 5,
"selected": false,
"text": "protected void Page_Load(object sender, EventArgs e)\n{\n var versionNumber = Assembly.GetExecutingAssembly().GetName().Version.ToString();\n this.myApp.Source += \"?\" + versionNumber;\n}\n"
},
{
"answer_id": 1882687,
"author": "FlappySocks",
"author_id": 115425,
"author_profile": "https://Stackoverflow.com/users/115425",
"pm_score": 3,
"selected": false,
"text": "<?php $fdate = date(\"dHis\",filemtime(\"MyApp.xap\")) ?>\n\n<param name=\"source\" value=\"MyApp.xap?=<?php echo $fdate ?>\"/>\n"
},
{
"answer_id": 4032381,
"author": "Chris Cairns",
"author_id": 488701,
"author_profile": "https://Stackoverflow.com/users/488701",
"pm_score": 2,
"selected": false,
"text": "var appTimestamp = '<%= System.IO.File.GetLastWriteTime(Server.MapPath(\"ClientBin/MyApp.xap\")) %>';\nvar source = 'ClientBin/MyApp.xap?appTimestamp=' + appTimestamp;\n"
},
{
"answer_id": 6309527,
"author": "JwJosefy",
"author_id": 543869,
"author_profile": "https://Stackoverflow.com/users/543869",
"pm_score": 3,
"selected": false,
"text": "<param name=\"source\" value=\"ClientBin/App.xap?<%= System.IO.File.GetLastWriteTime(Server.MapPath(\"ClientBin/App.xap\")).ToString().GetHashCode()%>\" />\n"
},
{
"answer_id": 7274060,
"author": "Vladimir Dorokhov",
"author_id": 493995,
"author_profile": "https://Stackoverflow.com/users/493995",
"pm_score": 0,
"selected": false,
"text": "<object id=\"Xaml1\" data=\"data:application/x-silverlight-2,\" type=\"application/x-silverlight-2\"\nwidth=\"100%\" height=\"100%\">\n<%––<param name=\"source\" value=\"ClientBin/SilverlightApp.xap\"/>––%>\n<%\nstring orgSourceValue = @\"ClientBin/SilverlightApp.xap\";\nstring param;\nif (System.Diagnostics.Debugger.IsAttached)\nparam = \"<param name=\\\"source\\\" value=\\\"\" + orgSourceValue + \"\\\" />\";\nelse\n{\nstring xappath = HttpContext.Current.Server.MapPath(@\"\") + @\"\\\" + orgSourceValue;\nDateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);\nparam = \"<param name=\\\"source\\\" value=\\\"\" + orgSourceValue + \"?ignore=\"\n+ xapCreationDate.ToString() + \"\\\" />\";\n}\nResponse.Write(param);\n%>\n<param name=\"onError\" value=\"onSilverlightError\" \n"
},
{
"answer_id": 8045953,
"author": "Alexanderius",
"author_id": 550882,
"author_profile": "https://Stackoverflow.com/users/550882",
"pm_score": 2,
"selected": false,
"text": "<%\n const string sourceValue = @\"ClientBin/MyXapFile.xap\";\n string param;\n\n if(System.Diagnostics.Debugger.IsAttached)\n param = \"<param name=\\\"source\\\" value=\\\"\" + sourceValue + \"\\\" />\";\n else\n {\n var xappath = HttpContext.Current.Server.MapPath(@\"\") + @\"\\\" + sourceValue;\n var xapCreationDate = System.IO.File.GetLastWriteTime(xappath);\n\n param = \"<param name=\\\"source\\\" value=\\\"\" + sourceValue + \"?ignore=\"\n + xapCreationDate + \"\\\" />\";\n }\n Response.Write(param);\n%>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12172/"
] |
307,729 | <pre><code>class Ball:
a = []
def __init__(self):
pass
def add(self,thing):
self.a.append(thing)
def size(self):
print len(self.a)
for i in range(3):
foo = Ball()
foo.add(1)
foo.add(2)
foo.size()
</code></pre>
<p>I would expect a return of :</p>
<pre><code>2
2
2
</code></pre>
<p>But I get :</p>
<pre><code>2
4
6
</code></pre>
<p>Why is this? I've found that by doing a=[] in the <strong>init</strong>, I can route around this behavior, but I'm less than clear why.</p>
| [
{
"answer_id": 307775,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "class Ball:\n def __init__(self):\n self.a = []\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35335/"
] |
307,737 | <p>I've got this problem with dynamically created TextBox.</p>
<p>When the TextBox is created in PageLoad, it's TextChanged event was fired.<br>
But when I dynamically delete and recreated the TextBox, the TextChanged was not fired.</p>
<p>This is the code:</p>
<p><strong>.aspx file</strong></p>
<pre><code><body>
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell ColumnSpan="2">Fixed content</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</code></pre>
<p><strong>.cs file</strong></p>
<pre><code>public partial class test : System.Web.UI.Page
{
string myText = "a";
protected void Page_Load(object sender, EventArgs e)
{
WriteRows();
}
private void WriteRows()
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
TextBox txt = new TextBox();
txt.Text = myText;
txt.TextChanged += new EventHandler(txt_TextChanged); // Assign event handler
tc.Controls.Add(txt);
tr.Controls.Add(tc);
tc = new TableCell();
tc.Text = txt.Text;
tr.Controls.Add(tc);
Table1.Controls.AddAt(1, tr);
}
private void txt_TextChanged(object sender, EventArgs e)
{
myText = ((TextBox)sender).Text;
RedrawTable(); // Delete the row (incl. the TextBox) and rewrite it
}
private void RedrawTable()
{
Table1.Controls.RemoveAt(1);
WriteRows();
}
}
</code></pre>
<p>Does anyone have a solution so that the event is always fired?</p>
| [
{
"answer_id": 307817,
"author": "Howard Pinsley",
"author_id": 7961,
"author_profile": "https://Stackoverflow.com/users/7961",
"pm_score": 1,
"selected": false,
"text": " \"The process that matches controls to posted values occurs \n after page_load completes, so it has to occur just like this \n if you are to use this way.\"\n"
},
{
"answer_id": 309155,
"author": "Buu",
"author_id": 17815,
"author_profile": "https://Stackoverflow.com/users/17815",
"pm_score": 5,
"selected": true,
"text": "TextBox txt = new TextBox();\ntxt.Text = myText;\ntxt.ID = \"txtBox\";\n"
},
{
"answer_id": 2927705,
"author": "mojam",
"author_id": 352723,
"author_profile": "https://Stackoverflow.com/users/352723",
"pm_score": 0,
"selected": false,
"text": "string myText = \"a\";\n\nprotected void Page_Load(object sender, EventArgs e)\n{\n WriteRows();\n}\n\nprivate void WriteRows()\n{\n TableRow tr = new TableRow();\n\n TableCell tc = new TableCell();\n TextBox txt = new TextBox();\n txt.Text = myText;\n\n txt.ID = \"txt1\";\n\n txt.TextChanged += new EventHandler(txt_TextChanged); // Assign event handler\n\n txt.AutoPostBack = true;\n\n tc.Controls.Add(txt);\n tr.Controls.Add(tc);\n\n tc = new TableCell();\n tc.Text = txt.Text;\n tr.Controls.Add(tc);\n\n Table1.Controls.AddAt(0,tr);\n\n}\n\nprivate void txt_TextChanged(object sender, EventArgs e)\n{\n myText = ((TextBox)sender).Text;\n RedrawTable(); // Delete the row (incl. the TextBox) and rewrite it\n}\n\nprivate void RedrawTable()\n{\n Table1.Controls.RemoveAt(0);\n WriteRows();\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36036/"
] |
307,740 | <p>In asp.net mvc, when do we use:</p>
<p>and</p>
<p>Do we ever need to put a ; (colon) ?</p>
| [
{
"answer_id": 307754,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": true,
"text": "<%= %>"
},
{
"answer_id": 307834,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "<%=\"something\" %>"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307740",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1368/"
] |
307,763 | <p>In VB6, ActiveX DLL is listed as a project template but in VS 2005+ there is no such thing. Where is my good old ActiveX DLL template? Many thanks in advance.</p>
| [
{
"answer_id": 308741,
"author": "RS Conley",
"author_id": 7890,
"author_profile": "https://Stackoverflow.com/users/7890",
"pm_score": 2,
"selected": false,
"text": "<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _\nPublic Class ComClass1\n\n#Region \"COM GUIDs\"\n ' These GUIDs provide the COM identity for this class \n ' and its COM interfaces. If you change them, existing \n ' clients will no longer be able to access the class.\n Public Const ClassId As String = \"6DB79AF2-F661-44AC-8458-62B06BFDD9E4\"\n Public Const InterfaceId As String = \"EDED909C-9271-4670-BA32-109AE917B1D7\"\n Public Const EventsId As String = \"17C731B8-CE61-4B5F-B114-10F3E46153AC\"\n#End Region\n\n ' A creatable COM class must have a Public Sub New() \n ' without parameters. Otherwise, the class will not be \n ' registered in the COM registry and cannot be created \n ' through CreateObject.\n Public Sub New()\n MyBase.New()\n End Sub\n\nEnd Class\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8203/"
] |
307,765 | <p>I was thinking along the lines of using <code>typeid()</code> but I don't know how to ask if that type is a subclass of another class (which, by the way, is abstract)</p>
| [
{
"answer_id": 307779,
"author": "Howard Pinsley",
"author_id": 7961,
"author_profile": "https://Stackoverflow.com/users/7961",
"pm_score": -1,
"selected": false,
"text": "if (myObj is Car) {\n\n}\n"
},
{
"answer_id": 307793,
"author": "Dima",
"author_id": 13313,
"author_profile": "https://Stackoverflow.com/users/13313",
"pm_score": 7,
"selected": true,
"text": "class Base;\nclass A : public Base {...};\nclass B : public Base {...};\n\nvoid foo(Base *p)\n{\n if(/* p is A */) /* do X */\n else /* do Y */\n}\n"
},
{
"answer_id": 307801,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 7,
"selected": false,
"text": "class Base\n{\n public: virtual ~Base() {}\n};\n\nclass D1: public Base {};\n\nclass D2: public Base {};\n\nint main(int argc,char* argv[]);\n{\n D1 d1;\n D2 d2;\n\n Base* x = (argc > 2)?&d1:&d2;\n\n if (dynamic_cast<D2*>(x) == nullptr)\n {\n std::cout << \"NOT A D2\" << std::endl;\n }\n if (dynamic_cast<D1*>(x) == nullptr)\n {\n std::cout << \"NOT A D1\" << std::endl;\n }\n}\n"
},
{
"answer_id": 307818,
"author": "Drew Hall",
"author_id": 23934,
"author_profile": "https://Stackoverflow.com/users/23934",
"pm_score": 5,
"selected": false,
"text": "dynamic_cast"
},
{
"answer_id": 307897,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 3,
"selected": false,
"text": "dynamic_cast"
},
{
"answer_id": 309409,
"author": "Sandeep Datta",
"author_id": 39648,
"author_profile": "https://Stackoverflow.com/users/39648",
"pm_score": 3,
"selected": false,
"text": "B"
},
{
"answer_id": 34375619,
"author": "BuvinJ",
"author_id": 3220983,
"author_profile": "https://Stackoverflow.com/users/3220983",
"pm_score": 2,
"selected": false,
"text": "class MyQObject : public QObject\n{\npublic:\n MyQObject( QObject *parent = 0 ) : QObject( parent ){}\n ~MyQObject(){}\n\n static bool isThisType( const QObject *qObj )\n { return ( dynamic_cast<const MyQObject*>(qObj) != NULL ); }\n};\n"
},
{
"answer_id": 44206749,
"author": "Reinaldo Guedes",
"author_id": 3594901,
"author_profile": "https://Stackoverflow.com/users/3594901",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <iostream.h>\n\nclass Base\n{\n public: virtual ~Base() {}\n\n template<typename T>\n bool isA() {\n return (dynamic_cast<T*>(this) != NULL);\n }\n};\n\nclass D1: public Base {};\nclass D2: public Base {};\nclass D22: public D2 {};\n\nint main(int argc,char* argv[]);\n{\n D1* d1 = new D1();\n D2* d2 = new D2();\n D22* d22 = new D22();\n\n Base* x = d22;\n\n if( x->isA<D22>() )\n {\n std::cout << \"IS A D22\" << std::endl;\n }\n if( x->isA<D2>() )\n {\n std::cout << \"IS A D2\" << std::endl;\n }\n if( x->isA<D1>() )\n {\n std::cout << \"IS A D1\" << std::endl;\n }\n if(x->isA<Base>() )\n {\n std::cout << \"IS A Base\" << std::endl;\n }\n}\n"
},
{
"answer_id": 44400720,
"author": "Ziezi",
"author_id": 3313438,
"author_profile": "https://Stackoverflow.com/users/3313438",
"pm_score": 2,
"selected": false,
"text": "typeid()"
},
{
"answer_id": 56977583,
"author": "ajneu",
"author_id": 5106243,
"author_profile": "https://Stackoverflow.com/users/5106243",
"pm_score": 4,
"selected": false,
"text": "#include <iostream>\n#include <typeinfo>\n#include <typeindex>\n\nenum class Type {Base, A, B};\n\nclass Base {\npublic:\n virtual ~Base() = default;\n virtual Type type() const {\n return Type::Base;\n }\n};\n\nclass A : public Base {\n Type type() const override {\n return Type::A;\n }\n};\n\nclass B : public Base {\n Type type() const override {\n return Type::B;\n }\n};\n\nint main()\n{\n const char *typemsg;\n A a;\n B b;\n Base *base = &a; // = &b; !!!!!!!!!!!!!!!!!\n Base &bbb = *base;\n\n // below you can replace base with &bbb and get the same results\n\n // USING virtual function\n // ======================\n // classes need to be in your control\n switch(base->type()) {\n case Type::A:\n typemsg = \"type A\";\n break;\n case Type::B:\n typemsg = \"type B\";\n break;\n default:\n typemsg = \"unknown\";\n }\n std::cout << typemsg << std::endl;\n\n // USING typeid\n // ======================\n // needs RTTI. under gcc, avoid -fno-rtti\n std::type_index ti(typeid(*base));\n if (ti == std::type_index(typeid(A))) {\n typemsg = \"type A\";\n } else if (ti == std::type_index(typeid(B))) {\n typemsg = \"type B\";\n } else {\n typemsg = \"unknown\";\n }\n std::cout << typemsg << std::endl;\n\n // USING dynamic_cast\n // ======================\n // needs RTTI. under gcc, avoid -fno-rtti\n if (dynamic_cast</*const*/ A*>(base)) {\n typemsg = \"type A\";\n } else if (dynamic_cast</*const*/ B*>(base)) {\n typemsg = \"type B\";\n } else {\n typemsg = \"unknown\";\n }\n std::cout << typemsg << std::endl;\n}\n"
},
{
"answer_id": 65380305,
"author": "Akib Azmain",
"author_id": 11819469,
"author_profile": "https://Stackoverflow.com/users/11819469",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\n\nclass base\n{\npublic:\n virtual ~base() = default;\n};\n\ntemplate <\n class type,\n class = decltype(\n static_cast<base*>(static_cast<type*>(0))\n )\n>\nbool check(type)\n{\n return true;\n}\n\nbool check(...)\n{\n return false;\n}\n\nclass child : public base\n{\npublic:\n virtual ~child() = default;\n};\n\nclass grandchild : public child {};\n\nint main()\n{\n std::cout << std::boolalpha;\n\n std::cout << \"base: \" << check(base()) << '\\n';\n std::cout << \"child: \" << check(child()) << '\\n';\n std::cout << \"grandchild: \" << check(grandchild()) << '\\n';\n std::cout << \"int: \" << check(int()) << '\\n';\n\n std::cout << std::flush;\n}\n"
},
{
"answer_id": 67866610,
"author": "user13947194",
"author_id": 13947194,
"author_profile": "https://Stackoverflow.com/users/13947194",
"pm_score": 2,
"selected": false,
"text": "class Base\n{\n void *p_virtual_table = BASE_VIRTUAL_TABLE;\n}\n\nclass Derived : Base\n{\n void *p_virtual_table = DERIVED_VIRTUAL_TABLE;\n}\n\nvoid *BASE_VIRTUAL_TABLE[n];\nvoid *DERIVED_VIRTUAL_TABLE[n];\n"
},
{
"answer_id": 69845765,
"author": "BuvinJ",
"author_id": 3220983,
"author_profile": "https://Stackoverflow.com/users/3220983",
"pm_score": 0,
"selected": false,
"text": "#define isInstance( ptr, clazz ) (dynamic_cast<const clazz*>(ptr) != NULL)\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39189/"
] |
307,766 | <p>I'm trying to convert a Web Site to the Web Application project model and I'm running into compile errors that do not seem to be covered by the guidance I found at <a href="http://msdn.microsoft.com/en-us/library/aa983476.aspx" rel="nofollow noreferrer">Converting a Web Site Project to a Web Application Project</a>.</p>
<p>The issue is that standard ASP.NET controls that are embedded as child controls within the ContentTemplate of the Ajax Control Toolkit's TabContainer/TabPanel are no longer visible to the page (and result in compile errors). It appears that they can only be referenced with a call to FindControl whereas, when the project was a Web Site, they were directly accessible in the page's code behind file as properties.</p>
<p>Unfortunately, we have a lot of webforms that utilize the TabContainer, and converting all the references to child controls from simple property refences to FindControl calls will be quite burdensome.</p>
<p>While researching the problem I found a reference to a property called TemplateInstance in <a href="http://www.nikhilk.net/SingleInstanceTemplates.aspx" rel="nofollow noreferrer">Single Instance Templates</a> that seemed promising, but I understand that this is applicable to control designers, not control users. Any help would be much appreciated.</p>
| [
{
"answer_id": 307779,
"author": "Howard Pinsley",
"author_id": 7961,
"author_profile": "https://Stackoverflow.com/users/7961",
"pm_score": -1,
"selected": false,
"text": "if (myObj is Car) {\n\n}\n"
},
{
"answer_id": 307793,
"author": "Dima",
"author_id": 13313,
"author_profile": "https://Stackoverflow.com/users/13313",
"pm_score": 7,
"selected": true,
"text": "class Base;\nclass A : public Base {...};\nclass B : public Base {...};\n\nvoid foo(Base *p)\n{\n if(/* p is A */) /* do X */\n else /* do Y */\n}\n"
},
{
"answer_id": 307801,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 7,
"selected": false,
"text": "class Base\n{\n public: virtual ~Base() {}\n};\n\nclass D1: public Base {};\n\nclass D2: public Base {};\n\nint main(int argc,char* argv[]);\n{\n D1 d1;\n D2 d2;\n\n Base* x = (argc > 2)?&d1:&d2;\n\n if (dynamic_cast<D2*>(x) == nullptr)\n {\n std::cout << \"NOT A D2\" << std::endl;\n }\n if (dynamic_cast<D1*>(x) == nullptr)\n {\n std::cout << \"NOT A D1\" << std::endl;\n }\n}\n"
},
{
"answer_id": 307818,
"author": "Drew Hall",
"author_id": 23934,
"author_profile": "https://Stackoverflow.com/users/23934",
"pm_score": 5,
"selected": false,
"text": "dynamic_cast"
},
{
"answer_id": 307897,
"author": "coppro",
"author_id": 16855,
"author_profile": "https://Stackoverflow.com/users/16855",
"pm_score": 3,
"selected": false,
"text": "dynamic_cast"
},
{
"answer_id": 309409,
"author": "Sandeep Datta",
"author_id": 39648,
"author_profile": "https://Stackoverflow.com/users/39648",
"pm_score": 3,
"selected": false,
"text": "B"
},
{
"answer_id": 34375619,
"author": "BuvinJ",
"author_id": 3220983,
"author_profile": "https://Stackoverflow.com/users/3220983",
"pm_score": 2,
"selected": false,
"text": "class MyQObject : public QObject\n{\npublic:\n MyQObject( QObject *parent = 0 ) : QObject( parent ){}\n ~MyQObject(){}\n\n static bool isThisType( const QObject *qObj )\n { return ( dynamic_cast<const MyQObject*>(qObj) != NULL ); }\n};\n"
},
{
"answer_id": 44206749,
"author": "Reinaldo Guedes",
"author_id": 3594901,
"author_profile": "https://Stackoverflow.com/users/3594901",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n#include <iostream.h>\n\nclass Base\n{\n public: virtual ~Base() {}\n\n template<typename T>\n bool isA() {\n return (dynamic_cast<T*>(this) != NULL);\n }\n};\n\nclass D1: public Base {};\nclass D2: public Base {};\nclass D22: public D2 {};\n\nint main(int argc,char* argv[]);\n{\n D1* d1 = new D1();\n D2* d2 = new D2();\n D22* d22 = new D22();\n\n Base* x = d22;\n\n if( x->isA<D22>() )\n {\n std::cout << \"IS A D22\" << std::endl;\n }\n if( x->isA<D2>() )\n {\n std::cout << \"IS A D2\" << std::endl;\n }\n if( x->isA<D1>() )\n {\n std::cout << \"IS A D1\" << std::endl;\n }\n if(x->isA<Base>() )\n {\n std::cout << \"IS A Base\" << std::endl;\n }\n}\n"
},
{
"answer_id": 44400720,
"author": "Ziezi",
"author_id": 3313438,
"author_profile": "https://Stackoverflow.com/users/3313438",
"pm_score": 2,
"selected": false,
"text": "typeid()"
},
{
"answer_id": 56977583,
"author": "ajneu",
"author_id": 5106243,
"author_profile": "https://Stackoverflow.com/users/5106243",
"pm_score": 4,
"selected": false,
"text": "#include <iostream>\n#include <typeinfo>\n#include <typeindex>\n\nenum class Type {Base, A, B};\n\nclass Base {\npublic:\n virtual ~Base() = default;\n virtual Type type() const {\n return Type::Base;\n }\n};\n\nclass A : public Base {\n Type type() const override {\n return Type::A;\n }\n};\n\nclass B : public Base {\n Type type() const override {\n return Type::B;\n }\n};\n\nint main()\n{\n const char *typemsg;\n A a;\n B b;\n Base *base = &a; // = &b; !!!!!!!!!!!!!!!!!\n Base &bbb = *base;\n\n // below you can replace base with &bbb and get the same results\n\n // USING virtual function\n // ======================\n // classes need to be in your control\n switch(base->type()) {\n case Type::A:\n typemsg = \"type A\";\n break;\n case Type::B:\n typemsg = \"type B\";\n break;\n default:\n typemsg = \"unknown\";\n }\n std::cout << typemsg << std::endl;\n\n // USING typeid\n // ======================\n // needs RTTI. under gcc, avoid -fno-rtti\n std::type_index ti(typeid(*base));\n if (ti == std::type_index(typeid(A))) {\n typemsg = \"type A\";\n } else if (ti == std::type_index(typeid(B))) {\n typemsg = \"type B\";\n } else {\n typemsg = \"unknown\";\n }\n std::cout << typemsg << std::endl;\n\n // USING dynamic_cast\n // ======================\n // needs RTTI. under gcc, avoid -fno-rtti\n if (dynamic_cast</*const*/ A*>(base)) {\n typemsg = \"type A\";\n } else if (dynamic_cast</*const*/ B*>(base)) {\n typemsg = \"type B\";\n } else {\n typemsg = \"unknown\";\n }\n std::cout << typemsg << std::endl;\n}\n"
},
{
"answer_id": 65380305,
"author": "Akib Azmain",
"author_id": 11819469,
"author_profile": "https://Stackoverflow.com/users/11819469",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\n\nclass base\n{\npublic:\n virtual ~base() = default;\n};\n\ntemplate <\n class type,\n class = decltype(\n static_cast<base*>(static_cast<type*>(0))\n )\n>\nbool check(type)\n{\n return true;\n}\n\nbool check(...)\n{\n return false;\n}\n\nclass child : public base\n{\npublic:\n virtual ~child() = default;\n};\n\nclass grandchild : public child {};\n\nint main()\n{\n std::cout << std::boolalpha;\n\n std::cout << \"base: \" << check(base()) << '\\n';\n std::cout << \"child: \" << check(child()) << '\\n';\n std::cout << \"grandchild: \" << check(grandchild()) << '\\n';\n std::cout << \"int: \" << check(int()) << '\\n';\n\n std::cout << std::flush;\n}\n"
},
{
"answer_id": 67866610,
"author": "user13947194",
"author_id": 13947194,
"author_profile": "https://Stackoverflow.com/users/13947194",
"pm_score": 2,
"selected": false,
"text": "class Base\n{\n void *p_virtual_table = BASE_VIRTUAL_TABLE;\n}\n\nclass Derived : Base\n{\n void *p_virtual_table = DERIVED_VIRTUAL_TABLE;\n}\n\nvoid *BASE_VIRTUAL_TABLE[n];\nvoid *DERIVED_VIRTUAL_TABLE[n];\n"
},
{
"answer_id": 69845765,
"author": "BuvinJ",
"author_id": 3220983,
"author_profile": "https://Stackoverflow.com/users/3220983",
"pm_score": 0,
"selected": false,
"text": "#define isInstance( ptr, clazz ) (dynamic_cast<const clazz*>(ptr) != NULL)\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7961/"
] |
307,774 | <p>How can I list the contents of a zipped folder in C#? For example how to know how many items are contained within a zipped folder, and what is their name?</p>
| [
{
"answer_id": 307778,
"author": "Chris Ballance",
"author_id": 1551,
"author_profile": "https://Stackoverflow.com/users/1551",
"pm_score": 4,
"selected": false,
"text": "ZipInputStream inStream = new ZipInputStream(File.OpenRead(fileName));\n\nwhile (inStream.GetNextEntry())\n{\n\n ZipEntry entry = inStream.GetNextEntry();\n //write out your entry's filename\n}\n"
},
{
"answer_id": 307787,
"author": "Chris Fulstow",
"author_id": 38126,
"author_profile": "https://Stackoverflow.com/users/38126",
"pm_score": 5,
"selected": false,
"text": "using (var zip = ZipFile.Read(PathToZipFolder))\n{\n int totalEntries = zip.Entries.Count; \n foreach (ZipEntry e in zip.Entries)\n {\n e.FileName ...\n e.CompressedSize ...\n e.LastModified...\n }\n}\n"
},
{
"answer_id": 309561,
"author": "vbroto",
"author_id": 20837,
"author_profile": "https://Stackoverflow.com/users/20837",
"pm_score": 0,
"selected": false,
"text": "\nZipFile package = new ZipFile(packagePath);\njava.util.Enumeration entries = package.entries();\n//We have to use Java enumerators because we\n//use java.util.zip for reading the .zip files\nwhile ( entries.hasMoreElements() )\n{\n ZipEntry entry = (ZipEntry) entries.nextElement();\n\n if (!entry.isDirectory())\n {\n string name = entry.getName();\n Console.WriteLine(\"File: \" + name + \", size: \" + entry.getSize() + \", compressed size: \" + entry.getCompressedSize());\n }\n else\n {\n // Handle directories...\n } \n}\n"
},
{
"answer_id": 410456,
"author": "Cheeso",
"author_id": 48082,
"author_profile": "https://Stackoverflow.com/users/48082",
"pm_score": 3,
"selected": false,
"text": "using (ZipFile zip = ZipFile.Read(zipfile) )\n{\n bool header = true;\n foreach (ZipEntry e in zip)\n {\n if (header)\n {\n System.Console.WriteLine(\"Zipfile: {0}\", zip.Name);\n if ((zip.Comment != null) && (zip.Comment != \"\"))\n System.Console.WriteLine(\"Comment: {0}\", zip.Comment);\n\n System.Console.WriteLine(\"\\n{1,-22} {2,9} {3,5} {4,9} {5,3} {6,8} {0}\",\n \"Filename\", \"Modified\", \"Size\", \"Ratio\", \"Packed\", \"pw?\", \"CRC\");\n System.Console.WriteLine(new System.String('-', 80));\n header = false;\n }\n\n System.Console.WriteLine(\"{1,-22} {2,9} {3,5:F0}% {4,9} {5,3} {6:X8} {0}\",\n e.FileName,\n e.LastModified.ToString(\"yyyy-MM-dd HH:mm:ss\"),\n e.UncompressedSize,\n e.CompressionRatio,\n e.CompressedSize,\n (e.UsesEncryption) ? \"Y\" : \"N\",\n e.Crc32);\n\n if ((e.Comment != null) && (e.Comment != \"\"))\n System.Console.WriteLine(\" Comment: {0}\", e.Comment);\n }\n}\n"
},
{
"answer_id": 10072571,
"author": "Joshua",
"author_id": 1104995,
"author_profile": "https://Stackoverflow.com/users/1104995",
"pm_score": 2,
"selected": false,
"text": "var zipFilePath = \"c:\\\\myfile.zip\";\nvar tempFolderPath = \"c:\\\\unzipped\";\n\nusing (Package package = ZipPackage.Open(zipFilePath, FileMode.Open, FileAccess.Read))\n{\n foreach (PackagePart part in package.GetParts())\n {\n var target = Path.GetFullPath(Path.Combine(tempFolderPath, part.Uri.OriginalString.TrimStart('/')));\n var targetDir = target.Remove(target.LastIndexOf('\\\\'));\n\n if (!Directory.Exists(targetDir))\n Directory.CreateDirectory(targetDir);\n\n using (Stream source = part.GetStream(FileMode.Open, FileAccess.Read))\n {\n source.CopyTo(File.OpenWrite(target));\n }\n }\n}\n"
},
{
"answer_id": 21767844,
"author": "Csaba Toth",
"author_id": 292502,
"author_profile": "https://Stackoverflow.com/users/292502",
"pm_score": 5,
"selected": false,
"text": "System.IO.Compression.ZipArchive"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20837/"
] |
307,777 | <p>This is a really basic question but...</p>
<p>I have some code like this</p>
<pre><code>var arr = Array('blah.jpg','ha.jpg');
for (var i=0; i<array.length; i++)
{
$('div#blah' + i).click(function() {
$('img').attr('src', arr[i]); });
}
</code></pre>
<p>This should bind the div with <code>id="blah0"</code> to change all images to <code>'blah.jpg'</code> when clicked.
Similarly, clicking the div with <code>id ="blah1"</code> should change all images to <code>'ha.jpg'</code>.</p>
<p>However, the anonymous function won't work because it will use the value of 'i' at the time of execution, i.e. 2. This means that clicking either div will try and set all images to arr[2] - a non-existent element (interestingly not throwing a JS error on my machine but that's another story...).</p>
<p>How can I get the anonymous function to be created using the value of 'i' at declaration time?</p>
<p>As a simpler example:</p>
<pre><code>for (var i=0; i<10; i++)
{
$('div#blah'+i).click(function() {
alert(i)); });
}
</code></pre>
<p>This should display '0' when I click 'blah0', '1' when I click 'blah1' etc.</p>
<p>However, by default it will display '10' no matter which 'blah' i click.</p>
| [
{
"answer_id": 307786,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 0,
"selected": false,
"text": "\nvar j = 0;\nfor (var i=0; i<array.length; i++)\n{\n $('div#blah' + j).click(function() {\n $('img').attr('src', arr[i]); });\n\n j++;\n}\n"
},
{
"answer_id": 307790,
"author": "Matthew Crumley",
"author_id": 2214,
"author_profile": "https://Stackoverflow.com/users/2214",
"pm_score": 4,
"selected": true,
"text": "function makeClickHandler(arr, local_i) {\n return function() {\n $('img').attr('src', arr[local_i]);\n };\n}\n\nvar arr = Array('blah.jpg','ha.jpg');\nfor (var i=0; i<array.length; i++)\n{\n $('div#blah' + i).click(makeClickHandler(arr, i));\n}\n"
},
{
"answer_id": 307810,
"author": "Matt Mitchell",
"author_id": 364,
"author_profile": "https://Stackoverflow.com/users/364",
"pm_score": 0,
"selected": false,
"text": "var arr = Array('blah.jpg','ha.jpg');\nfor (var i=0; i<array.length; i++)\n{\n eval(\"$('div#blah' + i).click(function() { $('img').attr('src', arr[\" + i + \"]); })\");\n}\n"
},
{
"answer_id": 307903,
"author": "Darko",
"author_id": 32943,
"author_profile": "https://Stackoverflow.com/users/32943",
"pm_score": 2,
"selected": false,
"text": "for (var i=0; i<10; i++)\n{\n (function(j){\n $('div#blah'+j).click(function() { alert(j)); });\n })(i); \n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364/"
] |
307,783 | <p>When using topfunky's <a href="http://nubyonrails.com/articles/automation-with-rstakeout" rel="nofollow noreferrer">RStakeout</a>, the color in the result of the <code>spec</code> command is lost. This happens even when adding the <code>--color</code> flag.</p>
| [
{
"answer_id": 307788,
"author": "Chris Lloyd",
"author_id": 42413,
"author_profile": "https://Stackoverflow.com/users/42413",
"pm_score": 2,
"selected": true,
"text": "AUTOTEST"
},
{
"answer_id": 4435801,
"author": "sent-hil",
"author_id": 236655,
"author_profile": "https://Stackoverflow.com/users/236655",
"pm_score": 2,
"selected": false,
"text": "--tty"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42413/"
] |
307,796 | <p>Hopefully a nice simple one.</p>
<p>I've got a php3 website that I want to run on php 5.2</p>
<p>To start with I'd just like to have every reference to the current "index.php3" _within_each_file_ (recursively) changed to "index.php" and then move on to worrying about globals etc.</p>
<p>K. Go!</p>
<p>:) </p>
<p>Update: Thanks a lot! I realise that my question missed the fact that the references are in each file of a website and I wanted to do it recursively in all files/folders.</p>
| [
{
"answer_id": 307815,
"author": "Brian C. Lane",
"author_id": 27461,
"author_profile": "https://Stackoverflow.com/users/27461",
"pm_score": 2,
"selected": false,
"text": "sed -i 's/php3/php/g' *"
},
{
"answer_id": 307816,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 2,
"selected": false,
"text": "for file in *.php3\ndo\n sed 's/\\.php3/.php/g' $file > ${file%3}\ndone\n"
},
{
"answer_id": 307988,
"author": "ctuffli",
"author_id": 26683,
"author_profile": "https://Stackoverflow.com/users/26683",
"pm_score": 1,
"selected": false,
"text": "find . -type f"
},
{
"answer_id": 308048,
"author": "Joshua Swink",
"author_id": 14732,
"author_profile": "https://Stackoverflow.com/users/14732",
"pm_score": 4,
"selected": true,
"text": "find -type f -exec perl -pi -e 's/\\bindex\\.php3\\b/index.php/g' {} \\;\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307796",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13007/"
] |
307,798 | <p>I'm working on a little web crawler that will run in the system tray and crawl a web site every hour on the hour.</p>
<p>What is the best way to get .NET to raise an event every hour or some other interval to perform some task. For example I want to run an event every 20 minutes based on the time. The event would be raised at:</p>
<pre><code>00:20
00:40
01:00
01:20
01:40
</code></pre>
<p>and so on. The best way I can think of to do this is by creating a loop on a thread, that constantly checks if the time is divisible by a given interval and raises a callback event if the time is reached. I feel like there has got to be a better way. </p>
<p>I'd use a <code>Timer</code> but I'd prefer something that follows a "schedule" that runs on the hour or something along those lines. </p>
<p>Without setting up my application in the windows task scheduler is this possible?</p>
<p><strong>UPDATE:</strong><br>
I'm adding my algorithm for calculating the time interval for a timer. This method takes a "<code>minute</code>" parameter, which is what time the timer should trigger a tick. For example, if the "<code>minute</code>" parameter is 20, then the timer will tick at the intervals in the timetable above.</p>
<pre><code>int CalculateTimerInterval(int minute)
{
if (minute <= 0)
minute = 60;
DateTime now = DateTime.Now;
DateTime future = now.AddMinutes((minute - (now.Minute % minute))).AddSeconds(now.Second * -1).AddMilliseconds(now.Millisecond * -1);
TimeSpan interval = future - now;
return (int)interval.TotalMilliseconds;
}
</code></pre>
<p>This code is used as follows: </p>
<pre><code>static System.Windows.Forms.Timer t;
const int CHECK_INTERVAL = 20;
static void Main()
{
t = new System.Windows.Forms.Timer();
t.Interval = CalculateTimerInterval(CHECK_INTERVAL);
t.Tick += new EventHandler(t_Tick);
t.Start();
}
static void t_Tick(object sender, EventArgs e)
{
t.Interval = CalculateTimerInterval(CHECK_INTERVAL);
}
</code></pre>
| [
{
"answer_id": 307806,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 6,
"selected": true,
"text": "int minutes = DateTime.Now.Minute;\nint adjust = 10 - (minutes % 10);\ntimer.Interval = adjust * 60 * 1000; \n"
},
{
"answer_id": 308055,
"author": "ExCodeCowboy",
"author_id": 384951,
"author_profile": "https://Stackoverflow.com/users/384951",
"pm_score": 2,
"selected": false,
"text": " public Form1()\n {\n InitializeComponent();\n\n //some fake data, obviously you would have your own.\n DateTime someStart = DateTime.Now.AddMinutes(1);\n TimeSpan someInterval = TimeSpan.FromMinutes(2);\n\n //sample call\n StartTimer(someStart,someInterval,doSomething);\n }\n\n //just a fake function to call\n private bool doSomething()\n {\n DialogResult keepGoing = MessageBox.Show(\"Hey, I did something! Keep Going?\",\"Something!\",MessageBoxButtons.YesNo);\n return (keepGoing == DialogResult.Yes);\n }\n\n //The following is the actual guts.. and can be transplanted to an actual class.\n private delegate void voidFunc<P1,P2,P3>(P1 p1,P2 p2,P3 p3);\n public void StartTimer(DateTime startTime, TimeSpan interval, Func<bool> action)\n {\n voidFunc<DateTime,TimeSpan,Func<bool>> Timer = TimedThread;\n Timer.BeginInvoke(startTime,interval,action,null,null);\n }\n\n private void TimedThread(DateTime startTime, TimeSpan interval, Func<bool> action)\n {\n bool keepRunning = true;\n DateTime NextExecute = startTime;\n while(keepRunning)\n {\n if (DateTime.Now > NextExecute)\n {\n keepRunning = action.Invoke();\n NextExecute = NextExecute.Add(interval);\n }\n //could parameterize resolution.\n Thread.Sleep(1000);\n } \n }\n"
},
{
"answer_id": 7555057,
"author": "hey",
"author_id": 965044,
"author_profile": "https://Stackoverflow.com/users/965044",
"pm_score": -1,
"selected": false,
"text": "private Timer _timer;\nprivate Int32 _hours = 0;\nprivate Int32 _runAt = 3;\n\nprotected override void OnStart(string[] args)\n{\n _hours = (24 - (DateTime.Now.Hour + 1)) + _runAt;\n _timer = new Timer();\n _timer.Interval = _hours * 60 * 60 * 1000;\n _timer.Elapsed += new ElapsedEventHandler(Tick);\n _timer.Start();\n}\n\nvoid Tick(object sender, ElapsedEventArgs e)\n{\n if (_hours != 24)\n {\n _hours = 24;\n _timer.Interval = _hours * 60 * 60 * 1000;\n }\n\n RunImport();\n}\n"
},
{
"answer_id": 64368932,
"author": "user2295457",
"author_id": 2295457,
"author_profile": "https://Stackoverflow.com/users/2295457",
"pm_score": 0,
"selected": false,
"text": "static void Main(string[] Args)\n{\n try\n {\n MainAsync().GetAwaiter().GetResult();\n }\n catch (Exception ex)\n {\n Console.WriteLine(ex.Message);\n }\n}\n\nstatic async Task MainAsync()\n{\n CancellationTokenSource tokenSource = new CancellationTokenSource();\n \n // Start the timed event here\n StartAsync(tokenSource.Token);\n \n\n Console.ReadKey();\n\n tokenSource.Cancel();\n tokenSource.Dispose();\n}\n\npublic Task StartAsync(CancellationToken cancellationToken)\n{\n var nextRunTime = new DateTime();\n\n switch (DateTime.Now.AddSeconds(1) < DateTime.Today.AddHours(12)) // add a second to current time to account for time needed to setup the task.\n{\n case true:\n nextRunTime = DateTime.Today.AddHours(12); // Run at midday today.\n break;\n case false:\n nextRunTime = DateTime.Today.AddDays(1).AddHours(12); // Run at midday tomorrow.\n break;\n }\n\n var firstInterval = nextRunTime.Subtract(DateTime.Now);\n \n Action action = () =>\n {\n // Run the task at the first interval, then run the task again at midday every day. \n _timer = new Timer(\n EventMethod,\n null,\n firstInterval,\n DateTime.Today.AddDays(1).AddHours(12).Subtract(DateTime.Now)\n );\n };\n\n // no need to await this call here because this task is scheduled to run later.\n Task.Run(action);\n return Task.CompletedTask;\n}\n\nprivate async void EventMethod(object state)\n{\n // do work\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392/"
] |
307,821 | <p>I am using my own custom authentication with IIS, and I want the server on <i>every</i> page load (no matter what type of file) to first check the Application variable to see if the user is authenticated and authorized to see the site. In global.asax this could be:</p>
<pre><code>void Application_Start(Object Sender, EventArgs e)
{
if(Application["username"] == null)
{
Response.redirect("login.aspx");
}
}
</code></pre>
<p>The problem is that this site has multiple sub-roots. That is, <a href="http://example.com/site1" rel="noreferrer">http://example.com/site1</a> is a completely different website from <a href="http://example.com/site2" rel="noreferrer">http://example.com/site2</a> . Therefore, I would like said Application_Start function to work on site1 but not affect site2.</p>
<p>If global.asax was customizable at directory level, then this wouldn't be a problem. But since there is only one global.asax per <i>server</i> I cannot implement this solution.</p>
<p>What alternatives are there to global.asax? or can global.asax be different somehow for each directory?</p>
| [
{
"answer_id": 307822,
"author": "Alexander Bird",
"author_id": 10608,
"author_profile": "https://Stackoverflow.com/users/10608",
"pm_score": 4,
"selected": true,
"text": "response.redirect(\"login.aspx\")"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10608/"
] |
307,828 | <p>I accidentally committed an unwanted file (<code>filename.orig</code> while resolving a merge) to my repository several commits ago, without me noticing it until now. I want to completely delete the file from the repository history. </p>
<p>Is it possible to rewrite the change history such that <code>filename.orig</code> was never added to the repository in the first place?</p>
| [
{
"answer_id": 308355,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 0,
"selected": false,
"text": "git filter-branch"
},
{
"answer_id": 308684,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 9,
"selected": true,
"text": "filter-branch"
},
{
"answer_id": 646694,
"author": "Schwern",
"author_id": 14660,
"author_profile": "https://Stackoverflow.com/users/14660",
"pm_score": 7,
"selected": false,
"text": "git rm"
},
{
"answer_id": 1371374,
"author": "paolo granada lim",
"author_id": 167646,
"author_profile": "https://Stackoverflow.com/users/167646",
"pm_score": -1,
"selected": false,
"text": "git reset HEAD file/path"
},
{
"answer_id": 2197616,
"author": "Darren",
"author_id": 265931,
"author_profile": "https://Stackoverflow.com/users/265931",
"pm_score": 6,
"selected": false,
"text": "*.gz"
},
{
"answer_id": 15729420,
"author": "Roberto Tyley",
"author_id": 438886,
"author_profile": "https://Stackoverflow.com/users/438886",
"pm_score": 5,
"selected": false,
"text": "git-filter-branch"
},
{
"answer_id": 19404364,
"author": "Sverrir Sigmundarson",
"author_id": 779521,
"author_profile": "https://Stackoverflow.com/users/779521",
"pm_score": 2,
"selected": false,
"text": "# Pick your commit with 'e'\n$ git rebase -i\n\n# Perform as many removes as necessary\n$ git rm project/code/file.txt\n\n# amend the commit\n$ git commit --amend\n\n# continue with rebase\n$ git rebase --continue\n"
},
{
"answer_id": 23188613,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 8,
"selected": false,
"text": "filename.orig"
},
{
"answer_id": 37266146,
"author": "lepe",
"author_id": 196507,
"author_profile": "https://Stackoverflow.com/users/196507",
"pm_score": 2,
"selected": false,
"text": "leontalbot"
},
{
"answer_id": 37741424,
"author": "paulalexandru",
"author_id": 3522687,
"author_profile": "https://Stackoverflow.com/users/3522687",
"pm_score": 4,
"selected": false,
"text": "You should probably clone your repository first.\n\nRemove your file from all branches history:\ngit filter-branch --tree-filter 'rm -f filename.orig' -- --all\n\nRemove your file just from the current branch:\ngit filter-branch --tree-filter 'rm -f filename.orig' -- --HEAD \n\nLastly you should run to remove empty commits:\ngit filter-branch -f --prune-empty -- --all\n"
},
{
"answer_id": 41936460,
"author": "nachoparker",
"author_id": 7445849,
"author_profile": "https://Stackoverflow.com/users/7445849",
"pm_score": 2,
"selected": false,
"text": "git filter-branch"
},
{
"answer_id": 49560100,
"author": "clarkttfu",
"author_id": 1999185,
"author_profile": "https://Stackoverflow.com/users/1999185",
"pm_score": 1,
"selected": false,
"text": "touch empty\ngit init\ngit add empty\ngit commit -m init\n\n# 92K .git\ndu -hs .git\n\ndd if=/dev/random of=./random bs=1m count=5\ngit add random\ngit commit -m mistake\n\n# 5.1M .git\ndu -hs .git\n\ngit reset --hard HEAD^\ngit reflog expire --expire=now --all\ngit gc --prune=now\n\n# 92K .git\ndu -hs .git\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27314/"
] |
307,832 | <p>I would like to learn the best practices in reloading the application state, such that when my app is started, it should automatically load the "correct" view/subview when it is opened again.</p>
<p>In my particular case, my app has a bunch of view controllers, each taking care of a UITableView. I would like for my app to "jump" to the correct node within my table view hierarchy when it is opened again.</p>
| [
{
"answer_id": 307880,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 4,
"selected": true,
"text": "[navigationController pushViewController: viewController animated: NO]"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35478/"
] |
307,845 | <p>I am trying to add a <code>UIButton</code> at runtime however it is not visible. What am I doing wrong?</p>
<pre><code>- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
UIButton *btn = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
btn.frame = CGRectMake(0, 0, 100, 25);
btn.backgroundColor = [UIColor clearColor];
[btn setTitle:@"Play" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonClick:)
forControlEvents:UIControlEventTouchUpInside];
btn.center = self.center;
[self addSubview:btn];
}
return self;
}
</code></pre>
| [
{
"answer_id": 3888919,
"author": "NguyenHungA5",
"author_id": 470028,
"author_profile": "https://Stackoverflow.com/users/470028",
"pm_score": 1,
"selected": false,
"text": "btn"
},
{
"answer_id": 9774714,
"author": "kumar123",
"author_id": 579511,
"author_profile": "https://Stackoverflow.com/users/579511",
"pm_score": 0,
"selected": false,
"text": "NSArray *xibviews = [[NSBundle mainBundle] loadNibNamed: @\"MySubview\" owner: mySubview options: NULL];\nMySubview *msView = [xibviews objectAtIndex: 0];\n[self.view addSubview:msView]; \n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30099/"
] |
307,855 | <p>So, I'm working on some network programming in C, and it would seem that I am missing a bunch of standard C/C++ header files. For example, <code>sys/socket.h</code> is not there. A few otheres are missing too like <code>netdb.h</code>, and <code>unistd.h</code>. Is there a pack I need to install to get these on windows?</p>
<p>Thanks</p>
| [
{
"answer_id": 307902,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 3,
"selected": true,
"text": "#define strtok_r strtok_s"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2128/"
] |
307,857 | <p>I would like to completely reset the scroll position of a UITableView, so that every time I open it, it is displaying the top-most items. In other words, I would like to scroll the table view to the top every time it is opened.</p>
<p>I tried using the following piece of code, but it looks like I misunderstood the documentation:</p>
<pre><code>- (void)viewWillAppear:(BOOL)animated {
[tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:NO];
}
</code></pre>
<p>Is this the wrong approach here?</p>
| [
{
"answer_id": 307922,
"author": "August",
"author_id": 30966,
"author_profile": "https://Stackoverflow.com/users/30966",
"pm_score": 3,
"selected": false,
"text": "scrollToRowAtIndexPath:atScrollPosition:animated:\n"
},
{
"answer_id": 307960,
"author": "Mike McMaster",
"author_id": 544,
"author_profile": "https://Stackoverflow.com/users/544",
"pm_score": 6,
"selected": true,
"text": "[tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];\n"
},
{
"answer_id": 50161222,
"author": "Roberto LL",
"author_id": 5724513,
"author_profile": "https://Stackoverflow.com/users/5724513",
"pm_score": 0,
"selected": false,
"text": "self.tableView.contentOffset = CGPoint.zero\nDispatchQueue.main.async {\n self.tableView.reloadData()\n}\n"
},
{
"answer_id": 66870992,
"author": "sash",
"author_id": 1757229,
"author_profile": "https://Stackoverflow.com/users/1757229",
"pm_score": 0,
"selected": false,
"text": "self.tableView.scrollRectToVisible(CGRect.zero, animated: false)\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35478/"
] |
307,859 | <p>I'd like to skip the tests and create a (default) Makefile.</p>
| [
{
"answer_id": 307889,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 2,
"selected": false,
"text": "CC=g++\nCFLAGS=-c -Wall\nLDFLAGS=\nSOURCES=main.cpp hello.cpp\nOBJECTS=$(SOURCES:.cpp=.o)\nEXECUTABLE=hello\n\nall: $(SOURCES) $(EXECUTABLE)\n\n$(EXECUTABLE): $(OBJECTS) \n $(CC) $(LDFLAGS) $(OBJECTS) -o $@\n\n.cpp.o:\n $(CC) $(CFLAGS) $< -o $@\n"
},
{
"answer_id": 308047,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 0,
"selected": false,
"text": "use ExtUtils::MakeMaker;\n\nWriteMakefile(\n 'NAME' => 'Foo::Bar',\n 'DISTNAME' => 'Foo-Bar',\n 'EXE_FILES' => [\"foobar.sh\"],\n 'VERSION_FROM' => 'lib/Foo/Bar.pm',\n );\n"
},
{
"answer_id": 308178,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 1,
"selected": false,
"text": "./configure"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307859",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,882 | <p>jQuery's <code>draggable</code> functionality doesn't seem to work on tables (in FF3 or Safari). It's kind of difficult to envision how this <em>would</em> work, so it's not really surprising that it doesn't.</p>
<pre><code><html>
<style type='text/css'>
div.table { display: table; }
div.row { display: table-row; }
div.cell { display: table-cell; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/ui.core.js"></script>
<script src="http://dev.jquery.com/view/tags/ui/latest/ui/ui.draggable.js"></script>
<script>
$(document).ready(function(){
$(".row").draggable();
});
</script>
<body>
<div class='table'>
<div class='row'>
<div class='cell'>Foo</div>
<div class='cell'>Bar</div>
</div>
<div class='row'>
<div class='cell'>Spam</div>
<div class='cell'>Eggs</div>
</div>
</div>
<table>
<tr class'row'><td>Foo</td><td>Bar</td></tr>
<tr class='row'><td>Spam</td><td>Eggs</td></tr>
</table>
</body>
</html>
</code></pre>
<p>I'm was wondering a) if there's any specific reason why this doesn't work (from a w3c/HTML spec perspective) and b) what the right way to go about getting draggable table rows is.</p>
<p>I like real tables because of the border collapsing and row height algorithm -- any alternative that can do those things would work fine.</p>
| [
{
"answer_id": 2231845,
"author": "Ariel Popovsky",
"author_id": 29804,
"author_profile": "https://Stackoverflow.com/users/29804",
"pm_score": 5,
"selected": false,
"text": "helper: function(event){\nreturn $('<div class=\"drag-cart-item\"><table></table></div>').find('table').append($(event.target).closest('tr').clone()).end();\n},\n"
},
{
"answer_id": 8941819,
"author": "Andrei",
"author_id": 179581,
"author_profile": "https://Stackoverflow.com/users/179581",
"pm_score": 0,
"selected": false,
"text": "tr.ui-draggable-dragging {display: block}"
},
{
"answer_id": 12092398,
"author": "sevmusic",
"author_id": 916581,
"author_profile": "https://Stackoverflow.com/users/916581",
"pm_score": 1,
"selected": false,
"text": "$(function() {\n $(\".sortable\").sortable({\n revert: true\n });\n});"
},
{
"answer_id": 16390550,
"author": "Rn2dy",
"author_id": 376753,
"author_profile": "https://Stackoverflow.com/users/376753",
"pm_score": 2,
"selected": false,
"text": "<tr>"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
307,929 | <p>If I have a query such as <code>SELECT * from authors where name = @name_param</code>, is there a regex to parse out the parameter names (specifically the "name_param")?</p>
<p>Thanks</p>
| [
{
"answer_id": 307957,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 3,
"selected": false,
"text": "SELECT * FROM authors WHERE name = @name_param \n AND string = 'don\\'t use @name_param';\n"
},
{
"answer_id": 308162,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 2,
"selected": false,
"text": "@([_a-zA-Z]+) /* match group 1 contains the name only */\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
307,939 | <p>In java, does <code>file.delete()</code> return <code>true</code> or <code>false</code> where <code>File file</code> refers to a non-existent file?</p>
<p>I realize this is kind of a basic question, and easy to very through test, but I'm getting strange results and would appreciate confirmation.</p>
| [
{
"answer_id": 307952,
"author": "Steve B.",
"author_id": 19479,
"author_profile": "https://Stackoverflow.com/users/19479",
"pm_score": 2,
"selected": false,
"text": "Deletes the file or directory denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty in order to be deleted.\n\nReturns:\n true if and only if the file or directory is successfully deleted; false otherwise \nThrows:\n SecurityException - If a security manager exists and its SecurityManager.checkDelete(java.lang.String) method denies delete access to the file\n"
},
{
"answer_id": 307953,
"author": "Daniel Hiller",
"author_id": 16193,
"author_profile": "https://Stackoverflow.com/users/16193",
"pm_score": 4,
"selected": true,
"text": "import java.io.File;\n\npublic class FileDoesNotExistTest {\n\n\n public static void main( String[] args ) {\n final boolean result = new File( \"test\" ).delete();\n System.out.println( \"result: |\" + result + \"|\" );\n }\n}\n"
},
{
"answer_id": 307954,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 3,
"selected": false,
"text": "import java.io.File;\n\npublic class FileTest\n{\n public static void main(String[] args)\n {\n File file = new File(\"non-existent file\");\n\n boolean result = file.delete();\n System.out.println(result);\n }\n}"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20498/"
] |
307,941 | <p>I've connected to a MySQL database using Perl DBI. I would like to find out which database I'm connected to.</p>
<p>I don't think I can use:</p>
<pre><code>$dbh->{Name}
</code></pre>
<p>because I call <a href="http://dev.mysql.com/doc/refman/5.0/en/use.html" rel="noreferrer"><code>USE new_database</code></a> and <code>$dbh->{Name}</code> only reports the database that I initially connected to.</p>
<p>Is there any trick or do I need to keep track of the database name?</p>
| [
{
"answer_id": 307972,
"author": "ysth",
"author_id": 17389,
"author_profile": "https://Stackoverflow.com/users/17389",
"pm_score": 1,
"selected": false,
"text": "($dbname) = (each %{$dbh->selectrow_hashref(\"show tables\")}) =~ /^Tables_in_(.*)/;\n"
},
{
"answer_id": 307975,
"author": "Rizwan Kassim",
"author_id": 35335,
"author_profile": "https://Stackoverflow.com/users/35335",
"pm_score": 5,
"selected": true,
"text": "select DATABASE();\n"
},
{
"answer_id": 307979,
"author": "Chris Kloberdanz",
"author_id": 28714,
"author_profile": "https://Stackoverflow.com/users/28714",
"pm_score": 0,
"selected": false,
"text": "USE database_name"
},
{
"answer_id": 308116,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 0,
"selected": false,
"text": "$dbh->{Name}"
},
{
"answer_id": 4634238,
"author": "hornetbzz",
"author_id": 461212,
"author_profile": "https://Stackoverflow.com/users/461212",
"pm_score": 2,
"selected": false,
"text": "$dbh->{Name}"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4704/"
] |
307,942 | <p>OK, so Sybase (12.5.4) will let me do the following to DROP a table if it already exists:</p>
<pre><code>IF EXISTS (
SELECT 1
FROM sysobjects
WHERE name = 'a_table'
AND type = 'U'
)
DROP TABLE a_table
GO
</code></pre>
<p>But if I try to do the same with table creation, I always get warned that the table already exists, because it went ahead and tried to create my table and ignored the conditional statement. Just try running the following statement twice, you'll see what I mean:</p>
<pre><code>IF NOT EXISTS (
SELECT 1
FROM sysobjects
WHERE name = 'a_table'
AND type = 'U'
)
CREATE TABLE a_table (
col1 int not null,
col2 int null
)
GO
</code></pre>
<p>Running the above produces the following error:</p>
<blockquote>
<p><em>SQL Server Error on (localhost)
Error:2714 at Line:7 Message:There is
already an object named 'a_table' in
the database.</em></p>
</blockquote>
<p>What's the deal with that?!</p>
| [
{
"answer_id": 307958,
"author": "Eugene Yokota",
"author_id": 3827,
"author_profile": "https://Stackoverflow.com/users/3827",
"pm_score": -1,
"selected": false,
"text": "IF object_id('a_table') IS NULL\nBEGIN\n CREATE TABLE a_table (\n col1 int not null,\n col2 int null\n ) \nEND\n"
},
{
"answer_id": 307991,
"author": "ninesided",
"author_id": 1030,
"author_profile": "https://Stackoverflow.com/users/1030",
"pm_score": 5,
"selected": true,
"text": "IF NOT EXISTS (\n SELECT 1\n FROM sysobjects\n WHERE name = 'a_table'\n AND type = 'U'\n)\nEXECUTE(\"CREATE TABLE a_table (\n col1 int not null,\n col2 int null\n)\")\nGO\n"
},
{
"answer_id": 1947502,
"author": "Vinay",
"author_id": 237001,
"author_profile": "https://Stackoverflow.com/users/237001",
"pm_score": 3,
"selected": false,
"text": "create table"
},
{
"answer_id": 5067536,
"author": "Mark Rhodes",
"author_id": 509619,
"author_profile": "https://Stackoverflow.com/users/509619",
"pm_score": 1,
"selected": false,
"text": "IF(SELECT count(*) FROM sysobjects WHERE name=\"tableNameWithoutUserPart\") > 0\n DROP TABLE tableNameWithUserPart\nGO\n\nCREATE TABLE tableNameWithUserPart ...\n"
},
{
"answer_id": 13193330,
"author": "Diego Frehner",
"author_id": 715223,
"author_profile": "https://Stackoverflow.com/users/715223",
"pm_score": 0,
"selected": false,
"text": "CREATE [ GLOBAL TEMPORARY ] TABLE [ IF NOT EXISTS ] [ owner.]table-name\n( { column-definition | table-constraint | pctfree }, ... )\n[ { IN | ON } dbspace-name ]\n[ ENCRYPTED ]\n[ ON COMMIT { DELETE | PRESERVE } ROWS\n | NOT TRANSACTIONAL ]\n[ AT location-string ]\n[ SHARE BY ALL ]\n"
},
{
"answer_id": 27987467,
"author": "Peter Cichoszewski",
"author_id": 4462235,
"author_profile": "https://Stackoverflow.com/users/4462235",
"pm_score": -1,
"selected": false,
"text": "if not exists(select * from SysColumns where tname = 'AAA') then create table DBA.AAA( UNIQUEID integer not null ) END IF ;\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307942",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1030/"
] |
307,951 | <p>I run an OpenSuse server that uploads zipped source code backups to a Microsoft FTP server every night. I have written a Bash script that does this through a cron job.</p>
<p>I want to delete backed up files that are older than a certain date. How could I do this?</p>
| [
{
"answer_id": 307958,
"author": "Eugene Yokota",
"author_id": 3827,
"author_profile": "https://Stackoverflow.com/users/3827",
"pm_score": -1,
"selected": false,
"text": "IF object_id('a_table') IS NULL\nBEGIN\n CREATE TABLE a_table (\n col1 int not null,\n col2 int null\n ) \nEND\n"
},
{
"answer_id": 307991,
"author": "ninesided",
"author_id": 1030,
"author_profile": "https://Stackoverflow.com/users/1030",
"pm_score": 5,
"selected": true,
"text": "IF NOT EXISTS (\n SELECT 1\n FROM sysobjects\n WHERE name = 'a_table'\n AND type = 'U'\n)\nEXECUTE(\"CREATE TABLE a_table (\n col1 int not null,\n col2 int null\n)\")\nGO\n"
},
{
"answer_id": 1947502,
"author": "Vinay",
"author_id": 237001,
"author_profile": "https://Stackoverflow.com/users/237001",
"pm_score": 3,
"selected": false,
"text": "create table"
},
{
"answer_id": 5067536,
"author": "Mark Rhodes",
"author_id": 509619,
"author_profile": "https://Stackoverflow.com/users/509619",
"pm_score": 1,
"selected": false,
"text": "IF(SELECT count(*) FROM sysobjects WHERE name=\"tableNameWithoutUserPart\") > 0\n DROP TABLE tableNameWithUserPart\nGO\n\nCREATE TABLE tableNameWithUserPart ...\n"
},
{
"answer_id": 13193330,
"author": "Diego Frehner",
"author_id": 715223,
"author_profile": "https://Stackoverflow.com/users/715223",
"pm_score": 0,
"selected": false,
"text": "CREATE [ GLOBAL TEMPORARY ] TABLE [ IF NOT EXISTS ] [ owner.]table-name\n( { column-definition | table-constraint | pctfree }, ... )\n[ { IN | ON } dbspace-name ]\n[ ENCRYPTED ]\n[ ON COMMIT { DELETE | PRESERVE } ROWS\n | NOT TRANSACTIONAL ]\n[ AT location-string ]\n[ SHARE BY ALL ]\n"
},
{
"answer_id": 27987467,
"author": "Peter Cichoszewski",
"author_id": 4462235,
"author_profile": "https://Stackoverflow.com/users/4462235",
"pm_score": -1,
"selected": false,
"text": "if not exists(select * from SysColumns where tname = 'AAA') then create table DBA.AAA( UNIQUEID integer not null ) END IF ;\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307951",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1264322/"
] |
307,964 | <p>I am developing an online examination using servlets/jsp.I need to add a count down (hh/mm/ss) timer to the questions page that would end the exam and redirects to results page.</p>
<p>I am done with all the other functionalities except the timer one.</p>
<p>Can someone provide some help on this.</p>
<p>Thanks</p>
| [
{
"answer_id": 6072810,
"author": "sachin",
"author_id": 762833,
"author_profile": "https://Stackoverflow.com/users/762833",
"pm_score": 1,
"selected": false,
"text": "<html>\n<%@page session=\"false\" %>\n<%\nHttpSession s=request.getSession(false);\n\nif(s==null) { %>\n\n <jsp:forward page=\"/Expired\" />\n<% } %>\n<% String duration=(String)s.getAttribute(\"duration\"); %>\n<% int a=Integer.parseInt(duration); %>\n<head><title></title>\n<script type=\"text/javascript\">\nvar cmin=<%= a %>;\nvar total=cmin*60;\ncmin=cmin-1;\nvar ctr=0;\nvar dom=document.getElementById(\"kulu\");\nfunction ram(){\nvar dom=document.getElementById(\"kulu\");\ndom.value=(cmin)+\"minutes\"+(total%60)+\"seconds\";\n<% String t=(String)s.getAttribute(\"over\"); %>\nvar tt=<%= t %>\nif(tt==\"false\"){ram1();}\ntotal=total-1;ctr++;\nif(ctr==60){ctr=0;cmin=cmin-1;}\nif(total==0){\nram1();}\nsetTimeout(\"ram()\", 1000);\n }\nfunction ram1(){\n\nwindow.location.replace(\"/hcl/TTimeUp.jsp\");\n\n }\n</script>\n</head>\n<body background=\"image/background.gif\" onload=\"ram()\"><center>\n<form name=\"form1\">\n<input type=\"text\" id=\"kulu\"/>\n</form>\n</center>\n</body>\n</html>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11193/"
] |
307,968 | <p>I lost my installation of Dave Gillespie's calc.el by reinstalling Cygwin. It is not included with the default Cygwin install of Emacs. Who is considered the master maintainer these days? Is version 2.02f still most current?</p>
| [
{
"answer_id": 308001,
"author": "Jouni K. Seppänen",
"author_id": 26575,
"author_profile": "https://Stackoverflow.com/users/26575",
"pm_score": 2,
"selected": false,
"text": "cvs -d:pserver:anonymous@cvs.sv.gnu.org:/sources/emacs co emacs/lisp/calc\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39526/"
] |
307,984 | <p>Is it possible to declare an instance of a generic without knowing the type at design-time?</p>
<p>Example:</p>
<pre><code>Int i = 1;
List<typeof(i)> list = new List<typeof(i)>();
</code></pre>
<p>where the type of i could be anything, instead of having to do:</p>
<pre><code>List<int> list = new List<int();
</code></pre>
| [
{
"answer_id": 308006,
"author": "Nathan",
"author_id": 24954,
"author_profile": "https://Stackoverflow.com/users/24954",
"pm_score": 1,
"selected": false,
"text": "static void Main(string[] args)\n{\n int i = 1;\n var thelist = CreateList(i);\n}\n\npublic static List<T> CreateList<T>(T t)\n{\n return new List<T>();\n}\n"
},
{
"answer_id": 308013,
"author": "abelenky",
"author_id": 34824,
"author_profile": "https://Stackoverflow.com/users/34824",
"pm_score": 2,
"selected": false,
"text": "List<object> list = new List<object>();\n"
},
{
"answer_id": 308018,
"author": "KevinT",
"author_id": 39561,
"author_profile": "https://Stackoverflow.com/users/39561",
"pm_score": 1,
"selected": false,
"text": "public class BaseRepository<T> where T : DataContext\n{\n protected T _dc;\n\n public BaseRepository(string connectionString)\n {\n _dc = (T) Activator.CreateInstance(typeof(T), connectionString);\n }\n\n public void SubmitChanges()\n {\n _dc.SubmitChanges();\n }\n}\n"
},
{
"answer_id": 308040,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": true,
"text": "List<object>"
},
{
"answer_id": 309710,
"author": "baretta",
"author_id": 30052,
"author_profile": "https://Stackoverflow.com/users/30052",
"pm_score": 0,
"selected": false,
"text": "Type T = typeof ( string ); // replace with actual T\nstring typeName = string.Format (\n \"System.Collections.Generic.List`1[[{0}]], mscorlib\", T.AssemblyQualifiedName );\n\nIList list = Activator.CreateInstance ( Type.GetType ( typeName ) )\n as IList;\n\nSystem.Diagnostics.Debug.Assert ( list != null ); //\n\nlist.Add ( \"string 1\" ); // new T\nlist.Add ( \"string 2\" ); // new T\nforeach ( object item in list )\n{\n Console.WriteLine ( \"item: {0}\", item );\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/307984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4490/"
] |
308,019 | <p>I have this line of JavaScript and the behavior I am seeing is that the <code>selectedLi</code> instantly disappears without "sliding up". This is not the behavior that I expected.</p>
<p>What should I be doing so that the <code>selectedLi</code> slides up before it is removed?</p>
<pre><code>selectedLi.slideUp("normal").remove();
</code></pre>
| [
{
"answer_id": 308034,
"author": "seanb",
"author_id": 3354,
"author_profile": "https://Stackoverflow.com/users/3354",
"pm_score": 9,
"selected": true,
"text": "selectedLi.slideUp(\"normal\", function() { $(this).remove(); } );\n"
},
{
"answer_id": 310278,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "selectedLi.slideUp(200, this.remove);\n"
},
{
"answer_id": 4817127,
"author": "Blake",
"author_id": 592278,
"author_profile": "https://Stackoverflow.com/users/592278",
"pm_score": 5,
"selected": false,
"text": "$(\"#yourdiv\").slideUp(1000, function() {\n $(this).remove();\n});\n"
},
{
"answer_id": 17024345,
"author": "xaviqv",
"author_id": 1910848,
"author_profile": "https://Stackoverflow.com/users/1910848",
"pm_score": 3,
"selected": false,
"text": "$(\"#yourdiv\").slideUp(\"normal\", function() {\n $(this).remove();\n});\n"
},
{
"answer_id": 28855276,
"author": "famousgarkin",
"author_id": 681785,
"author_profile": "https://Stackoverflow.com/users/681785",
"pm_score": 2,
"selected": false,
"text": "selectedLi.slideUp({duration: 5000, queue: false})\n.fadeOut({duration: 3000, queue: false})\n.promise().done(function() {\n selectedLi.remove()\n})\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308019",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] |
308,027 | <p>I think my eclipse's ctrl+clicking links might benefit greatly...</p>
<p><b>Edit:</b> I'm using eclipse PDT.</p>
<p><b>Edit 2:</b> I'm very happy with the solution of putting docblocks before functions (and variables) with an @return or @var statement, I've just updated the documentation of my app and now eclipse is showing me what functions are available to what objects!</p>
<p>Awesome.</p>
| [
{
"answer_id": 308137,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 5,
"selected": true,
"text": "// [...]\n/**\n * Return the Request object\n *\n * @return Zend_Controller_Request_Abstract\n */\npublic function getRequest()\n{\n return $this->_request;\n}\n// [...]\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308027",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14966/"
] |
308,044 | <p>The first thing I do when I incorporate any third party code into my application is reformat it to my personal coding preference:</p>
<pre><code>// Single line comments only
// I never put spaces inside my parenthesis
-(void)myOCDMethod
{
// If an if or for statement has only one instruction, I don't use brackets
if(this)
[self that];
else
[self somethingElse];
// If I do have to use brackets, they go on their own lines so that they line up
if(this)
{
[self that];
[self andThat];
}
// I always put the pointer asterisk next to the instance name
NSObject *variable = [[NSObject alloc] init];
// I always put spaces around operators
if(i == 0)
x = 2;
}
</code></pre>
<p>What OCD coding format do you use?</p>
| [
{
"answer_id": 308799,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 2,
"selected": false,
"text": " -(void)myOCDMethod -> - (void) myOCDMethod"
},
{
"answer_id": 308909,
"author": "Sergey Borodavkin",
"author_id": 39614,
"author_profile": "https://Stackoverflow.com/users/39614",
"pm_score": 2,
"selected": false,
"text": "int n;\ndouble d;\n"
},
{
"answer_id": 11378119,
"author": "Nicolas Miari",
"author_id": 433373,
"author_profile": "https://Stackoverflow.com/users/433373",
"pm_score": 0,
"selected": false,
"text": "NSString* aString;\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308044",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28106/"
] |
308,046 | <p>So I'm doing this in PHP but it is a logic issue so I'll try to write it as generically as possible.</p>
<p>To start here's how this pagination script works:</p>
<ol>
<li>for (<em>draw first three pages links</em>)</li>
<li>if (<em>draw ellipsis (...) if there are pages between #1's pages and #3's pages</em>)</li>
<li>for (<em>draw current page and two pages on each side of it links</em>)</li>
<li>if (<em>draw elipsis (...) if there are pages between #3's pages and #5's pages</em>)</li>
<li>for (<em>draw final three pages links</em>)</li>
</ol>
<p>The problem is that when there are low amounts of pages (I noticed this when the page count was at 10) there should be an ellipsis but none is drawn.</p>
<p>Onto the code:</p>
<pre><code>$page_count = 10; //in actual code this is set properly
$current_page = 1; //in actual code this is set properly
for ($i = 1;$i <= 3;$i++)
{
if ($page_count >= $i)
echo $i;
}
if ($page_count > 3 && $current_page >= 7)
echo "...";
for ($i = $current_page - 2;$i <= current_page + 2;$i++)
{
if ($i > 3 && $i < $page_count - 2)
echo $i;
}
if ($page_count > 13 && $current_page < $page_count - 5)
echo "...";
for ($i = $page_count - 2;$i <= $page_count;$i++)
{
if ($page_count > 3)
echo $i;
}
</code></pre>
<p>So I figure the best idea would to be to modify one of the two ellipsis if statements to include a case like this, however I've tried and am stumped.</p>
<p>Also please note that I condensed this code for readability sake so please don't give tips like "those for loops are ineffective because they will recalculate current_page - 2 for each iteration" because I know :)</p>
<hr>
<p>For those whom want to see a breakdown of how this logic currently works, here is example output ( modified ) with iterating $page_count and $current_page.
<a href="http://rafb.net/p/TNa56h71.html" rel="nofollow noreferrer">http://rafb.net/p/TNa56h71.html</a></p>
| [
{
"answer_id": 308106,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "function cdotinator ( $current_page, $page_count ) \n{\n $stepsize = 3; \n $elipse = '...';\n # Simple Case. \n if ( $page_count <= 2 * $stepsize )\n {\n $out = range( 1, $page_count );\n $out[$current_page - 1 ] = '*' . $current_page . '*';\n return $out;\n }\n #Complex Case\n # 1) Create All Pages\n $out = range( 1, $page_count ); \n # 2 ) Replace \"middle\" pages with \".\" placeholder elements \n for( $i = $stepsize+1 ; $i <= ( $page_count - $stepsize ) ; $i ++ )\n {\n $out[ $i - 1 ] = '.' ; \n }\n # 3.1 ) Insert the pages around the current page \n for( $i = max(1,( $current_page - floor($stepsize / 2) )) ;\n $i <= min( $page_count,( $current_page + floor( $stepsize/2))); \n $i ++ )\n {\n $out[ $i - 1] = $i;\n }\n # 3.2 Bold Current Item\n $out[ $current_page - 1 ] = '*' . $current_page . '*' ; \n\n # 4 ) Grep out repeated '.' sequences and replace them with elipses \n $out2 = array(); \n foreach( $out as $i => $v )\n {\n # end, current == peek() \n end($out2);\n if( current($out2) == $elipse and $v == '.' )\n {\n continue;\n }\n if( $v == '.' )\n {\n $out2[] = $elipse; \n continue;\n }\n $out2[]= $v;\n }\n\n return $out2;\n\n}\n"
},
{
"answer_id": 308161,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": true,
"text": "<?php\n\n/**\n * windowsize must be odd\n *\n * @param int $totalItems \n * @param int $currentPage \n * @param int $windowSize \n * @param int $anchorSize \n * @param int $itemsPerPage \n * @return void\n */\nfunction paginate($totalItems, $currentPage=1, $windowSize=3, $anchorSize=3, $itemsPerPage=10) {\n $halfWindowSize = ($windowSize-1)/2;\n\n $totalPages = ceil($totalItems / $itemsPerPage);\n $elipsesCount = 0;\n for ($page = 1; $page <= $totalPages; $page++) {\n // do we display a link for this page or not?\n if ( $page <= $anchorSize || \n $page > $totalPages - $anchorSize ||\n ($page >= $currentPage - $halfWindowSize &&\n $page <= $currentPage + $halfWindowSize) ||\n ($page == $anchorSize + 1 &&\n $page == $currentPage - $halfWindowSize - 1) ||\n ($page == $totalPages - $anchorSize && \n $page == $currentPage + $halfWindowSize + 1 ))\n {\n $elipsesCount = 0;\n if ($page == $currentPage)\n echo \">$page< \";\n else\n echo \"[$page] \";\n // if not, have we already shown the elipses?\n } elseif ($elipsesCount == 0) {\n echo \"... \";\n $elipsesCount+=1; // make sure we only show it once\n }\n }\n echo \"\\n\";\n}\n\n//\n// Examples and output\n//\n\npaginate(1000, 1, 3, 3);\n// >1< [2] [3] ... [98] [99] [100] \n\npaginate(1000, 7, 3, 3);\n// [1] [2] [3] ... [6] >7< [8] ... [98] [99] [100] \n\npaginate(1000, 4, 3, 3);\n// [1] [2] [3] >4< [5] ... [98] [99] [100] \n\npaginate(1000, 32, 3, 3);\n// [1] [2] [3] ... [31] >32< [33] ... [98] [99] [100] \n\npaginate(1000, 42, 7, 2);\n// [1] [2] ... [39] [40] [41] >42< [43] [44] [45] ... [99] [100] \n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/428190/"
] |
308,054 | <p>It's kind of embarassing that I find it so difficult to learn JavaScript, but .. </p>
<p>Let's say I have a really simple controller like this:</p>
<pre><code>class front extends Controller {
public function __construct()
{
parent::Controller();
}
public function index()
{
//nothing!
}
public function test () {
$someNumber = $this->input->post('someNumber');
if ($someNumber == 12) { return TRUE; }
}
}
</code></pre>
<p>Yes, that could probably be written better, haha. </p>
<p>What I want to know is - how could I use JavaScript to submit a number in a form (I'll worry about validation and models later), how should I write my test() function so that it returns something readable by the JavaScript (I'm assuming return TRUE probably wouldn't work, perhaps XML or JSON or something like that?), and how do I access the data with the JavaScript? </p>
<p>I know there are frameworks like jQuery that will help with this, but right now I'd just like to understand it at the simplest level and all the tutorials and guides I've found so far are way too in depth for me. An example in jQuery or whatever would be good too. </p>
<p>Thanks a lot :)</p>
| [
{
"answer_id": 308127,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": false,
"text": "public function test() {\n $somenumber = $this->input->post('someNumber');\n if ($somenumber == 12) {\n print \"Number is 12\";\n } else {\n print \"Number is not 12\";\n }\n}\n"
},
{
"answer_id": 8520381,
"author": "Phil Lowe",
"author_id": 1099873,
"author_profile": "https://Stackoverflow.com/users/1099873",
"pm_score": 2,
"selected": false,
"text": "$this->input->is_ajax_request();\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
308,059 | <p>I am trying to set up apache instead of IIS because <a href="https://stackoverflow.com/questions/188896/why-does-iis-crash-when-i-print-to-stderr-in-perl">IIS needlessly crashes</a> all the time, and it would be nice to be able to have my own checkout of the source instead of all of us editing a common checkout.</p>
<p>In IIS we <em>must</em> do something like this at the beginning of each file:</p>
<pre><code>use CGI;
my $input = new CGI();
print "HTTP/1.0 200 OK";
print $input->header();
</code></pre>
<p>whereas with apache we <em>must</em> leave off the 200 OK line. The following works with both:</p>
<pre><code>use CGI;
my $input = new CGI();
print $input->header('text/html','200 OK');
</code></pre>
<p>Can anyone explain why? And I was under the impression that the CGI module was supposed to figure out these kind of details automatically...</p>
<p>Thanks!</p>
<p><strong>Update</strong>: brian is right, nph fixes the problem for IIS, but it is still broken for Apache. I don't think it's worth it to have conditionals all over the code so I will just stick with the last method, which works with and without nph.</p>
| [
{
"answer_id": 308070,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 5,
"selected": true,
"text": "-nph"
},
{
"answer_id": 11138279,
"author": "Derek P",
"author_id": 1172324,
"author_profile": "https://Stackoverflow.com/users/1172324",
"pm_score": 0,
"selected": false,
"text": "$ENV{PerlXS} eq 'PerlIS'"
},
{
"answer_id": 38932650,
"author": "Michel",
"author_id": 6712496,
"author_profile": "https://Stackoverflow.com/users/6712496",
"pm_score": 0,
"selected": false,
"text": "binmode(STDOUT);\nmy $CRLF = \"\\r\\n\"; # \"\\015\\012\"; # ^M: \\x0D ^L: \\x0A\nprint \"HTTP/1.0 200 OK\",$CRLF if ($0 =~ m/nph-/o);\nprint \"Content-Type: text/plain\".$CRLF;\nprint $CRLF; print \"OK !\\n\";\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12448/"
] |
308,061 | <p>I was of the opinion that virtualization doesnt work in the super class constructor as per the design of OOP. For example, consider the following C# code. </p>
<pre><code>using System;
namespace Problem
{
public class BaseClass
{
public BaseClass()
{
Console.WriteLine("Hello, World!");
this.PrintRandom();
}
public virtual void PrintRandom()
{
Console.WriteLine("0");
}
}
public class Descendent : BaseClass
{
private Random randomValue;
public Descendent()
{
Console.WriteLine("Bonjour, Monde!");
randomValue = new Random();
}
public override void PrintRandom()
{
Console.WriteLine(randomValue.NextDouble().ToString());
}
public static void Main()
{
Descendent obj = new Descendent();
obj.PrintRandom();
Console.ReadLine();
}
}
}
</code></pre>
<p>This code breaks because when the object of Descendent is made, it calls the base class constructor and we have a virtual method call in Base Class constructor which in turn calls the Derived class's method and hence, it crashes since randomValue is not intialized by that time.</p>
<p>A similar code works in C++ because the call to PrintRandom is not routed to the derived class since IMO, the order in C++ is something like:</p>
<p><br>1. call for base class constructor
<br>2. Update V - Table for this class
<br>3. call the constructor code</p>
<p>My Question is that firstly whether I am right that as per OOP principles, virtualization shouldn't/doesn't work in the super class constructor and secondly if I am right, then why the behavior is different in all .NET languages ( I have tested it with C#, VB.NET and MC++)</p>
| [
{
"answer_id": 308092,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "random"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30341/"
] |
308,076 | <p>I want to spruce up some areas of my website with a few jQuery animations here and there, and I'm looking to replace my AJAX code entirely since my existing code is having some cross-browser compatibility issues. However, since jQuery is a JavaScript library, I'm worried about my pages not functioning correctly when JavaScript is turned off or doesn't exist in a user's browser.</p>
<p>I'll give an example: Currently, I'm using a pure CSS tooltip to give my users (players, the site is a browser game) information on other users. For example, if the other players in the game satisfy one or more conditions, a target icon is displayed next to their name, and upon hovering over that target icon information regarding the reasons behind the target is displayed. This is useful information, as it helps my players to know who they should plan to attack next in the game.</p>
<p>Currently, I do such tooltips using CSS. I have a parent div that holds the image of the target icon of class "info". I then have a div inside of that with class "tooltip" that, on the hover state of the "info" class that it is contained in, is shown, but on the normal state is hidden. I thought it was rather clever when I read about it, and since no JavaScript is used it works on any CSS compliant browser.</p>
<p>I would like to use jQuery to achieve the same effect, mostly because it would look much cleaner, but also because I believe quick and subtle animations can make such things "randomly appearing" make a lot more sense to the user, especially on the first encounter. I'm just wondering if the two will conflict. This is only one example of this, there are numerous other examples where the inability to use JavaScript would hinder the site.</p>
<p>So what I'm asking I guess is, how does one make a jQuery site degrade gracefully on browsers that do not support JavaScript, but otherwise <em>do</em> support most CSS? My goal is for the site to function on a basic level for all users, regardless of choice in browser. The animation is a good example, but I'm also worried about the more dynamic bits, like the auto-updating with AJAX, etc. Are there any good resources on how to achieve this, or do you have any advice about the best way such degradability could be achieved?</p>
<p>Thanks</p>
<p>PS: Totally irrelevant, but Firefox seems to think that "degradability" isn't a word, but "biodegradability" (with the "bio" prefix) is. Weird...</p>
| [
{
"answer_id": 308104,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": true,
"text": "a.info:hover span{ display:none}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19521/"
] |
308,081 | <p>For the iPhone, is it possible to configure a UITableView such that it will allow multiple-selection?</p>
<p>I've tried overriding <code>-setSelected:animated:</code> for each UITableViewCell, but trying to fudge the required behavior is tricky as it's difficult to separate the real unselections from the ones where the UITableView thinks I've unselected due to selection of another cell!</p>
<p>Hope someone can help!</p>
<p>Thanks,</p>
<p>Nick.</p>
| [
{
"answer_id": 675215,
"author": "Benjamin Ortuzar",
"author_id": 71560,
"author_profile": "https://Stackoverflow.com/users/71560",
"pm_score": 5,
"selected": false,
"text": " - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {\n\n UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];\n\n\n if (thisCell.accessoryType == UITableViewCellAccessoryNone) {\n thisCell.accessoryType = UITableViewCellAccessoryCheckmark;\n\n }else{\n thisCell.accessoryType = UITableViewCellAccessoryNone;\n\n }\n}\n\n- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {\n\n//add your own code to set the cell accesory type.\nreturn UITableViewCellAccessoryNone;\n}\n"
},
{
"answer_id": 3427944,
"author": "titaniumdecoy",
"author_id": 18091,
"author_profile": "https://Stackoverflow.com/users/18091",
"pm_score": 1,
"selected": false,
"text": "- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {\n return 3; // Undocumented constant\n}"
},
{
"answer_id": 8373451,
"author": "RolandasR",
"author_id": 199232,
"author_profile": "https://Stackoverflow.com/users/199232",
"pm_score": 4,
"selected": false,
"text": "allowsMultipleSelectionDuringEditing"
},
{
"answer_id": 9505028,
"author": "John Riselvato",
"author_id": 525576,
"author_profile": "https://Stackoverflow.com/users/525576",
"pm_score": 2,
"selected": false,
"text": "- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{\n int selectedRow = indexPath.row;\n cout << \"selected Row: \" << selectedRow << endl;\n UITableViewCell *indexPathForCell = [tableView cellForRowAtIndexPath:indexPath];\n if (indexPathForCell.accessoryType == UITableViewCellAccessoryNone) {\n indexPathForCell.accessoryType = UITableViewCellAccessoryCheckmark;\n } else {\n indexPathForCell.accessoryType = UITableViewCellAccessoryNone;\n }\n\n}\n"
},
{
"answer_id": 9969185,
"author": "Hamdi",
"author_id": 80738,
"author_profile": "https://Stackoverflow.com/users/80738",
"pm_score": 5,
"selected": false,
"text": "self.tableView.allowsMultipleSelection = YES;\n"
},
{
"answer_id": 13342399,
"author": "Adriana",
"author_id": 715417,
"author_profile": "https://Stackoverflow.com/users/715417",
"pm_score": 0,
"selected": false,
"text": "-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {\n\n if ([controller.searchResultsTableView respondsToSelector:@selector(allowsMultipleSelectionDuringEditing)]) {\n controller.searchResultsTableView.allowsMultipleSelectionDuringEditing = YES;\n }\n else {\n controller.searchResultsTableView.allowsSelectionDuringEditing = YES;\n }\n}\n\n- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath\n{\n return UITableViewCellAccessoryCheckmark;\n}\n"
},
{
"answer_id": 13828026,
"author": "Raphael Oliveira",
"author_id": 1792327,
"author_profile": "https://Stackoverflow.com/users/1792327",
"pm_score": 3,
"selected": false,
"text": "self.tableView.allowsMultipleSelection = YES;\n"
},
{
"answer_id": 14355829,
"author": "Omar Elgendy",
"author_id": 1760804,
"author_profile": "https://Stackoverflow.com/users/1760804",
"pm_score": 2,
"selected": false,
"text": "- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath\n{\n\n UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];\n if ( [array indexOfObject:indexPath] == NSNotFound ) {\n [array addObject:indexPath];\n cell.accessoryType = UITableViewCellAccessoryCheckmark;\n } else {\n [array removeObject:indexPath];\n cell.accessoryType = UITableViewCellAccessoryNone;\n }\n\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1221378/"
] |
308,085 | <p>I have a DataGridView that I want to query using Linq (C# WinForm). I want to "count" rows where a certain criteria is met. For example, </p>
<pre><code>variable1 = "count rows where ColumnBoxAge > 3 || < 5"
label1.Text = variable1
</code></pre>
<p>How to do this in C# WinForm using Linq?</p>
| [
{
"answer_id": 308148,
"author": "Ali Ersöz",
"author_id": 4215,
"author_profile": "https://Stackoverflow.com/users/4215",
"pm_score": 3,
"selected": true,
"text": "dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>(\"ageColumn\") > 3 ||\n c.Field<int>(\"ageColumn\") < 5).Count();\n"
},
{
"answer_id": 308166,
"author": "Ali Ersöz",
"author_id": 4215,
"author_profile": "https://Stackoverflow.com/users/4215",
"pm_score": 0,
"selected": false,
"text": "dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>(\"ageColumn\") > 3 &&\n c.Field<int>(\"ageColumn\") < 5).Count();\n"
},
{
"answer_id": 308173,
"author": "MarlonRibunal",
"author_id": 10385,
"author_profile": "https://Stackoverflow.com/users/10385",
"pm_score": 0,
"selected": false,
"text": "dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>(\"ageColumn\") > 3 &&\n c.Field<int>(\"ageColumn\") < 5).Count();\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308085",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10385/"
] |
308,109 | <p>I've noticed that in some lines of rails views, this is used:</p>
<pre><code><% # Code... -%>
</code></pre>
<p>instead of:</p>
<pre><code><% # Code... %>
</code></pre>
<p>What is the difference?</p>
| [
{
"answer_id": 308114,
"author": "dylanfm",
"author_id": 38795,
"author_profile": "https://Stackoverflow.com/users/38795",
"pm_score": 4,
"selected": false,
"text": " <ul>\n <% @posts.each do |post| -%> \n <li><%=post.title%></li>\n <% end -%>\n </ul>\n"
},
{
"answer_id": 311196,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<div>\n <% if @some_var == some_value %>\n <p>Some message</p>\n <% end %>\n</div>\n"
},
{
"answer_id": 311224,
"author": "Chris Lloyd",
"author_id": 42413,
"author_profile": "https://Stackoverflow.com/users/42413",
"pm_score": 3,
"selected": false,
"text": "<% %>"
},
{
"answer_id": 321273,
"author": "Chu Yeow",
"author_id": 25226,
"author_profile": "https://Stackoverflow.com/users/25226",
"pm_score": 1,
"selected": false,
"text": "<%- @posts.each do |post| -%>\n <li><%= post.title %></li>\n<%- end %>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36049/"
] |
308,122 | <p>What is the regular expression for a decimal with a precision of 2?</p>
<p><em>Valid examples</em>:</p>
<pre><code>123.12
2
56754
92929292929292.12
0.21
3.1
</code></pre>
<p><em>Invalid examples:</em></p>
<pre><code>12.1232
2.23332
e666.76
</code></pre>
<p>The decimal point may be optional, and integers may also be included.</p>
| [
{
"answer_id": 308124,
"author": "DocMax",
"author_id": 6234,
"author_profile": "https://Stackoverflow.com/users/6234",
"pm_score": 10,
"selected": true,
"text": "[0-9]+(\\.[0-9][0-9]?)?\n"
},
{
"answer_id": 308132,
"author": "spacemonkeys",
"author_id": 32336,
"author_profile": "https://Stackoverflow.com/users/32336",
"pm_score": 1,
"selected": false,
"text": "e"
},
{
"answer_id": 308216,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 8,
"selected": false,
"text": "^[0-9]+(\\.[0-9]{1,2})?$\n"
},
{
"answer_id": 3068537,
"author": "Karol Bienkowski",
"author_id": 370168,
"author_profile": "https://Stackoverflow.com/users/370168",
"pm_score": 4,
"selected": false,
"text": "015"
},
{
"answer_id": 6339290,
"author": "Android",
"author_id": 674530,
"author_profile": "https://Stackoverflow.com/users/674530",
"pm_score": 3,
"selected": false,
"text": " (\\\\+|-)?([0-9]+(\\\\.[0-9]+))\n"
},
{
"answer_id": 6677735,
"author": "DEC32",
"author_id": 842519,
"author_profile": "https://Stackoverflow.com/users/842519",
"pm_score": 2,
"selected": false,
"text": "preg_match(\"/^-?\\d+[\\.]?\\d\\d$/\", $sum)\n"
},
{
"answer_id": 7207421,
"author": "frustrated regex user",
"author_id": 914437,
"author_profile": "https://Stackoverflow.com/users/914437",
"pm_score": 3,
"selected": false,
"text": "(^(\\+|\\-)(0|([1-9][0-9]*))(\\.[0-9]{1,2})?$)|(^(0{0,1}|([1-9][0-9]*))(\\.[0-9]{1,2})?$)"
},
{
"answer_id": 7990697,
"author": "Premanshu",
"author_id": 987695,
"author_profile": "https://Stackoverflow.com/users/987695",
"pm_score": 1,
"selected": false,
"text": "+ | -"
},
{
"answer_id": 8920486,
"author": "Jimmy",
"author_id": 68936,
"author_profile": "https://Stackoverflow.com/users/68936",
"pm_score": 4,
"selected": false,
"text": "\\d+(\\.\\d{2})?|\\.\\d{2}\n"
},
{
"answer_id": 10942637,
"author": "Ken",
"author_id": 283311,
"author_profile": "https://Stackoverflow.com/users/283311",
"pm_score": 2,
"selected": false,
"text": "^-?(([1-9]\\d*)|0)(.0*[1-9](0*[1-9])*)?$"
},
{
"answer_id": 12327166,
"author": "BSharper",
"author_id": 1656004,
"author_profile": "https://Stackoverflow.com/users/1656004",
"pm_score": 3,
"selected": false,
"text": "^[0-9]+(\\.([0-9]{1,2})?)?$\n"
},
{
"answer_id": 23825245,
"author": "STEEL",
"author_id": 942317,
"author_profile": "https://Stackoverflow.com/users/942317",
"pm_score": 1,
"selected": false,
"text": "function getInteger(int){\n var regx = /^[-+]?[\\d.]+$/g;\n return regx.test(int);\n}\n\n\nalert(getInteger('-11.11'));\n"
},
{
"answer_id": 29213683,
"author": "Shady Mohamed Sherif",
"author_id": 348589,
"author_profile": "https://Stackoverflow.com/users/348589",
"pm_score": 1,
"selected": false,
"text": "(-?[0-9]+(\\.[0-9]+)?)\n"
},
{
"answer_id": 39355885,
"author": "Bhanu Pratap",
"author_id": 4847565,
"author_profile": "https://Stackoverflow.com/users/4847565",
"pm_score": -1,
"selected": false,
"text": " function DecimalNumberValidation() {\n var amounttext = ;\n if (!(/^[-+]?\\d*\\.?\\d*$/.test(document.getElementById('txtRemittanceNumber').value))){\n alert('Please enter only numbers into amount textbox.')\n }\n else\n {\n alert('Right Number');\n }\n }\n"
},
{
"answer_id": 49668034,
"author": "Pipo",
"author_id": 4542111,
"author_profile": "https://Stackoverflow.com/users/4542111",
"pm_score": 2,
"selected": false,
"text": "5."
},
{
"answer_id": 52163769,
"author": "Nambi_0915",
"author_id": 9976846,
"author_profile": "https://Stackoverflow.com/users/9976846",
"pm_score": 0,
"selected": false,
"text": "^[+-]?\\d+(\\.\\d{2}([eE](-[1-9]([0-9]*)?|[+]?\\d+))?)?$\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39221/"
] |
308,125 | <p>Is there anything like Firebug that you can use within Google Chrome?</p>
<p>Essential features I would like:</p>
<ul>
<li>Inspect HTML source (select elements, delete them, etc.)</li>
<li>check CSS values (the built-in solution is weird, somehow)</li>
</ul>
| [
{
"answer_id": 1707770,
"author": "Manuel",
"author_id": 50770,
"author_profile": "https://Stackoverflow.com/users/50770",
"pm_score": 3,
"selected": false,
"text": "javascript:var firebug=document.createElement('script');firebug.setAttribute('src','http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js');document.body.appendChild(firebug);(function(){if(window.firebug.version){firebug.init();}else{setTimeout(arguments.callee);}})();void(firebug);\n"
},
{
"answer_id": 3922788,
"author": "Amandasaurus",
"author_id": 161922,
"author_profile": "https://Stackoverflow.com/users/161922",
"pm_score": 1,
"selected": false,
"text": "chromium-browser-inspector"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9535/"
] |
308,133 | <p>I'm using PHP 5.2. I'd like to find a way to output a unique id for every object, so it's easy when looking over logs to see which objects are the same.</p>
<p>In Ruby, I'd just say object.object_id to get Ruby's internal identifier for the object. There doesn't seem to be an obvious way to do this in PHP.</p>
<p>Is there is a built-in way of doing this? If there isn't, can you offer any other suggestions?</p>
| [
{
"answer_id": 308145,
"author": "azkotoki",
"author_id": 28581,
"author_profile": "https://Stackoverflow.com/users/28581",
"pm_score": 7,
"selected": true,
"text": "spl_object_hash()"
},
{
"answer_id": 34599839,
"author": "rolacja",
"author_id": 4307374,
"author_profile": "https://Stackoverflow.com/users/4307374",
"pm_score": 0,
"selected": false,
"text": "<?php\n\nclass objectMarker\n{\n private $storage;\n\n function add($object) {\n $this->storage[] = $object;\n }\n\n function getId($object) {\n foreach ($this->storage as $id => $item) {\n if ($item === $object) {\n return $id;\n }\n }\n\n return null;\n }\n}\n\n$marker = new objectMarker;\n\n$t1 = new stdClass;\n$t2 = new stdClass;\n\n$marker->add($t1);\n$marker->add($t2);\n\necho $marker->getId($t1) . \"\\n\";\necho $marker->getId($t2) . \"\\n\";\n\nunset($t1);\n\n$t1 = new stdClass;\n$marker->add($t1);\n\necho $marker->getId($t1) . \"\\n\";\n\n$t2->x = 1;\necho $marker->getId($t2) . \"\\n\";\n\n/* output:\n0\n1\n2\n1\n*/\n"
},
{
"answer_id": 56070808,
"author": "i336_",
"author_id": 3229684,
"author_profile": "https://Stackoverflow.com/users/3229684",
"pm_score": 3,
"selected": false,
"text": "$test = (object)[];\nvar_dump(spl_object_id($test)); # int(1)\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31092/"
] |
308,156 | <p>I have created one sample PHP script to upload excel sheets of very bigger sizes. Also the process happening with each records given in the excel sheets is bit complex. To allow bigger sizes, I have added necessary PHP ini values in the Apache configuration file to override the actual PHP ini values.</p>
<p>The problem is, once I upload the bigger files, it takes longer time say 2 minutes or so, after that i am seeing the blank page instead of results page. When I tailed the Apache logs, I didn't see any such lines related to this issue.</p>
<p>Just wanted to know, are there any case/possibilities when Apache could serves blank page? </p>
<p>But when I tailed my application level logs, it is very clear the script has completes the job perfectly. My suspect, may be what could have happen is, once the job completes, while Apache about to serve back the results page something would have happened, but I am not sure about it.</p>
| [
{
"answer_id": 308225,
"author": "Mojah",
"author_id": 30330,
"author_profile": "https://Stackoverflow.com/users/30330",
"pm_score": 1,
"selected": false,
"text": "error_reporting(E_ALL);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
308,158 | <p>When reviewing our codebase, I found an inheritance structure that resembles the following pattern:</p>
<pre><code>interface IBase
{
void Method1();
void Method2();
}
interface IInterface2 : IBase
{
void Method3();
}
class Class1 : IInterface2
{
...
}
class Class2 : IInterface2
{
...
}
class Class3 : IInterface2
{
...
}
</code></pre>
<p>In <code>Class2</code>, <code>Method1</code> throws <code>NotImplementedException</code>.</p>
<p>Questions:</p>
<ul>
<li>What do you think in general about inheriting interfaces?</li>
<li>Does the relationship between <code>IBase</code> and <code>Class2</code> violate the Liskov Substitution Principle?</li>
</ul>
| [
{
"answer_id": 308183,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 2,
"selected": false,
"text": "NotImplementedException"
},
{
"answer_id": 308245,
"author": "Jorge Córdoba",
"author_id": 2695,
"author_profile": "https://Stackoverflow.com/users/2695",
"pm_score": 1,
"selected": false,
"text": "interface ISubmergible\n{\n void Submerge();\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2822/"
] |
308,174 | <p>I have just moved job and gone from VB 6 to VB.Net and found the learning jump fairly steep, have more a problem with the object / conceptual side of things .. but getting there now ... but as I was a assembler / C++ 10/15 years ago and was considering learning C++/C# .Net (XNA games library calls my name) but not sure if it would hinder my VB.NET learning .... or should I just get myself certified</p>
| [
{
"answer_id": 963852,
"author": "Binoj Antony",
"author_id": 33015,
"author_profile": "https://Stackoverflow.com/users/33015",
"pm_score": 1,
"selected": false,
"text": "Sub"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308174",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32336/"
] |
308,175 | <p>I can't tell if this is a result of the jQuery I'm using, but this is what I'm trying to do:</p>
<pre><code><div class="info" style="display: inline;"
onMouseOut="$(this).children('div').hide('normal');"
onMouseOver="$(this).children('div').show('normal');"
>
<img src="images/target.png">
<div class="tooltiptwo" id="tooltip"
style="font-weight: normal; font-size: 0.8em;" >TOOLTIP TEXT</div>
</div>
</code></pre>
<p>To anyone familiar with basic CSS and jQuery, I'm trying to add a simple animation to my tooltips. The problem is the triggering of such an animation. It seems that when the animation happens, if the user moves their mouse over the tooltip, the animation will go into a loop of showing and hiding until the user moves the mouse away. This is an undesired effect, as I want the animation to go away just once, when the mouse moves out of the <em>parent</em> div. I've positioned my CSS so that the tooltip appears away from the parent div, but regardless the actions should be triggering only on the parent, and not any of its children.</p>
<p>So basically, how would I go about achieving this? I want my hover/out state on my parent element to trigger a function (an animation) on the children of that parent, without the hover/out states of the children doing anything. It seems that the normal method of <code>onMouseOver</code> and <code>onMouseOut</code> is triggering even for the children of the parent that the method belongs to, which is causing some rather undesirable effects.</p>
<p>Note that I'm new to jQuery (although its amazing so far, I want to coat my site in its goodness if I can) and if there is a better way to achieve the hover/out states using jQuery I probably don't know about them.</p>
| [
{
"answer_id": 308209,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": true,
"text": "$('.info').bind('mouseenter', function() {\n $('div', this).show('normal');\n});\n\n$('.info').bind('mouseleave', function() {\n $('div', this).hide('normal');\n});\n\n// hide the tooltip to start off\n$('.info div').hide();\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19521/"
] |
308,187 | <p>how do I translate this code into jython?</p>
<pre><code> ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file + ".zip"));
byte[] buf = new byte[1024];
int len;
//Create a new Zip entry with the file's name.
ZipEntry zipEntry = new ZipEntry(file.toString());
//Create a buffered input stream out of the file
//we're trying to add into the Zip archive.
FileInputStream fin = new FileInputStream(file);
BufferedInputStream in = new BufferedInputStream(fin);
zos.putNextEntry(zipEntry);
//Read bytes from the file and write into the Zip archive.
while ((len = in.read(buf)) >= 0) {
zos.write(buf, 0, len);
}
//Close the input stream.
in.close();
//Close this entry in the Zip stream.
zos.closeEntry();
</code></pre>
<p>this is what I have but it Fails badly</p>
<pre><code> buf=None <<<< ?
len=None <<<< ?
zipEntry=ZipEntry(file.toString())
fin=FileInputStream(file)
bin=BufferedInputStream(fin)
self._zos.putNextEntry(zipEntry)
while (len=bin.helpme_im_dying(buf)) >= 0): <<<< ?
self._zos.write(buf,0,len) <<<< ?
len = bin.read(buf) <<<< ?
bin.close()
self._zos.closeEntry()
</code></pre>
<p>refer to this page for information <a href="https://www.acm.org/crossroads/xrds6-3/ovp63.html" rel="nofollow noreferrer">https://www.acm.org/crossroads/xrds6-3/ovp63.html</a></p>
| [
{
"answer_id": 308210,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": true,
"text": "bin"
},
{
"answer_id": 308462,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 1,
"selected": false,
"text": "from zipfile import ZipFile, ZIP_DEFLATED\n\ndef test(file):\n ZipFile(file+\".zip\", \"w\", ZIP_DEFLATED).write(file)\n"
},
{
"answer_id": 25662884,
"author": "Greg Allen",
"author_id": 779173,
"author_profile": "https://Stackoverflow.com/users/779173",
"pm_score": 0,
"selected": false,
"text": "with ZipFile('spam.zip', 'w') as myzip:\n myzip.write('eggs.txt')\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21537/"
] |
308,188 | <p>I'm trying to use <a href="http://www.jboss.org/community/docs/DOC-10032" rel="noreferrer">this method</a> for receiving mail in our EJB3 app. In short, that means creating an MDB with the following annotations:</p>
<pre><code>@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "mailServer", propertyValue = "imap.company.com"),
@ActivationConfigProperty(propertyName = "mailFolder", propertyValue = "INBOX"),
@ActivationConfigProperty(propertyName = "storeProtocol", propertyValue = "imap"),
@ActivationConfigProperty(propertyName = "debug", propertyValue = "false"),
@ActivationConfigProperty(propertyName = "userName", propertyValue = "username"),
@ActivationConfigProperty(propertyName = "password", propertyValue = "pass") })
@ResourceAdapter("mail-ra.rar")
@Name("mailMessageBean")
public class MailMessageBean implements MailListener {
public void onMessage(final Message msg) {
...snip...
}
}
</code></pre>
<p>I have this working, but the situation is less than ideal: The hostname, username and password are hardcoded. Short of using ant and build.properties to replace those values before compilation, I don't know how to externalize them. </p>
<p>It would be ideal to use an MBean, but I have no idea how to get the values from the MBean to the MDB configuration.</p>
<p>How should I do this?</p>
| [
{
"answer_id": 337473,
"author": "Brett Hannah",
"author_id": 42491,
"author_profile": "https://Stackoverflow.com/users/42491",
"pm_score": 5,
"selected": true,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<ejb-jar version=\"3.0\">\n <enterprise-beans>\n <message-driven>\n <ejb-name>YourMDB</ejb-name>\n <ejb-class>MailMessageBean</ejb-class> \n <activation-config>\n <activation-config-property>\n <activation-config-property-name>username</activation-config-property-name>\n <activation-config-property-value>${mdb.user.name}</activation-config-property-value>\n </activation-config-property>\n...\n...\n </activation-config>\n </message-driven>\n </enterprise-beans>\n"
},
{
"answer_id": 5250979,
"author": "Joseph Valerio",
"author_id": 652232,
"author_profile": "https://Stackoverflow.com/users/652232",
"pm_score": 2,
"selected": false,
"text": "...\n@MessageDriven\n@AspectDomain(\"TestMDBean\")\npublic class TestMDBean implements MessageListener {\n...\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6400/"
] |
308,191 | <p>I have a group of strings in Javascript and I need to write a function that detects if another specific string belongs to this group or not.</p>
<p>What is the fastest way to achieve this? Is it alright to put the group of values into an array, and then write a function that searches through the array?</p>
<p>I think if I keep the values sorted and do a binary search, it should work fast enough. Or is there some other smart way of doing this, which can work faster?</p>
| [
{
"answer_id": 308201,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 3,
"selected": false,
"text": "// prepare a mock-up object\nsetOfValues = {};\nfor (var i = 0; i < 100; i++)\n setOfValues[\"example value \" + i] = true;\n\n// check for existence\nif (setOfValues[\"example value 99\"]); // true\nif (setOfValues[\"example value 101\"]); // undefined, essentially: false\n"
},
{
"answer_id": 308268,
"author": "Simon Howard",
"author_id": 24806,
"author_profile": "https://Stackoverflow.com/users/24806",
"pm_score": 6,
"selected": true,
"text": "// Initialise the set\n\nmySet = {};\n\n// Add to the set\n\nmySet[\"some string value\"] = true;\n\n...\n\n// Test if a value is in the set:\n\nif (testValue in mySet) {\n alert(testValue + \" is in the set\");\n} else {\n alert(testValue + \" is not in the set\");\n}\n"
},
{
"answer_id": 308525,
"author": "Ralf",
"author_id": 39645,
"author_profile": "https://Stackoverflow.com/users/39645",
"pm_score": 3,
"selected": false,
"text": "\"toString\" in setOfValues"
},
{
"answer_id": 308573,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "var haystack = \"monday tuesday wednesday thursday friday saturday sunday\";\nvar needle = \"Friday\";\nif (haystack.indexOf(needle.toLowerCase()) >= 0) alert(\"Found!\");\n"
},
{
"answer_id": 44196832,
"author": "melchoir55",
"author_id": 1812993,
"author_profile": "https://Stackoverflow.com/users/1812993",
"pm_score": 3,
"selected": false,
"text": "> let set = new Set();\n> set.add('red')\n\n> set.has('red')\ntrue\n> set.delete('red')\ntrue\n> set.has('red')\nfalse\n"
},
{
"answer_id": 44927094,
"author": "jafarbtech",
"author_id": 6082645,
"author_profile": "https://Stackoverflow.com/users/6082645",
"pm_score": 0,
"selected": false,
"text": "indexOf()"
},
{
"answer_id": 54228411,
"author": "Penny Liu",
"author_id": 6904888,
"author_profile": "https://Stackoverflow.com/users/6904888",
"pm_score": 0,
"selected": false,
"text": "var string = \"The quick brown fox jumps over the lazy dog.\",\n substring = \"lazy dog\";\n\nconsole.log(string.includes(substring));"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11384/"
] |
308,203 | <p>I'm trying to figure out how to execute a custom query with Castle ActiveRecord. </p>
<p>I was able to run simple query that returns my entity, but what I really need is the query like that below (with custom field set):</p>
<p><em>select count(1) as cnt, data from workstationevent where serverdatetime >= :minDate and serverdatetime < :maxDate and userId = 1 group by data having count(1) > :threshold</em></p>
<p>Thanks!</p>
| [
{
"answer_id": 318100,
"author": "Neil Hewitt",
"author_id": 22178,
"author_profile": "https://Stackoverflow.com/users/22178",
"pm_score": 4,
"selected": true,
"text": "HqlBasedQuery"
},
{
"answer_id": 840387,
"author": "enriquein",
"author_id": 88868,
"author_profile": "https://Stackoverflow.com/users/88868",
"pm_score": 0,
"selected": false,
"text": "var results = (ICollection<object[]>) ActiveRecordMediator.ExecuteQuery(query);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22680/"
] |
308,204 | <p>I would like to hear from you guys on how do you decide when you should be using concrete parameterized type vs. bounded parameterized type when designing API, esp. (that I care most) of defining a class/interface.</p>
<p>For instance,</p>
<pre><code>public interface Event<S>{
void setSource(S s);
}
public interface UserEvent extends EVent<User> // OR: UserEvent<S extends User> extends Event<S>
// It will therefore be void setSource(User s);
}
</code></pre>
<p>The problem of using concrete parameter is that, I can't bring this compile-time benefit I earn when using setSource() to a new interface say,</p>
<pre><code>public interface AdminUserEvent extends UserEvent{
void setSource(AdminUser s); // WHERE: AdminUser extends User. This is a method overloading, we also have a void setSource(User s) inherited from UserEvent.
}
</code></pre>
<p>What I can work around for this is to do a type checking on the <code>User</code> object when <code>AdminUserEvent.setSource()</code> is called.</p>
<p>Have you ever had this question raised when you design your API? And what are the practices or rules that you will go for when this sort of situation arises? Thanks.</p>
<p>yc</p>
| [
{
"answer_id": 308229,
"author": "Miserable Variable",
"author_id": 18573,
"author_profile": "https://Stackoverflow.com/users/18573",
"pm_score": 0,
"selected": false,
"text": "B extends A"
},
{
"answer_id": 1277054,
"author": "David Moles",
"author_id": 27358,
"author_profile": "https://Stackoverflow.com/users/27358",
"pm_score": 1,
"selected": false,
"text": "UserEvent<S extends User>"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36397/"
] |
308,219 | <p>I'm trying to build a multi-level dropdrown CSS menu for a website I'm doing on the umbraco content management system.</p>
<p>I need to build it to have the following structure:</p>
<pre><code><ul id="nav">
<li><a href="..">Page #1</a></li>
<li>
<a href="..">Page #2</a>
<ul>
<li><a href="..">Subpage #1</a></li>
<li><a href="..">Subpage #2</a></li>
</ul>
</li>
</ul>
</code></pre>
<p>So now I'm trying to figure out how to do the nesting using XSLT. This is what I have so far:</p>
<pre><code><xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<!-- update this variable on how deep your menu should be -->
<xsl:variable name="maxLevelForMenu" select="4"/>
<xsl:template match="/">
<ul id="nav">
<xsl:call-template name="drawNodes">
<xsl:with-param
name="parent"
select="$currentPage/ancestor-or-self::node [@level=1]"
/>
</xsl:call-template>
</ul>
</xsl:template>
<xsl:template name="drawNodes">
<xsl:param name="parent"/>
<xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
<xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForMenu]">
<li>
<a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/>
</a>
<xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevelForMenu]) &gt; 0">
<xsl:call-template name="drawNodes">
<xsl:with-param name="parent" select="."/>
</xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</xsl:if>
</xsl:template>
</code></pre>
<p>What I can't seem to figure out is how to check if the first level (here Page #1 and Page #2) has any children, and if they do add the extra <code><ul></code> to contain the <code><li></code> children.</p>
<p>Anyone out there to point me in the right direction?</p>
| [
{
"answer_id": 308651,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 4,
"selected": true,
"text": "parent"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
308,227 | <p>Two snippets of MySQL: </p>
<pre><code>SELECT * FROM annoyingly_long_left_hand_table
LEFT JOIN annoyingly_long_right_hand_table
ON annoyingly_long_left_hand_table.id = annoyingly_long_right_hand_table.id;
</code></pre>
<p>vs</p>
<pre><code>SELECT * FROM annoyingly_long_left_hand_table
LEFT JOIN annoyingly_long_right_hand_table
USING (id);
</code></pre>
<p>Given that both tables have an <code>id</code> field, is there any disadvantage to using the second version. It isn't just laziness - the version with USING seems far clearer to me.</p>
<p>(Please don't mention aliasing - I want to know if there is any reason to favour one conditional structure over the other)</p>
| [
{
"answer_id": 1493614,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 1,
"selected": false,
"text": "USING"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20074/"
] |
308,254 | <p>I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone.</p>
<p>Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file.</p>
<p>Before, there was a ipython2.4 package but it is deprecated.</p>
| [
{
"answer_id": 308260,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 5,
"selected": true,
"text": "ls /usr/bin/ipython*\n/usr/bin/ipython /usr/bin/ipython2.4 /usr/bin/ipython2.5\n"
},
{
"answer_id": 5293422,
"author": "idbrii",
"author_id": 79125,
"author_profile": "https://Stackoverflow.com/users/79125",
"pm_score": 2,
"selected": false,
"text": "virtualenv --python=/usr/bin/python2.5 project_name\nsource project_name/bin/activate\npip install ipython\n"
},
{
"answer_id": 18981744,
"author": "atupal",
"author_id": 2226698,
"author_profile": "https://Stackoverflow.com/users/2226698",
"pm_score": 0,
"selected": false,
"text": "$ python2.4 setup.py install --prefix=$HOME/usr\n$ python2.5 setup.py install --prefix=$HOME/usr\n"
},
{
"answer_id": 43886087,
"author": "Pol Alvarez Vecino",
"author_id": 2221409,
"author_profile": "https://Stackoverflow.com/users/2221409",
"pm_score": 0,
"selected": false,
"text": "python2.7 ipython\npython3 ipython\n"
},
{
"answer_id": 45552382,
"author": "Peter",
"author_id": 2665843,
"author_profile": "https://Stackoverflow.com/users/2665843",
"pm_score": 1,
"selected": false,
"text": "which ipython"
},
{
"answer_id": 72532009,
"author": "Assombrance Andreson",
"author_id": 8179194,
"author_profile": "https://Stackoverflow.com/users/8179194",
"pm_score": 0,
"selected": false,
"text": "$ cp ipython ipython3\n$ nano ipython3\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
308,258 | <p>How do I tell the Vim editor about my include files path so that it can auto complete the function names when I press <kbd>CTRL</kbd>+<kbd>N</kbd>?</p>
<p>For example, I have a C program like below:</p>
<pre><code>#include<stdio.h>
int main()
{
sca // here I press control+N, it does not complete to scanf
}
</code></pre>
| [
{
"answer_id": 308274,
"author": "Rob Wells",
"author_id": 2974,
"author_profile": "https://Stackoverflow.com/users/2974",
"pm_score": 5,
"selected": true,
"text": ".vimrc"
},
{
"answer_id": 308293,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 4,
"selected": false,
"text": "^x ^o = \"omnicomplete\" \n^x ^i = \"included-files completion\" \n^x ^f = \"path completion\" \n^x ^l = \"Complete this line using one that looks the same\"\n"
},
{
"answer_id": 4027067,
"author": "Heikki Naski",
"author_id": 310344,
"author_profile": "https://Stackoverflow.com/users/310344",
"pm_score": 2,
"selected": false,
"text": "i"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39615/"
] |
308,276 | <p>As a <a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29" rel="noreferrer">C#</a> developer I'm used to running through constructors:</p>
<pre class="lang-cs prettyprint-override"><code>class Test {
public Test() {
DoSomething();
}
public Test(int count) : this() {
DoSomethingWithCount(count);
}
public Test(int count, string name) : this(count) {
DoSomethingWithName(name);
}
}
</code></pre>
<p>Is there a way to do this in C++?</p>
<p>I tried calling the Class name and using the 'this' keyword, but both fail.</p>
| [
{
"answer_id": 308309,
"author": "Cyrille Ka",
"author_id": 39622,
"author_profile": "https://Stackoverflow.com/users/39622",
"pm_score": 7,
"selected": false,
"text": "class SomeType\n{\n int number;\n \npublic:\n SomeType(int newNumber) : number(newNumber) {}\n SomeType() : SomeType(42) {}\n};\n"
},
{
"answer_id": 308318,
"author": "JohnIdol",
"author_id": 1311500,
"author_profile": "https://Stackoverflow.com/users/1311500",
"pm_score": 12,
"selected": true,
"text": "class Foo {\npublic: \n Foo(char x, int y) {}\n Foo(int y) : Foo('a', y) {}\n};\n"
},
{
"answer_id": 310962,
"author": "kchoose2",
"author_id": 39870,
"author_profile": "https://Stackoverflow.com/users/39870",
"pm_score": 5,
"selected": false,
"text": "class Foo {\npublic: \n Foo(char x, int y) {}\n Foo(int y) : Foo('a', y) {}\n};\n"
},
{
"answer_id": 5422670,
"author": "lyngvi",
"author_id": 675336,
"author_profile": "https://Stackoverflow.com/users/675336",
"pm_score": 4,
"selected": false,
"text": "class Foo() {\n Foo() { /* default constructor deliciousness */ }\n Foo(Bar myParam) {\n new (this) Foo();\n /* bar your param all night long */\n } \n};\n"
},
{
"answer_id": 7520788,
"author": "Ben L",
"author_id": 328316,
"author_profile": "https://Stackoverflow.com/users/328316",
"pm_score": 5,
"selected": false,
"text": "class Foo {\n int d; \npublic:\n Foo (int i) : d(i) {}\n Foo () : Foo(42) {} //New to C++11\n};\n"
},
{
"answer_id": 8263875,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 3,
"selected": false,
"text": "class Test_Base {\n public Test_Base() {\n DoSomething();\n }\n};\n\nclass Test : public Test_Base {\n public Test() : Test_Base() {\n }\n\n public Test(int count) : Test_Base() {\n DoSomethingWithCount(count);\n }\n};\n"
},
{
"answer_id": 9359241,
"author": "izogfif",
"author_id": 425345,
"author_profile": "https://Stackoverflow.com/users/425345",
"pm_score": 3,
"selected": false,
"text": "class Vertex\n{\n private:\n int x, y;\n public:\n Vertex(int xCoo, int yCoo): x(xCoo), y(yCoo) {}\n Vertex()\n {\n this->Vertex::Vertex(-1, -1);\n }\n};\n"
},
{
"answer_id": 26694709,
"author": "Pantelis Sopasakis",
"author_id": 613016,
"author_profile": "https://Stackoverflow.com/users/613016",
"pm_score": 2,
"selected": false,
"text": "private friend"
},
{
"answer_id": 33639823,
"author": "V15I0N",
"author_id": 930610,
"author_profile": "https://Stackoverflow.com/users/930610",
"pm_score": 2,
"selected": false,
"text": "Foo::Foo()\n{\n // do what every Foo is needing\n ...\n}\n\nFoo::Foo(char x)\n{\n *this = Foo();\n\n // do the special things for a Foo with char\n ...\n}\n"
},
{
"answer_id": 39409654,
"author": "gyula",
"author_id": 6813199,
"author_profile": "https://Stackoverflow.com/users/6813199",
"pm_score": -1,
"selected": false,
"text": "#include <iostream>\n\nclass A {\npublic:\n A( int a) : m_a(a) {\n std::cout << \"A::Ctor\" << std::endl; \n }\n ~A() {\n std::cout << \"A::dtor\" << std::endl; \n }\npublic:\n int m_a;\n};\n\nclass B : public A {\npublic:\n B( int a, int b) : m_b(b), A(a) {}\npublic:\n int m_b;\n};\n\nint main() {\n B b(9, 6);\n std::cout << \"Test constructor delegation a = \" << b.m_a << \"; b = \" << b.m_b << std::endl; \n return 0;\n}\n"
},
{
"answer_id": 46989424,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "class Foo {\npublic: \n Foo(char x, int y) {}\n Foo(int y) : Foo('a', y) {} // Foo(int) delegates to Foo(char,int)\n};\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2090/"
] |
308,277 | <p>I am working on a C++ project and I noticed that we have a number of warnings about unused parameters.</p>
<p>What effect could it have if these warnings are ignored?</p>
| [
{
"answer_id": 308286,
"author": "Alex B",
"author_id": 23643,
"author_profile": "https://Stackoverflow.com/users/23643",
"pm_score": 7,
"selected": true,
"text": "#ifdef"
},
{
"answer_id": 308314,
"author": "Wilka",
"author_id": 1367,
"author_profile": "https://Stackoverflow.com/users/1367",
"pm_score": 1,
"selected": false,
"text": "const int Size = 12; // intended for use in some other function\n\nchar* MakeBuffer(int size)\n{\n return new char[Size];\n}\n"
},
{
"answer_id": 308329,
"author": "warren",
"author_id": 4418,
"author_profile": "https://Stackoverflow.com/users/4418",
"pm_score": 1,
"selected": false,
"text": "int sum(int first, int second=0){ // should not give warning\n return first+first;\n}\n"
},
{
"answer_id": 409204,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": false,
"text": "__attribute__((unused))"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24459/"
] |
308,279 | <p>Been thinking, what's the difference between declaring a variable with [] or * ? The way I see it:</p>
<pre><code>char *str = new char[100];
char str2[] = "Hi world!";
</code></pre>
<p>.. should be the main difference, though Im unsure if you can do something like</p>
<pre><code>char *str = "Hi all";
</code></pre>
<p>.. since the pointer should the reference to a static member, which I don't know if it can?</p>
<p>Anyways, what's really bugging me is knowing the difference between:</p>
<pre><code>void upperCaseString(char *_str) {};
void upperCaseString(char _str[]) {};
</code></pre>
<p>So, would be much appreciated if anyone could tell me the difference? I have a hunch that both might be compiled down the same, except in some special cases?</p>
<p>Ty</p>
| [
{
"answer_id": 308312,
"author": "warren",
"author_id": 4418,
"author_profile": "https://Stackoverflow.com/users/4418",
"pm_score": -1,
"selected": false,
"text": "upperCaseString()"
},
{
"answer_id": 308315,
"author": "Timbo",
"author_id": 1810,
"author_profile": "https://Stackoverflow.com/users/1810",
"pm_score": 4,
"selected": false,
"text": "char* str = new char[100];\n"
},
{
"answer_id": 308724,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 6,
"selected": true,
"text": "char const"
},
{
"answer_id": 309009,
"author": "Leonardo Herrera",
"author_id": 7841,
"author_profile": "https://Stackoverflow.com/users/7841",
"pm_score": 2,
"selected": false,
"text": "\nchar *str = new char[100];\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25745/"
] |
308,298 | <p>Using <strong>sc</strong> command we can query, start , stop windows services.<br>
For ex: </p>
<pre><code>sc query "windows service name"
</code></pre>
<p>The <strong>sc config</strong> command changes the configuration of the service, but I don't know how to use it. </p>
<p>Could someone tell me how we can set the username and password for any windows service?</p>
| [
{
"answer_id": 308319,
"author": "Andrew Ferrier",
"author_id": 27641,
"author_profile": "https://Stackoverflow.com/users/27641",
"pm_score": 8,
"selected": true,
"text": "sc.exe config \"[servicename]\" obj= \"[.\\username]\" password= \"[password]\"\n"
},
{
"answer_id": 13630270,
"author": "Alberto Dallagiacoma",
"author_id": 1433706,
"author_profile": "https://Stackoverflow.com/users/1433706",
"pm_score": 3,
"selected": false,
"text": "sc.exe config Service obj= user password= pass\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32670/"
] |
308,301 | <p>I've got code similar to the following...</p>
<pre><code><p><label>Do you have buffet facilities?</label>
<asp:RadioButtonList ID="blnBuffetMealFacilities:chk" runat="server">
<asp:ListItem Text="Yes" Value="1"></asp:ListItem>
<asp:ListItem Text="No" Value="0"></asp:ListItem>
</asp:RadioButtonList></p>
<div id="HasBuffet">
<p><label>What is the capacity for the buffet?</label>
<asp:RadioButtonList ID="radBuffetCapacity" runat="server">
<asp:ListItem Text="Suitable for upto 30 guests" value="0 to 30"></asp:ListItem>
<asp:ListItem Text="Suitable for upto 50 guests" value="30 to 50"></asp:ListItem>
<asp:ListItem Text="Suitable for upto 75 guests" value="50 to 75"></asp:ListItem>
<asp:ListItem Text="Suitable for upto 100 guests" value="75 to 100"></asp:ListItem>
<asp:ListItem Text="Suitable for upto 150 guests" value="100 to 150"></asp:ListItem>
<asp:ListItem Text="Suitable for upto 250 guests" value="150 to 250"></asp:ListItem>
<asp:ListItem Text="Suitable for upto 400 guests" value="250 to 400"></asp:ListItem>
</asp:RadioButtonList></p>
</div>
</code></pre>
<p>I want to capture an event when the radio list blBuffetMealFacilities:chk changes client side and perform a slide down function on the HasBuffet div from jQuery. What's the best way to create this, bearing in mind there are several similar sections on the page, where I want questions to be revealed depending on a yes no answer in a radio list.</p>
| [
{
"answer_id": 308327,
"author": "Andrew Bullock",
"author_id": 28543,
"author_profile": "https://Stackoverflow.com/users/28543",
"pm_score": 6,
"selected": true,
"text": "$('#rblDiv input').click(function(){\n alert($('#rblDiv input').index(this));\n});\n"
},
{
"answer_id": 708785,
"author": "digiguru",
"author_id": 5055,
"author_profile": "https://Stackoverflow.com/users/5055",
"pm_score": 1,
"selected": false,
"text": "var shows_6 = function() {\n var selected = $(\"#q_7 input:radio:checked\").val();\n if (selected == 'Groom') {\n $(\"#s_6\").slideDown();\n } else {\n $(\"#s_6\").slideUp();\n }\n};\n$('#q_7 input').ready(shows_6);\nvar shows_7 = function() {\n var selected = $(\"#q_7 input:radio:checked\").val();\n if (selected == 'Bride') {\n $(\"#s_7\").slideDown();\n } else {\n $(\"#s_7\").slideUp();\n }\n};\n$('#q_7 input').ready(shows_7);\n$(document).ready(function() {\n $('#q_7 input:radio').click(shows_6);\n $('#q_7 input:radio').click(shows_7);\n});\n\n<div id=\"q_7\" class='question '><label>Who are you?</label> \n <p>\n <label for=\"ctl00_ctl00_ContentMainPane_Body_ctl00_ctl00_chk_0\">Bride</label>\n <input id=\"ctl00_ctl00_ContentMainPane_Body_ctl00_ctl00_chk_0\" type=\"radio\" name=\"ctl00$ctl00$ContentMainPane$Body$ctl00$ctl00$chk\" value=\"Bride\" />\n </p> \n <p>\n <label for=\"ctl00_ctl00_ContentMainPane_Body_ctl00_ctl00_chk_1\">Groom</label>\n <input id=\"ctl00_ctl00_ContentMainPane_Body_ctl00_ctl00_chk_1\" type=\"radio\" name=\"ctl00$ctl00$ContentMainPane$Body$ctl00$ctl00$chk\" value=\"Groom\" />\n </p> \n\n</div> \n"
},
{
"answer_id": 887378,
"author": "Felipe Pessoto",
"author_id": 97082,
"author_profile": "https://Stackoverflow.com/users/97082",
"pm_score": 0,
"selected": false,
"text": "var Ocasiao = \"\"; \n$('#ctl00_rdlOcasioesMarcas input').each(function() { if (this.checked) { Ocasiao = this.value } });\n"
},
{
"answer_id": 2879478,
"author": "Vinh",
"author_id": 344818,
"author_profile": "https://Stackoverflow.com/users/344818",
"pm_score": 6,
"selected": false,
"text": "$('#RadioButtonList1 input:checked').val()\n"
},
{
"answer_id": 3734429,
"author": "Fischer",
"author_id": 193719,
"author_profile": "https://Stackoverflow.com/users/193719",
"pm_score": 0,
"selected": false,
"text": "$('#<%= radBuffetCapacity.ClientID %> input').click(function (e) {\n var val = $('#<%= radBuffetCapacity.ClientID %>').find('input:checked').val();\n //Do whatever\n});\n"
},
{
"answer_id": 6303201,
"author": "Stephen Montgomery",
"author_id": 233987,
"author_profile": "https://Stackoverflow.com/users/233987",
"pm_score": 2,
"selected": false,
"text": "var deliveryService;\n$('.deliveryservice input').each(function () {\n if (this.checked) {\n deliveryService = this.value\n }\n"
},
{
"answer_id": 6708814,
"author": "RWL01",
"author_id": 742356,
"author_profile": "https://Stackoverflow.com/users/742356",
"pm_score": 0,
"selected": false,
"text": "$('#ClientID' + ' input:checked').parent().find('label').text()"
},
{
"answer_id": 7666984,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "<asp:RadioButtonList runat=\"server\" ID=\"Intent\">\n <asp:ListItem Value=\"Confirm\">Yes!</asp:ListItem>\n <asp:ListItem Value=\"Postpone\">Not now</asp:ListItem>\n <asp:ListItem Value=\"Decline\">Never!</asp:ListItem>\n</asp:RadioButtonList>\n"
},
{
"answer_id": 10426382,
"author": "azarudeen",
"author_id": 1371742,
"author_profile": "https://Stackoverflow.com/users/1371742",
"pm_score": 3,
"selected": false,
"text": " var GetValue=$('#radiobuttonListId').find(\":checked\").val();\n"
},
{
"answer_id": 11315863,
"author": "Shah Bdr",
"author_id": 1499492,
"author_profile": "https://Stackoverflow.com/users/1499492",
"pm_score": 1,
"selected": false,
"text": "<script type=\"text/javascript\">\n $(document).ready(function () {\n\n $(\".ratingButtons\").buttonset();\n\n });\n </script>\n\n\n<asp:RadioButtonList ID=\"RadioButtonList1\" RepeatDirection=\"Horizontal\" runat=\"server\"\n AutoPostBack=\"True\" DataSourceID=\"SqlDataSourceSizes\" DataTextField=\"ProdSize\"\n CssClass=\"ratingButtons\" DataValueField=\"_ProdSizeID\" Font-Size=\"X-Small\" \n ForeColor=\"#666666\">\n</asp:RadioButtonList>\n"
},
{
"answer_id": 21264817,
"author": "ewitkows",
"author_id": 382214,
"author_profile": "https://Stackoverflow.com/users/382214",
"pm_score": 0,
"selected": false,
"text": "<asp:RadioButtonList id=\"rbl\" runat=\"server\" class=\"tbl\">...\n"
},
{
"answer_id": 21381077,
"author": "Predders",
"author_id": 1611481,
"author_profile": "https://Stackoverflow.com/users/1611481",
"pm_score": 1,
"selected": false,
"text": "$('#id:checked').val();\n"
},
{
"answer_id": 26161507,
"author": "Vin05",
"author_id": 863194,
"author_profile": "https://Stackoverflow.com/users/863194",
"pm_score": 2,
"selected": false,
"text": "$(\"input[name='<%=RadioButtonList1.UniqueID %>']:checked\").val()\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5055/"
] |
308,307 | <p>Can anyone point me in the right direction how to configure Visual Studio 2005 with our C++ console project how we can include a 'File Version' in the details section of the file properties.</p>
<p>I've tried resource files without any luck. This is with a C++ project just for clarification, and big thank you for the guys you responded with C# suggestions.</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 308380,
"author": "user33675",
"author_id": 33675,
"author_profile": "https://Stackoverflow.com/users/33675",
"pm_score": 3,
"selected": false,
"text": "VS_VERSION_INFO"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308307",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
308,324 | <p>I want to generate a CSV file for user to use Excel to open it.</p>
<p>If I want to escape the comma in values, I can write it as "640,480".</p>
<p>If I want to keep the leading zeros, I can use ="001234".</p>
<p>But if I want to keep both comma and leading zeros in the value, writing as ="001,002" will be splitted as two columns. It seems no solution to express the correct data.</p>
<p>Is there any way to express <strong>001, 002</strong> in CSV for Excel?</p>
| [
{
"answer_id": 308340,
"author": "Nick Fortescue",
"author_id": 5346,
"author_profile": "https://Stackoverflow.com/users/5346",
"pm_score": 2,
"selected": false,
"text": "\"\"\"001,002\"\"\"\n"
},
{
"answer_id": 308352,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 3,
"selected": false,
"text": " \"N001,002\",\"N002,003\" \n"
},
{
"answer_id": 26145193,
"author": "dubversion",
"author_id": 4099468,
"author_profile": "https://Stackoverflow.com/users/4099468",
"pm_score": 0,
"selected": false,
"text": "chr(13)"
},
{
"answer_id": 39577123,
"author": "davidwebca",
"author_id": 462943,
"author_profile": "https://Stackoverflow.com/users/462943",
"pm_score": 0,
"selected": false,
"text": "echo \"\\0\" . $data;\n"
},
{
"answer_id": 49170384,
"author": "LukStorms",
"author_id": 4003419,
"author_profile": "https://Stackoverflow.com/users/4003419",
"pm_score": 1,
"selected": false,
"text": "\\t"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288936/"
] |
308,342 | <p>I have a table with the following columns:</p>
<pre>
A B C
---------
1 10 X
1 11 X
2 15 X
3 20 Y
4 15 Y
4 20 Y
</pre>
<p>I want to group the data based on the B and C columns and count the distinct values of the A column. But if there are two ore more rows where the value on the A column is the same I want to get the maximum value from the B column.</p>
<p>If I do a simple group by the result would be:</p>
<pre>
B C Count
--------------
10 X 1
11 X 1
15 X 1
20 Y 2
15 Y 1
</pre>
<p>What I want is this result:</p>
<pre>
B C Count
--------------
11 X 1
15 X 1
20 Y 2
</pre>
<p>Is there any query that can return this result. Server is SQL Server 2005.</p>
| [
{
"answer_id": 308387,
"author": "Dheer",
"author_id": 17266,
"author_profile": "https://Stackoverflow.com/users/17266",
"pm_score": 0,
"selected": false,
"text": "select count(a), BB, CC from\n(\nselect a, max(B) BB, Max(C) CC\nfrom yourtable\ngroup by a\n)\ngroup by BB,CC\n"
},
{
"answer_id": 308395,
"author": "Tiberiu Ana",
"author_id": 38567,
"author_profile": "https://Stackoverflow.com/users/38567",
"pm_score": 3,
"selected": true,
"text": "with t1 as (\n select A, max(B) as B, C \n from YourTable\n group by A, C\n)\nselect count(A) as CountA, B, C\n from t1\n group by B, C\n"
},
{
"answer_id": 308397,
"author": "Kris",
"author_id": 18565,
"author_profile": "https://Stackoverflow.com/users/18565",
"pm_score": 2,
"selected": false,
"text": "SELECT \n MAX( B ) AS B,\n C,\n Count \nFROM\n(\n SELECT\n B, C, COUNT(DISTINCT A) AS Count\n FROM\n t\n GROUP BY\n B, C\n) X\nGROUP BY C, Count\n"
},
{
"answer_id": 308432,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "WITH cteA AS \n(\n SELECT \n A, C, \n MAX(B) OVER(PARTITION BY A, C) [Max]\n FROM T1\n)\n\nSELECT \n [Max] AS B, C, \n COUNT(DISTINCT A) AS [Count]\nFROM cteA\nGROUP BY C, [Max];\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308342",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24065/"
] |
308,349 | <p>I've created a a folder and after I open a file inside of that folder a write on it.
It happens that after that I try to open the file but I have no permissions thus I have to change it manually.</p>
<pre><code>/* str1 has tha name of the folder */
/* str the bytes I want to write in the file inside the folder*/
...
mkdir(str1,0777);
if (filefd < 0) {
strncpy(auxstr, str, MAX_MSG + 1);
strcat(str1,"\\");
strcat(str1, auxstr);
filefd = open (str1, O_RDWR | O_CREAT | O_TRUNC);
nbytes -= (strlen(str) + 1);
memcpy(auxstr, &str[strlen(str)+1], nbytes);
memcpy(str, auxstr, nbytes);
}
/*write to the file */
if ((nwritten = write(filefd, str, nbytes)) != nbytes) {
printf ("can't write on file\n");
break;
}
</code></pre>
<p>What should I change in order to have permissions to open the created file?</p>
<p>Thanks a lot,</p>
<hr>
<p>:s</p>
<p>with = 0_CREATE I STILL have the problem of no having permissions to read the file.
I have to set them manually</p>
<hr>
<p>And I already have the 0_CREAT at the open</p>
<p>open (str1, O_RDWR | O_CREAT | O_TRUNC);</p>
| [
{
"answer_id": 308374,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 3,
"selected": false,
"text": "open()"
},
{
"answer_id": 308575,
"author": "wimh",
"author_id": 33499,
"author_profile": "https://Stackoverflow.com/users/33499",
"pm_score": 2,
"selected": false,
"text": "filefd = open (str1, O_RDWR | O_CREAT | O_TRUNC, 0777);\n"
},
{
"answer_id": 316443,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 2,
"selected": false,
"text": "/tmp"
},
{
"answer_id": 318022,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 0,
"selected": false,
"text": "'\\\\'"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308349",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
308,359 | <p>Is either:</p>
<pre><code><a href="#"><h1>text here</h1></a>
</code></pre>
<p>or</p>
<pre><code><h1><a href="#">text here</a></h1>
</code></pre>
<p>"correct". Is there any benefit of using the first one, it seems more logical to me. Perhaps from an SEO point?</p>
| [
{
"answer_id": 308375,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": true,
"text": "<h1><a href=\"#\">text here</a></h1>\n"
},
{
"answer_id": 308378,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": 0,
"selected": false,
"text": "<h*>"
},
{
"answer_id": 308459,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 0,
"selected": false,
"text": " <a><h1>foo</h1></a>\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26823/"
] |
308,364 | <p>I've just done a test with bitfields, and the results are surprising me. </p>
<pre><code>class test1 {
public:
bool test_a:1;
bool test_b:1;
bool test_c:1;
bool test_d:1;
bool test_e:1;
bool test_f:1;
bool test_g:1;
bool test_h:1;
};
class test2 {
public:
int test_a:1;
int test_b:1;
int test_c:1;
int test_d:1;
int test_e:1;
int test_f:1;
int test_g:1;
int test_h:1;
};
class test3 {
public:
int test_a:1;
bool test_b:1;
int test_c:1;
bool test_d:1;
int test_e:1;
bool test_f:1;
int test_g:1;
bool test_h:1;
};
</code></pre>
<p>The results were:-</p>
<pre><code>sizeof(test1) = 1 // This is what I'd expect. 8 bits in a byte
sizeof(test2) = 4 // Reasonable. Maybe padded out to the size of an int.
sizeof(test3) = 16 // What???
</code></pre>
<p>Is this what you'd expect, or a compiler bug? (Codegear C++ Builder 2007, btw...)</p>
| [
{
"answer_id": 308393,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 3,
"selected": false,
"text": "#ifndef __cplusplus\n#include <stdbool.h>\n#endif\n#include <stdio.h>\n\nstruct test1 {\n bool test_a:1;\n bool test_b:1;\n bool test_c:1;\n bool test_d:1;\n bool test_e:1;\n bool test_f:1;\n bool test_g:1;\n bool test_h:1;\n};\n\nstruct test2 {\n int test_a:1;\n int test_b:1;\n int test_c:1;\n int test_d:1;\n int test_e:1;\n int test_f:1;\n int test_g:1;\n int test_h:1;\n};\n\nstruct test3 {\n int test_a:1;\n bool test_b:1;\n int test_c:1;\n bool test_d:1;\n int test_e:1;\n bool test_f:1;\n int test_g:1;\n bool test_h:1;\n};\n\nint\nmain()\n{\n printf(\"%zu %zu %zu\\n\", sizeof (struct test1), sizeof (struct test2),\n sizeof (struct test3));\n return 0;\n}\n"
},
{
"answer_id": 308457,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 3,
"selected": false,
"text": "int"
},
{
"answer_id": 2929394,
"author": "t1t0",
"author_id": 352945,
"author_profile": "https://Stackoverflow.com/users/352945",
"pm_score": 1,
"selected": false,
"text": "#include <iostream>\nusing namespace std;\n\nbool ary_bool4[10];\n\nstruct MyStruct {\n bool a1 :1;\n bool a2 :1;\n bool a3 :1;\n bool a4 :1;\n char b1 :2;\n char b2 :2;\n char b3 :2;\n char b4 :6;\n char c1;\n};\n\nint main() {\n cout << \"char size:\\t\" << sizeof(char) << endl;\n cout << \"short int size:\\t\" << sizeof(short int) << endl;\n cout << \"default int size:\\t\" << sizeof(int) << endl;\n cout << \"long int size:\\t\" << sizeof(long int) << endl;\n cout << \"long long int size:\\t\" << sizeof(long long int) << endl;\n cout << \"ary_bool4 size:\\t\" << sizeof(ary_bool4) << endl;\n cout << \"MyStruct size:\\t\" << sizeof(MyStruct) << endl;\n // cout << \"long long long int size:\\t\" << sizeof(long long long int) << endl;\n return 0;\n}\n\nchar size: 1\nshort int size: 2\ndefault int size: 4\nlong int size: 4\nlong long int size: 8\nary_bool4 size: 10\nMyStruct size: 3\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
308,390 | <p>I know this may be simple but being C++ I doubt it will be. How do I convert a string in the form 01/01/2008 to a date so I can manipulate it? I am happy to break the string into the day month year constituents. Also happy if solution is Windows only.</p>
| [
{
"answer_id": 308399,
"author": "kenny",
"author_id": 3225,
"author_profile": "https://Stackoverflow.com/users/3225",
"pm_score": 4,
"selected": false,
"text": "#include <time.h>\nchar *strptime(const char *buf, const char *format, struct tm *tm);\n"
},
{
"answer_id": 308916,
"author": "Ubervan",
"author_id": 39634,
"author_profile": "https://Stackoverflow.com/users/39634",
"pm_score": 3,
"selected": false,
"text": "strptime"
},
{
"answer_id": 23798816,
"author": "DoubleYou",
"author_id": 2710064,
"author_profile": "https://Stackoverflow.com/users/2710064",
"pm_score": 2,
"selected": false,
"text": "strptime()"
},
{
"answer_id": 26739240,
"author": "Sergey Bromirskiy",
"author_id": 4086384,
"author_profile": "https://Stackoverflow.com/users/4086384",
"pm_score": 2,
"selected": false,
"text": "#include <time.h>\n#include <iostream>\n#include <sstream>\n#include <algorithm>\n\nusing namespace std;\n\nint main ()\n{\n time_t rawtime;\n struct tm * timeinfo;\n int year, month ,day;\n char str[256];\n\n cout << \"Inter date: \" << endl; \n cin.getline(str,sizeof(str));\n\n replace( str, str+strlen(str), '/', ' ' ); \n istringstream( str ) >> day >> month >> year;\n\n time ( &rawtime );\n timeinfo = localtime ( &rawtime );\n timeinfo->tm_year = year - 1900;\n timeinfo->tm_mon = month - 1;\n timeinfo->tm_mday = day;\n mktime ( timeinfo );\n\n strftime ( str, sizeof(str), \"%A\", timeinfo );\n cout << str << endl;\n system(\"pause\");\n return 0;\n}\n"
},
{
"answer_id": 29815202,
"author": "Vinoj John Hosan",
"author_id": 1587156,
"author_profile": "https://Stackoverflow.com/users/1587156",
"pm_score": 1,
"selected": false,
"text": "#include <stdio.h>\n#include \"boost/date_time/posix_time/posix_time.hpp\"\n\nint main()\n{ \nstd::string strTime = \"2007-04-11 06:18:29.000\";\nstd::tm tmTime = boost::posix_time::to_tm(boost::posix_time::time_from_string(strTime));\nreturn 0;\n}\n"
},
{
"answer_id": 32633458,
"author": "Johan Engblom",
"author_id": 4129764,
"author_profile": "https://Stackoverflow.com/users/4129764",
"pm_score": 2,
"selected": false,
"text": "using namespace boost::gregorian;\nusing namespace boost::posix_time; \nptime pt = time_from_string(\"20150917\");\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39634/"
] |
308,401 | <p>When I maximize 1 MDI child form, all MDI child forms would be maximized too. Is it possible to have 1 form maximized and another one not?</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 4186597,
"author": "jp2code",
"author_id": 153923,
"author_profile": "https://Stackoverflow.com/users/153923",
"pm_score": 0,
"selected": false,
"text": "Child1.Show()"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39635/"
] |
308,406 | <p>One of my custom developed <a href="http://en.wikipedia.org/wiki/ASP.NET" rel="nofollow noreferrer">ASP.NET</a> sites was hacked today: "Hacked By Swan (Please Stop Wars !.. )"
It is using ASP.NET and SQL Server 2005 and IIS 6.0 and Windows 2003 server.
I am not using Ajax and I think I am using stored procedures everywhere I am connecting to the database so I dont think it is <a href="http://en.wikipedia.org/wiki/SQL_injection" rel="nofollow noreferrer">SQL injection</a>.
I have now removed the write permission on the folders. </p>
<p>How can I find out what they did to hack the site and what to do to prevent it from happening again?</p>
<p>The server is up to date with all Windows updates. </p>
<p>What they have done is uploading 6 files (index.asp, index.html, index.htm,...) to the main directory for the website.</p>
<p>What log files should I upload?
I have log files for IIS from this folder: <code>c:\winnt\system32\LogFiles\W3SVC1</code>.
I am willing to show it to some of you but don't think it is good to post on the Internet. Anyone willing to take a look at it?</p>
<p>I have already searched on Google but the only thing I find there are other sites that have been hacked - I haven't been able to see any discussion about it.</p>
<p>I know this is not strictly related to programming but this is still an important thing for programmers and a lot of programmers have been hacked like this.</p>
| [
{
"answer_id": 308634,
"author": "digiguru",
"author_id": 5055,
"author_profile": "https://Stackoverflow.com/users/5055",
"pm_score": 3,
"selected": false,
"text": "Dim strSQL As String = \"Select * FROM USERS Where name = '\" & Response.Querystring(\"name\") \"'\"\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308406",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26817/"
] |
308,417 | <p>I have some issue with a Perl script. It modifies the content of a file, then reopen it to write it, and in the process some characters are lost. All words starting with '%' are deleted from the file. That's pretty annoying because the % expressions are variable placeholders for dialog boxes.</p>
<p>Do you have any idea why? Source file is an XML with default encoding</p>
<p>Here is the code:</p>
<pre><code>undef $/;
open F, $file or die "cannot open file $file\n";
my $content = <F>;
close F;
$content =~s{status=["'][\w ]*["']\s*}{}gi;
printf $content;
open F, ">$file" or die "cannot reopen $file\n";
printf F $content;
close F or die "cannot close file $file\n";
</code></pre>
| [
{
"answer_id": 308434,
"author": "brian d foy",
"author_id": 2766176,
"author_profile": "https://Stackoverflow.com/users/2766176",
"pm_score": 6,
"selected": true,
"text": "printf"
},
{
"answer_id": 308437,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 2,
"selected": false,
"text": "printf \"%s\", $content;\n"
},
{
"answer_id": 310159,
"author": "Joe McMahon",
"author_id": 39791,
"author_profile": "https://Stackoverflow.com/users/39791",
"pm_score": 0,
"selected": false,
"text": "perl -i bak -pe 's{status=[\"\\'][\\w ]*[\"\\']\\s*}{}gi;' yourfiles\n"
},
{
"answer_id": 312666,
"author": "Yanick",
"author_id": 10356,
"author_profile": "https://Stackoverflow.com/users/10356",
"pm_score": 0,
"selected": false,
"text": "$ pyx doc.xml | perl -ne'print unless /^Astatus/' | pyxw\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29568/"
] |
308,427 | <p>I need a collection that </p>
<ul>
<li>contains a set of objects linked to a double.</li>
<li>The sequence of these pairs should be arbitrary set by me (based on an int I get from the database) and be static throughout the lifecycle.</li>
<li>The number of entries will be small (0 ~ 20) but varying.</li>
<li>The collection should be itteratable.</li>
<li>I don't have to search the collection for anything.</li>
<li>The double will be changed after intialization of the collection.</li>
<li>I would like to work with existing datatypes (no new classes) since it will be used in my asp.net mvc controllers, views and services and I don't want them to all to have a dependency on a library just for this stupid holder class.</li>
</ul>
<p>I thought </p>
<pre><code>IDictionary<int, KeyvaluePair<TheType, double>>
</code></pre>
<p>would do the trick, but then I can't set the double after init.</p>
<p><strong>--Edit--</strong><br>
I found out that the classes generated by the linq 2 sql visual studio thingy are actually partial classes so you can add to them whatever you want. I solved my question by adding a double field to the partial class.<br>
Thanks all for the answers you came up with.</p>
| [
{
"answer_id": 308441,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "KeyValuePair"
},
{
"answer_id": 308445,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 0,
"selected": false,
"text": "yourDict[10] = new KeyValuePair<TheType, Double>(yourDict[10].Key, newValue);\n"
},
{
"answer_id": 308447,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 1,
"selected": false,
"text": "struct MyPair\n{\n public object TheType;\n public double Value;\n}\n\nMyPair[] MyColleccyion = new MyPair[20]; \n"
},
{
"answer_id": 308448,
"author": "Hath",
"author_id": 5186,
"author_profile": "https://Stackoverflow.com/users/5186",
"pm_score": 0,
"selected": false,
"text": "public class ListThing<TKey, TValue> : Dictionary<TKey, TValue>\n{\n public double DoubleThing { get; set; }\n\n public ListThing(double value)\n {\n DoubleThing = value;\n }\n}\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
308,428 | <p>If I type the command:</p>
<pre><code>mvn dependency:list
</code></pre>
<p>The <a href="http://maven.apache.org/plugins/maven-dependency-plugin/" rel="nofollow noreferrer">docs</a> suggest that I'll get a list of my project's dependencies. Instead though, I get this:</p>
<pre><code>[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] -----------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] -----------------------------------------------------------
[INFO] Required goal not found: dependency:list
</code></pre>
<p>Call me a hopeful naive, but I had hoped maven would download any plugins it didn't have. Does anyone know what might be leading to this error? Does anyone know where maven stores information about what plugins it has installed, and where they're stored in the maven repository?</p>
| [
{
"answer_id": 308480,
"author": "Ivan Dubrov",
"author_id": 31118,
"author_profile": "https://Stackoverflow.com/users/31118",
"pm_score": 2,
"selected": false,
"text": "mvn -cpu dependency:list"
},
{
"answer_id": 308663,
"author": "Michael Rutherfurd",
"author_id": 33889,
"author_profile": "https://Stackoverflow.com/users/33889",
"pm_score": 2,
"selected": false,
"text": "<proxies>\n <proxy>\n <id>proxy</id> \n <active>true</active> \n <username>user</username>\n <password>passwrd</password>\n <protocol>http</protocol>\n <host>example.proxy.name.com</host>\n <port>80</port>\n </proxy>\n</proxies>\n"
},
{
"answer_id": 553999,
"author": "Matthew McCullough",
"author_id": 56039,
"author_profile": "https://Stackoverflow.com/users/56039",
"pm_score": 1,
"selected": false,
"text": "mvn <yourgoal> -X -e"
},
{
"answer_id": 52734222,
"author": "Dragas",
"author_id": 6523288,
"author_profile": "https://Stackoverflow.com/users/6523288",
"pm_score": 0,
"selected": false,
"text": "install"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/974/"
] |
308,436 | <p>How to (programmatically, without xml config) configure multiple loggers with Log4Net?
I need them to write to different files.</p>
| [
{
"answer_id": 308544,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 7,
"selected": true,
"text": "using log4net;\nusing log4net.Appender;\nusing log4net.Layout;\nusing log4net.Repository.Hierarchy;\n\n// Set the level for a named logger\npublic static void SetLevel(string loggerName, string levelName)\n{\n ILog log = LogManager.GetLogger(loggerName);\n Logger l = (Logger)log.Logger;\n\n l.Level = l.Hierarchy.LevelMap[levelName];\n }\n\n// Add an appender to a logger\npublic static void AddAppender(string loggerName, IAppender appender)\n{\n ILog log = LogManager.GetLogger(loggerName);\n Logger l = (Logger)log.Logger;\n\n l.AddAppender(appender);\n}\n\n// Create a new file appender\npublic static IAppender CreateFileAppender(string name, string fileName)\n{\n FileAppender appender = new\n FileAppender();\n appender.Name = name;\n appender.File = fileName;\n appender.AppendToFile = true;\n\n PatternLayout layout = new PatternLayout();\n layout.ConversionPattern = \"%d [%t] %-5p %c [%x] - %m%n\";\n layout.ActivateOptions();\n\n appender.Layout = layout;\n appender.ActivateOptions();\n\n return appender;\n}\n\n// In order to set the level for a logger and add an appender reference you\n// can then use the following calls:\nSetLevel(\"Log4net.MainForm\", \"ALL\");\nAddAppender(\"Log4net.MainForm\", CreateFileAppender(\"appenderName\", \"fileName.log\"));\n\n// repeat as desired\n"
},
{
"answer_id": 11080514,
"author": "Narottam Goyal",
"author_id": 1175623,
"author_profile": "https://Stackoverflow.com/users/1175623",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing Com.Foo;\nusing System.Collections.Generic;\nusing System.Text;\nusing log4net.Config;\nusing log4net;\nusing log4net.Appender;\nusing log4net.Layout;\nusing log4net.Repository.Hierarchy;\n\n\npublic class MyApp\n{\n\n\n public static void SetLevel(string loggerName, string levelName)\n {\n ILog log = LogManager.GetLogger(loggerName);\n Logger l = (Logger)log.Logger;\n\n l.Level = l.Hierarchy.LevelMap[levelName];\n }\n\n // Add an appender to a logger\n public static void AddAppender(string loggerName, IAppender appender)\n {\n ILog log = LogManager.GetLogger(loggerName);\n Logger l = (Logger)log.Logger;\n\n l.AddAppender(appender);\n }\n // Add an appender to a logger\n public static void AddAppender2(ILog log, IAppender appender)\n {\n // ILog log = LogManager.GetLogger(loggerName);\n Logger l = (Logger)log.Logger;\n\n l.AddAppender(appender);\n }\n\n // Create a new file appender\n public static IAppender CreateFileAppender(string name, string fileName)\n {\n FileAppender appender = new\n FileAppender();\n appender.Name = name;\n appender.File = fileName;\n appender.AppendToFile = true;\n\n PatternLayout layout = new PatternLayout();\n layout.ConversionPattern = \"%d [%t] %-5p %c [%logger] - %m%n\";\n layout.ActivateOptions();\n\n appender.Layout = layout;\n appender.ActivateOptions();\n\n return appender;\n }\n\n private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));\n static void Main(string[] args)\n {\n BasicConfigurator.Configure();\n SetLevel(\"Log4net.MainForm\", \"ALL\");\n AddAppender2(log, CreateFileAppender(\"appenderName\", \"fileName.log\"));\n log.Info(\"Entering application.\");\n Console.WriteLine(\"starting.........\");\n log.Info(\"Entering application.\");\n Bar bar = new Bar();\n bar.DoIt();\n Console.WriteLine(\"starting.........\");\n log.Error(\"Exiting application.\");\n Console.WriteLine(\"starting.........\");\n }\n}\n\n\nnamespace Com.Foo\n{\n public class Bar\n {\n private static readonly ILog log = LogManager.GetLogger(typeof(Bar));\n\n public void DoIt()\n {\n log.Debug(\"Did it again!\");\n }\n }\n}\n"
},
{
"answer_id": 45549280,
"author": "G.Y",
"author_id": 1310846,
"author_profile": "https://Stackoverflow.com/users/1310846",
"pm_score": 2,
"selected": false,
"text": "static void Main(string[] args)\n{\n const string logLayoutPattern =\n \"[%date %timestamp][%level] %message %newline\" +\n \"Domain: %appdomain, User: %username %identity %newline\" +\n \"%stacktracedetail{10} %newline\" +\n \"%exception %newline\";\n\n var wrapperLogger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);\n var logger = (Logger) wrapperLogger.Logger;\n logger.Hierarchy.Root.Level = Level.All;\n\n var consoleAppender = new ConsoleAppender\n {\n Name = \"ConsoleAppender\",\n Layout = new PatternLayout(logLayoutPattern)\n };\n\n logger.Hierarchy.Root.AddAppender(consoleAppender);\n logger.Hierarchy.Configured = true;\n\n wrapperLogger.Debug(\"Hello\");\n Console.ReadKey();\n}\n"
},
{
"answer_id": 52162977,
"author": "pasx",
"author_id": 683319,
"author_profile": "https://Stackoverflow.com/users/683319",
"pm_score": 0,
"selected": false,
"text": "public static Log = new Log4NetWrapper.LogWrapper().Setup(@\"c:\\myLog.log\", \"TestLog\");\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35425/"
] |
308,438 | <p>I am using tinyMCE and, rather annoyingly, it replaces all of my apostrophes with their HTML numeric equivalent. Now most of the time this isn't a problem but for some reason I am having a problem storing the apostrophe replacement. So i have to search through the string and replace them all. Any help would be much appreciated</p>
| [
{
"answer_id": 308439,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": true,
"text": "$string = str_replace(\"'\", \"<replacement>\", $string);\n"
},
{
"answer_id": 308574,
"author": "RJHunter",
"author_id": 39223,
"author_profile": "https://Stackoverflow.com/users/39223",
"pm_score": 2,
"selected": false,
"text": "print html_entity_decode(\"Hello, that's an apostophe.\", ENT_QUOTE);\n"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31677/"
] |
308,454 | <p>What is the difference between web reference and service reference in WCF?
Which is preferable in WCF?</p>
| [
{
"answer_id": 2973819,
"author": "Christian Hayter",
"author_id": 115413,
"author_profile": "https://Stackoverflow.com/users/115413",
"pm_score": 6,
"selected": false,
"text": "basicHttpBinding"
}
] | 2008/11/21 | [
"https://Stackoverflow.com/questions/308454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.