text
stringlengths
0
30.5k
title
stringclasses
1 value
embeddings
listlengths
768
768
I have an absolutely positioned `div` containing several children, one of which is a relatively positioned `div`. When I use a `percentage-based width` on the child `div`, it collapses to `0 width` on IE7, but not on Firefox or Safari. If I use `pixel width`, it works. If the parent is relatively positioned, the percentage width on the child works. 1. Is there something I'm missing here? 2. Is there an easy fix for this besides the `pixel-based width` on the child? 3. Is there an area of the CSS specification that covers this? The parent `div` needs to have a defined `width`, either in
[ 0.36346691846847534, 0.13352739810943604, 0.38462021946907043, -0.09144695103168488, 0.03362520784139633, 0.2223886251449585, 0.15952709317207336, 0.04703124985098839, 0.16300109028816223, -0.9281088709831238, -0.14638856053352356, 0.44247904419898987, -0.10123006999492645, -0.034093007445...
pixels or as a percentage. In Internet Explorer 7, the parent `div` needs a defined `width` for child percentage `div`s to work correctly.
[ 0.15191926062107086, -0.25587400794029236, 0.6354948878288269, 0.020723257213830948, -0.0793287456035614, 0.21894772350788116, -0.1288432627916336, 0.17382661998271942, 0.1672404408454895, -0.7667054533958435, -0.317180335521698, 0.36258769035339355, 0.08587139844894409, 0.2893849313259125...
Given a specific `DateTime` value, how do I display relative time, like: * `2 hours ago` * `3 days ago` * `a month ago` Jeff, [your code](https://stackoverflow.com/questions/11/how-do-i-calculate-relative-time/12#12) is nice but could be clearer with constants (as suggested in Code Complete). ```csharp const int SECOND = 1; const int MINUTE = 60 * SECOND; const int HOUR = 60 * MINUTE; const int DAY = 24 * HOUR; const int MONTH = 30 * DAY; var ts = new TimeSpan(DateTime.UtcNow.Ticks - yourDate.Ticks); double delta = Math.Abs(ts.TotalSeconds); if (delta < 1 * MINUTE) return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago"; if (delta < 2 * MINUTE) return
[ 0.24956881999969482, -0.28400707244873047, 0.42697280645370483, -0.10366053879261017, 0.26754510402679443, 0.18187139928340912, 0.29238608479499817, -0.19562628865242004, -0.29250016808509827, -0.6917046904563904, 0.006741516292095184, 0.0965135395526886, -0.013536662794649601, 0.218175485...
"a minute ago"; if (delta < 45 * MINUTE) return ts.Minutes + " minutes ago"; if (delta < 90 * MINUTE) return "an hour ago"; if (delta < 24 * HOUR) return ts.Hours + " hours ago"; if (delta < 48 * HOUR) return "yesterday"; if (delta < 30 * DAY) return ts.Days + " days ago"; if (delta < 12 * MONTH) { int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30)); return months <= 1 ? "one month ago" : months + " months ago"; } else { int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365)); return years <= 1 ? "one year ago"
[ 0.07253585755825043, -0.07856756448745728, 0.476757287979126, -0.11133746802806854, 0.3970925509929657, 0.3570560812950134, 0.104275643825531, -0.2949689030647278, -0.5174269676208496, -0.6097415685653687, -0.2055000513792038, 0.05089900642633438, 0.2416483759880066, 0.6006153225898743, ...
: years + " years ago"; } ```
[ 0.14279472827911377, 0.205266073346138, 0.1523635983467102, -0.20425456762313843, 0.4491024613380432, 0.002300682943314314, -0.1355222463607788, 0.21907761693000793, -0.34782448410987854, -0.19284705817699432, -0.1489245742559433, 0.1278957575559616, -0.008299010805785656, 0.71591150760650...
I am starting a new web application in PHP and this time around I want to create something that people can extend by using a plugin interface. How does one go about writing 'hooks' into their code so that plugins can attach to specific events? You could use an Observer pattern. A simple functional way to accomplish this: ``` <?php /** Plugin system **/ $listeners = array(); /* Create an entry point for plugins */ function hook() { global $listeners; $num_args = func_num_args(); $args = func_get_args(); if($num_args < 2)
[ 0.4421554505825043, -0.005190020892769098, 0.4554086923599243, -0.20815224945545197, -0.07669562101364136, -0.21639741957187653, 0.3228580951690674, -0.03867804631590843, -0.46694716811180115, -0.5472612380981445, 0.0938263088464737, 0.47780320048332214, -0.4415806829929352, 0.011794770136...
trigger_error("Insufficient arguments", E_USER_ERROR); // Hook name should always be first argument $hook_name = array_shift($args); if(!isset($listeners[$hook_name])) return; // No plugins have registered this hook foreach($listeners[$hook_name] as $func) { $args = $func($args); } return $args; } /* Attach a function to a hook */ function add_listener($hook, $function_name) { global $listeners; $listeners[$hook][] = $function_name; } ///////////////////////// /** Sample Plugin **/ add_listener('a_b', 'my_plugin_func1'); add_listener('str', 'my_plugin_func2'); function my_plugin_func1($args) { return array(4,
[ 0.07736250013113022, 0.02419062703847885, 0.5367022752761841, -0.5781400203704834, -0.24278901517391205, 0.13852280378341675, 0.09308016300201416, -0.6947160363197327, -0.057684529572725296, -0.24940721690654755, -0.16502289474010468, 0.7794996500015259, -0.6423627734184265, -0.08870970457...
5); } function my_plugin_func2($args) { return str_replace('sample', 'CRAZY', $args[0]); } ///////////////////////// /** Sample Application **/ $a = 1; $b = 2; list($a, $b) = hook('a_b', $a, $b); $str = "This is my sample application\n"; $str .= "$a + $b = ".($a+$b)."\n"; $str .= "$a * $b = ".($a*$b)."\n"; $str = hook('str', $str); echo $str; ?> ``` **Output:** ``` This is my CRAZY application 4 + 5 = 9 4 * 5 = 20 ``` **Notes:** For this example source code, you must declare all your plugins before the actual source code that you want to be extendable. I've included an example of how to handle single or multiple values being passed to the plugin. The hardest part of this
[ 0.3754497468471527, -0.0014767521061003208, 0.4796118438243866, 0.046504996716976166, 0.5728389024734497, -0.2168828696012497, 0.3094688653945923, -0.3971203565597534, -0.18876153230667114, 0.22605222463607788, -0.13674379885196686, 0.2720741033554077, -0.7520964741706848, 0.12527422606945...
is writing the actual documentation which lists what arguments get passed to each hook. This is just one method of accomplishing a plugin system in PHP. There are better alternatives, I suggest you check out the WordPress Documentation for more information.
[ 0.5995470881462097, 0.017877129837870598, -0.1137194111943245, 0.19938625395298004, -0.04159931093454361, -0.11741789430379868, -0.16675151884555817, -0.10620588809251785, 0.0985155925154686, -0.3959710896015167, 0.3599050045013428, 0.7480803728103638, -0.16251768171787262, -0.344789922237...
I have a `DataTable` with a `Name` column. I want to generate a collection of the unique names ordered alphabetically. The following query ignores the *order by* clause. ``` var names = (from DataRow dr in dataTable.Rows orderby (string)dr["Name"] select (string)dr["Name"]).Distinct(); ``` Why does the `orderby` not get enforced? To make it more readable and maintainable, you can also split it up into multiple LINQ statements. 1. First, select your data into a new list, let's call it `x1`, do a projection if desired 2. Next, create a distinct list, from `x1` into `x2`, using whatever distinction you
[ -0.016385691240429878, 0.16897258162498474, 0.4828588366508484, 0.02279658056795597, -0.10589967668056488, -0.024910246953368187, -0.26169976592063904, -0.3539438843727112, -0.20900700986385345, -0.5196703672409058, -0.13767559826374054, 0.3121918737888336, -0.42758598923683167, 0.40025031...
require 3. Finally, create an ordered list, from `x2` into `x3`, sorting by whatever you desire
[ -0.025671212002635002, 0.15197773277759552, 0.1261376589536667, -0.01233804039657116, -0.07477953284978867, 0.006084283348172903, -0.1126895323395729, -0.4853145480155945, -0.21397222578525543, -0.48161306977272034, -0.39210954308509827, 0.17122229933738708, -0.6176410913467407, -0.2428212...
I am porting a game, that was originally written for the Win32 API, to Linux (well, porting the OS X port of the Win32 port to Linux). I have implemented `QueryPerformanceCounter` by giving the uSeconds since the process start up: ``` BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount) { gettimeofday(&currentTimeVal, NULL); performanceCount->QuadPart = (currentTimeVal.tv_sec - startTimeVal.tv_sec); performanceCount->QuadPart *= (1000 * 1000); performanceCount->QuadPart += (currentTimeVal.tv_usec - startTimeVal.tv_usec); return true; } ``` This, coupled with `QueryPerformanceFrequency()` giving a constant 1000000 as the frequency, works well **on my machine**, giving me a 64-bit variable that contains `uSeconds` since
[ 0.3094436824321747, -0.32023996114730835, 1.0692250728607178, -0.19456009566783905, 0.12836454808712006, -0.27462708950042725, 0.28511935472488403, -0.38131383061408997, 0.024111630395054817, -0.9511324763298035, -0.24335724115371704, 0.8270329833030701, -0.0969851091504097, 0.402014166116...
the program's start-up. So *is this portable?* I don't want to discover it works differently if the kernel was compiled in a certain way or anything like that. I am fine with it being non-portable to something other than Linux, however. Maybe. But you have bigger problems. `gettimeofday()` can result in incorrect timings if there are processes on your system that change the timer (ie, ntpd). On a "normal" linux, though, I believe the resolution of `gettimeofday()` is 10us. It can jump forward and backward and time, consequently, based on the processes running on your system. This effectively makes the answer to
[ 0.09044951945543289, -0.2703722417354584, 0.40060457587242126, 0.11985131353139877, 0.049164220690727234, -0.17826451361179352, 0.29276043176651, 0.08701144903898239, -0.3628523051738739, -0.8910126686096191, -0.030048027634620667, 0.62862628698349, -0.2596869170665741, -0.0091638956218957...
your question no. You should look into `clock_gettime(CLOCK_MONOTONIC)` for timing intervals. It suffers from several less issues due to things like multi-core systems and external clock settings. Also, look into the `clock_getres()` function.
[ 0.40743252635002136, -0.1223515123128891, 0.2742648124694824, 0.26785436272621155, 0.09110730141401291, -0.09966125339269638, 0.12890630960464478, -0.21718494594097137, -0.15133361518383026, -0.40677157044410706, -0.02714494988322258, 0.7128232717514038, -0.23433516919612885, -0.0511417761...
How do you [branch and merge](http://svnbook.red-bean.com/en/1.8/svn.branchmerge.html) with Apache Subversion using the TortoiseSVN client? My easy click-by-click instructions (**specific to TortoiseSVN**) are in Stack Overflow question *[What is the simplest way to do branching and merging using TortoiseSVN?](https://stackoverflow.com/questions/1461922)*.
[ -0.07747363299131393, -0.5016990303993225, 0.41302913427352905, -0.025561684742569923, 0.2758564352989197, -0.22440402209758759, 0.29309332370758057, -0.0886038988828659, -0.5776097774505615, -0.20124614238739014, -0.18347838521003723, 0.5707523226737976, 0.013024878688156605, -0.188578650...
Recently our site has been deluged with the resurgence of the [Asprox botnet](https://en.wikipedia.org/wiki/Asprox_botnet) [SQL injection](http://en.wikipedia.org/wiki/SQL_injection) attack. Without going into details, the attack attempts to execute SQL code by encoding the [T-SQL](http://en.wikipedia.org/wiki/Transact-SQL) commands in an ASCII encoded BINARY string. It looks something like this: ``` DECLARE%20@S%20NVARCHAR(4000);SET%20@S=CAST(0x44004500...06F007200%20AS%20NVARCHAR(4000));EXEC(@S);-- ``` I was able to decode this in SQL, but I was a little wary of doing this since I didn't know exactly what was happening at the time. I tried to write a simple decode tool, so I could decode this type of text without even touching [SQL  Server](http://en.wikipedia.org/wiki/Microsoft_SQL_Server). The main part I need to be decoded is: ``` CAST(0x44004500...06F007200 AS NVARCHAR(4000)) ``` I've
[ 0.500487744808197, 0.1792416125535965, 0.38960495591163635, -0.19775666296482086, -0.3013199269771576, 0.06475268304347992, 0.36151784658432007, -0.17302757501602173, -0.40799278020858765, -0.5556366443634033, -0.029543820768594742, 0.41871505975723267, -0.2925300598144531, 0.3383283317089...
tried all of the following commands with no luck: ``` txtDecodedText.Text = System.Web.HttpUtility.UrlDecode(txtURLText.Text); txtDecodedText.Text = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(txtURLText.Text)); txtDecodedText.Text = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(txtURLText.Text)); txtDecodedText.Text = Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(txtURLText.Text)); txtDecodedText.Text = Encoding.Unicode.GetString(Convert.FromBase64String(txtURLText.Text)); ``` What is the proper way to translate this encoding without using SQL Server? Is it possible? I'll take VB.NET code since I'm familiar with that too. --- Okay, I'm sure I'm missing something here, so here's where I'm at. Since my input is a basic string, I started with just a snippet of the encoded portion - 4445434C41 (which translates to DECLA) - and the first attempt was to do
[ -0.09438242018222809, 0.06099672242999077, 0.297406405210495, -0.03574668988585472, 0.07466858625411987, 0.15183860063552856, 0.3888634145259857, -0.0397023968398571, -0.09023777395486832, -0.8596802353858948, -0.250889390707016, 0.43567606806755066, -0.26468625664711, 0.10811138153076172,...
this... ``` txtDecodedText.Text = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(txtURL.Text)); ``` ...and all it did was return the exact same thing that I put in since it converted each character into is a byte. I realized that I need to parse every two characters into a byte manually since I don't know of any methods yet that will do that, so now my little decoder looks something like this: ``` while (!boolIsDone) { bytURLChar = byte.Parse(txtURLText.Text.Substring(intParseIndex, 2)); bytURL[intURLIndex] = bytURLChar; intParseIndex += 2; intURLIndex++; if (txtURLText.Text.Length - intParseIndex < 2) {
[ -0.06417319923639297, 0.15463270246982574, 0.5255129933357239, -0.31394249200820923, -0.10719610005617142, 0.16676262021064758, 0.5240745544433594, -0.5543175935745239, -0.13334710896015167, -0.32142508029937744, -0.34025344252586365, 0.4220837950706482, -0.5442742705345154, 0.097984962165...
boolIsDone = true; } } txtDecodedText.Text = Encoding.UTF8.GetString(bytURL); ``` Things look good for the first couple of pairs, but then the loop balks when it gets to the "4C" pair and says that the string is in the incorrect format. Interestingly enough, when I step through the debugger and to the GetString method on the byte array that I was able to parse up to that point, I get ",-+" as the result. How do I figure out what I'm missing - do I need to do a "direct cast" for each byte instead of attempting to parse it? I went
[ 0.23367802798748016, 0.2154482752084732, 0.31609204411506653, -0.37639278173446655, 0.008065910078585148, -0.25268250703811646, 0.7703119516372681, -0.2975888252258301, -0.1562913954257965, -0.14971742033958435, -0.1282278597354889, 0.5583279132843018, -0.4493895471096039, 0.19565756618976...
back to Michael's post, did some more poking and realized that I did need to do a double conversion, and eventually worked out this little nugget: ``` Convert.ToString(Convert.ToChar(Int32.Parse(EncodedString.Substring(intParseIndex, 2), System.Globalization.NumberStyles.HexNumber))); ``` From there I simply made a loop to go through all the characters 2 by 2 and get them "hexified" and then translated to a string. To Nick, and anybody else interested, I went ahead and [posted my little application](http://www.codeplex.com/urldecoder) over in [CodePlex](http://en.wikipedia.org/wiki/CodePlex). Feel free to use/modify as you need.
[ 0.45894965529441833, 0.3111284673213959, 0.2788161039352417, -0.10015000402927399, -0.280887246131897, 0.133483424782753, 0.30929410457611084, 0.18554121255874634, -0.25205686688423157, -0.6836779713630676, 0.07645153999328613, 0.15510165691375732, -0.4047987759113312, 0.040666233748197556...
I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it. Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded? --- > Is the play link a link to the actual > mp3 file or to some javascript code > that pops up a player? > > > If the latter, you can easily add your > own logging code in there to track the > number of hits to it. > > > If the
[ 0.5549465417861938, 0.21741612255573273, 0.1662733107805252, 0.09115917235612869, -0.05676177144050598, -0.3801269233226776, -0.22183677554130554, 0.08043500036001205, -0.30891427397727966, -0.5697299838066101, 0.15793369710445404, 0.7766667008399963, -0.1567070484161377, 0.025443829596042...
former, you'll need something > that can track the web server log > itself and make that distinction. My > hosting plan comes with Webalizer, > which does this nicely. It's a javascript code so that answers that. However, it would be nice to know how to track downloads using the other method (without switching hosts). The funny thing is I wrote a php media gallery for all my musics 2 days ago. I had a similar problem. I'm using <http://musicplayer.sourceforge.net/> for the player. And the playlist is built via php. All music requests go to a script called xfer.php?file=WHATEVER ``` $filename = base64_url_decode($_REQUEST['file']); header("Cache-Control:
[ 0.2611217200756073, 0.13180051743984222, 0.7261233925819397, 0.32564353942871094, 0.11655770987272263, -0.3044450283050537, -0.018419548869132996, -0.12345638126134872, -0.5275558829307556, -0.6079345941543579, 0.11775972694158554, 0.8780531287193298, -0.2182609587907791, 0.185261130332946...
public"); header('Content-disposition: attachment; filename='.basename($filename)); header("Content-Transfer-Encoding: binary"); header('Content-Length: '. filesize($filename)); // Put either file counting code here, either a db or static files // readfile($filename); //and spit the user the file function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } ``` And when you call files use something like: ``` function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); } ``` <http://us.php.net/manual/en/function.base64-encode.php> If you are using some JavaScript or a flash player (JW player for example) that requires the actual link of an mp3 file or whatever, you can append the text "&type=.mp3" so the final link becomes something like: "www.example.com/xfer.php?file=34842ffjfjxfh&type=.mp3". That way it looks like it ends with an mp3 extension
[ 0.2547852396965027, 0.19268831610679626, 0.46486470103263855, -0.14959676563739777, -0.11514370888471603, -0.26942646503448486, 0.2529810965061188, -0.15558327734470367, -0.20084673166275024, -0.4601380228996277, -0.6155524849891663, 0.6066221594810486, -0.5130912661552429, 0.2910292446613...
without affecting the file link.
[ 0.040743812918663025, 0.04027979448437691, 0.34639015793800354, 0.05194270610809326, 0.12811526656150818, -0.2584969699382782, 0.16704320907592773, -0.06818071007728577, -0.2047058343887329, -0.35559403896331787, -0.4014594852924347, 0.3438870310783386, -0.06255817413330078, 0.053870256990...
Stack Overflow has a subversion version number at the bottom: > svn revision: 679 I want to use such automatic versioning with my `.NET Web Site/Application`, Windows Forms, WPD projects/solutions. How do I implement this? Looks like Jeff is using [CruiseControl.NET](https://web.archive.org/web/20090130045625/http://confluence.public.thoughtworks.org/display/CCNET/What+is+CruiseControl.NET) based on some leafing through the podcast transcripts. This seems to have automated deployment capabilities from source control to production. Might this be where the insertion is happening?
[ -0.2307431697845459, -0.04088889807462692, 0.6215137243270874, 0.04950765520334244, 0.3056453764438629, -0.15713994204998016, 0.1825382262468338, -0.16687460243701935, -0.5677107572555542, -0.25953367352485657, -0.05419092997908592, 0.569230318069458, -0.017915047705173492, -0.002906730398...
This is something I've pseudo-solved many times and have never quite found a solution for. The problem is to come up with a way to generate `N` colors, that are as distinguishable as possible where `N` is a parameter. My first thought on this is "how to generate N vectors in a space that maximize distance from each other." You can see that the RGB (or any other scale you use that forms a basis in color space) are just vectors. Take a look at [Random Point Picking](http://mathworld.wolfram.com/topics/RandomPointPicking.html). Once you have a set of vectors that are maximized apart, you can save them
[ 0.3885340690612793, -0.28406888246536255, -0.10851825773715973, 0.12397102266550064, 0.0016562845557928085, 0.21461130678653717, -0.35265791416168213, 0.040807824581861496, -0.3821687698364258, -0.8426895141601562, 0.39551499485969543, 0.27313271164894104, -0.48119208216667175, 0.191393762...
in a hash table or something for later, and just perform random rotations on them to get all the colors you desire that are maximally apart from each other! Thinking about this problem more, it would be better to map the colors in a linear manner, possibly (0,0,0) → (255,255,255) lexicographically, and then distribute them evenly. I really don't know how well this will work, but it should since, let us say: ``` n = 10 ``` we know we have 16777216 colors (256^3). We can use [Buckles Algorithm 515](https://stackoverflow.com/questions/561/using-combinations-of-sets-as-test-data#794) to find the lexicographically indexed color.![\frac {\binom {256^3} {3}} {n} * i](https://i.stack.imgur.com/gEuCs.gif). You'll probably have to edit
[ 0.09654178470373154, -0.031092870980501175, 0.2570190727710724, 0.007908494211733341, 0.03785601258277893, -0.05279766023159027, 0.16520647704601288, -0.2710069417953491, -0.48241326212882996, -0.7473191618919373, -0.23593741655349731, 0.5312584042549133, -0.5185238122940063, -0.0790092870...
the algorithm to avoid overflow and probably add some minor speed improvements.
[ -0.20138610899448395, 0.25008833408355713, 0.5488809943199158, 0.19507090747356415, 0.10505948960781097, 0.08148542791604996, 0.22409507632255554, -0.0945533737540245, -0.01846614107489586, -0.6925172209739685, -0.05010971799492836, 0.4072766602039337, -0.10229986160993576, -0.215368866920...
Does anybody know if there is a way to create an SQLite database based on an XSD `DataSet`? In the past, I've just used a basic SQLite manager, but I want to fuse things a bit more with my `.NET` development if possible. I suspect in the general case this is hard; XML Schema allows for some quite bizarre type constructions. I'm not sure how you would do substitution groups, or extensions to restrictions of types for example. However it should be possible to knock something together quite quickly (especially mapping from the classes in System.Xml.Schema) that works for 90% of schemas
[ 0.37352386116981506, 0.24252799153327942, -0.06095628812909126, 0.2548395097255707, 0.03425000607967377, -0.27866438031196594, 0.1799774467945099, 0.11450792104005814, -0.2470097541809082, -0.6035146713256836, 0.25443270802497864, 0.4543845057487488, -0.1419605165719986, 0.0709218606352806...
(i.e. sequence and choice elements with a few simple data types).
[ 0.04292970895767212, 0.03251860290765762, -0.23171266913414001, 0.27392712235450745, 0.2733028829097748, 0.1348276436328888, -0.17118464410305023, -0.2290576845407486, -0.035541996359825134, -0.5609593391418457, -0.4829797148704529, 0.21245704591274261, -0.19417628645896912, -0.00182105542...
I have a little game written in C#. It uses a database as back-end. It's a [trading card game](http://en.wikipedia.org/wiki/Collectible_card_game), and I wanted to implement the function of the cards as a script. What I mean is that I essentially have an interface, `ICard`, which a card class implements (`public class Card056: ICard`) and which contains a function that is called by the game. Now, to make the thing maintainable/moddable, I would like to have the class for each card as source code in the database and essentially compile it on first use. So when I have to add/change a card, I'll just
[ 0.3697289526462555, 0.01188751682639122, 0.13299493491649628, 0.3780822157859802, 0.1624370515346527, -0.35147401690483093, -0.37030938267707825, -0.07191001623868942, -0.24039477109909058, -0.13522426784038544, 0.16397009789943695, 0.3200318217277527, -0.08183694630861282, 0.2762309312820...
add it to the database and tell my application to refresh, without needing any assembly deployment (especially since we would be talking about 1 assembly per card which means hundreds of assemblies). Is that possible? Register a class from a source file and then instantiate it, etc. ``` ICard Cards[current] = new MyGame.CardLibrary.Card056(); Cards[current].OnEnterPlay(ref currentGameState); ``` The language is C# but extra bonus if it's possible to write the script in any .NET language. [Oleg Shilo's C# Script solution (at The Code Project](https://www.codeproject.com/Articles/8656/C-Script-The-Missing-Puzzle-Piece)) really is a great introduction to providing script abilities in your application. A different approach would be to consider a language that is specifically built
[ 0.1279614120721817, 0.07140643894672394, 0.29131078720092773, 0.17205357551574707, 0.04623683914542198, -0.20128211379051208, -0.0815558061003685, -0.1728701889514923, -0.3821239769458771, -0.49983012676239014, 0.05274006724357605, 0.2553313076496124, -0.18876147270202637, 0.04754956811666...
for scripting, such as [IronRuby](https://en.wikipedia.org/wiki/IronRuby), [IronPython](https://en.wikipedia.org/wiki/IronPython), or [Lua](https://en.wikipedia.org/wiki/Lua_%28programming_language%29). IronPython and IronRuby are both available today. For a guide to embedding IronPython read [How to embed IronPython script support in your existing app in 10 easy steps](https://blogs.msdn.microsoft.com/jmstall/2005/09/01/how-to-embed-ironpython-script-support-in-your-existing-app-in-10-easy-steps/). Lua is a scripting language commonly used in games. There is a Lua compiler for .NET, available from CodePlex -- <http://www.codeplex.com/Nua> That codebase is a great read if you want to learn about building a compiler in .NET. A different angle altogether is to try [PowerShell](https://en.wikipedia.org/wiki/PowerShell). There are numerous examples of embedding PowerShell into an application -- here's a thorough project on the topic: [Powershell Tunnel](http://code.msdn.microsoft.com/PowerShellTunnel/Wiki/View.aspx?title=PowerShellTunnel%20Reference "PowerShell Tunnel")
[ 0.06356718391180038, 0.2169915735721588, 0.12070569396018982, -0.04159945249557495, 0.072174571454525, 0.25472140312194824, 0.22037777304649353, -0.16409452259540558, -0.20761403441429138, -0.6873155236244202, -0.245703786611557, 0.3827753961086273, -0.2981489598751068, -0.2273095101118087...
I often have to sort a dictionary (consisting of keys & values) by value. For example, I have a hash of words and respective frequencies that I want to order by frequency. There is a `SortedList` which is good for a single value (say frequency), that I want to map back to the word. [SortedDictionary](http://msdn.microsoft.com/en-us/library/f7fta44c.aspx) orders by key, not value. Some resort to a [custom class](http://www.codeproject.com/KB/recipes/lookupcollection.aspx), but is there a cleaner way? Use: ``` using System.Linq.Enumerable; ... List<KeyValuePair<string, string>> myList = aDictionary.ToList(); myList.Sort( delegate(KeyValuePair<string, string> pair1, KeyValuePair<string, string> pair2) { return pair1.Value.CompareTo(pair2.Value);
[ -0.003946809098124504, 0.09239714592695236, 0.3790617883205414, -0.10281109064817429, 0.11739430576562881, 0.09341292083263397, 0.2873866856098175, -0.41345033049583435, -0.007849257439374924, -0.7230545878410339, -0.41143491864204407, 0.355297714471817, -0.2008722871541977, 0.177503585815...
} ); ``` Since you're targeting .NET 2.0 or above, you can simplify this into lambda syntax -- it's equivalent, but shorter. If you're targeting .NET 2.0 you can only use this syntax if you're using the compiler from Visual Studio 2008 (or above). ``` var myList = aDictionary.ToList(); myList.Sort((pair1,pair2) => pair1.Value.CompareTo(pair2.Value)); ```
[ 0.2758241891860962, -0.043128471821546555, 0.4683094918727875, -0.5024014115333557, -0.17758455872535706, 0.1874658316373825, 0.17786318063735962, -0.29298755526542664, 0.060049157589673996, -0.7564420700073242, -0.11654595285654068, 0.7372617721557617, -0.7401696443557739, -0.408340960741...
When is it appropriate to use an unsigned variable over a signed one? What about in a `for` loop? I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus. ``` for (unsigned int i = 0; i < someThing.length(); i++) { SomeThing var = someThing.at(i); // You get the idea. } ``` I know Java doesn't have unsigned values, and that must have been a concious decision on [Sun Microsystems](https://en.wikipedia.org/wiki/Sun_Microsystems)' part. I was glad to find [a good conversation](https://web.archive.org/web/20170323034837/http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-02/1382.html) on this subject, as I
[ 0.3691323697566986, -0.0055847130715847015, -0.15741804242134094, -0.30866774916648865, -0.10168980062007904, -0.3239680230617523, 0.2878040671348572, -0.282443106174469, -0.39198818802833557, -0.48857972025871277, -0.013877451419830322, 0.35293450951576233, -0.1831618845462799, 0.02525807...
hadn't really given it much thought before. In summary, signed is a good general choice - even when you're dead sure all the numbers are positive - if you're going to do arithmetic on the variable (like in a typical for loop case). unsigned starts to make more sense when: * You're going to do **bitwise things** like masks, or * You're **desperate** to to take advantage of the sign bit **for that extra positive range** . Personally, I like signed because I don't trust myself to stay consistent and avoid mixing the two types (like the article warns against).
[ 0.595941960811615, -0.08781109005212784, 0.05730557441711426, 0.06374514102935791, -0.2077506184577942, -0.22127921879291534, 0.4430799186229706, -0.010635980404913425, -0.4228188097476959, -0.5134925842285156, 0.13524676859378815, 0.4631331264972687, -0.04582174867391586, -0.1477516442537...
I am about to build a piece of a project that will need to construct and post an XML document to a web service and I'd like to do it in Python, as a means to expand my skills in it. Unfortunately, whilst I know the XML model fairly well in .NET, I'm uncertain what the pros and cons are of the XML models in Python. Anyone have experience doing XML processing in Python? Where would you suggest I start? The XML files I'll be building will be fairly simple. Personally, I've played with several of the built-in options on an
[ 0.6846240758895874, 0.11768028140068054, -0.086746945977211, 0.09974072873592377, 0.1645241677761078, -0.15187856554985046, -0.09230206906795502, 0.3208775818347931, -0.22653397917747498, -0.642114520072937, 0.17388202250003815, 0.516829252243042, 0.08100719004869461, 0.013709175400435925,...
XML-heavy project and have settled on [pulldom](http://docs.python.org/lib/module-xml.dom.pulldom.html) as the best choice for less complex documents. Especially for small simple stuff, I like the event-driven theory of parsing rather than setting up a whole slew of callbacks for a relatively simple structure. [Here is a good quick discussion of how to use the API](http://www.prescod.net/python/pulldom.html). What I like: you can handle the parsing in a `for` loop rather than using callbacks. You also delay full parsing (the "pull" part) and only get additional detail when you call `expandNode()`. This satisfies my general requirement for "responsible" efficiency without sacrificing ease of use and simplicity.
[ 0.1581829935312271, -0.17819562554359436, 0.5070423483848572, -0.033759575337171555, -0.2039262056350708, -0.4772859513759613, -0.12467370927333832, -0.307794451713562, -0.20264723896980286, -0.44776293635368347, -0.34215712547302246, 0.6616685390472412, -0.15812264382839203, -0.2355232238...
How would I go about generating a list of all possible permutations of a string between x and y characters in length, containing a variable list of characters. Any language would work, but it should be portable. There are several ways to do this. Common methods use recursion, memoization, or dynamic programming. The basic idea is that you produce a list of all strings of length 1, then in each iteration, for all strings produced in the last iteration, add that string concatenated with each character in the string individually. (the variable index in the code below keeps track of the start
[ 0.11697577685117722, 0.0011925061699002981, -0.11350996047258377, 0.06788124144077301, -0.0641728863120079, 0.3503550887107849, 0.008177319541573524, -0.3100689649581909, 0.008340086787939072, -0.48338767886161804, 0.08779186755418777, 0.3137931525707245, -0.10855070501565933, -0.032195080...
of the last and the next iteration) Some pseudocode: ``` list = originalString.split('') index = (0,0) list = [""] for iteration n in 1 to y: index = (index[1], len(list)) for string s in list.subset(index[0] to end): for character c in originalString: list.add(s + c) ``` you'd then need to remove all strings less than x in length, they'll be the first (x-1) \* len(originalString) entries in the list.
[ -0.060662925243377686, -0.10612655431032181, 0.627216637134552, -0.2371629774570465, 0.17609380185604095, 0.029154840856790543, 0.15463753044605255, -0.3427885174751282, -0.3673235774040222, -0.44318312406539917, -0.37216290831565857, 0.332490473985672, -0.24467812478542328, 0.175882577896...
Please note that this question is from 2008 and now is of only historic interest. --- What's the best way to create an iPhone application that runs in landscape mode from the start, regardless of the position of the device? Both programmatically and using the Interface Builder. Historic answer only. Spectacularly out of date. ================================================ Please note that this answer is now hugely out of date/ This answer is **only a historical curiosity**. --- Exciting news! As discovered by Andrew below, this problem has been fixed by Apple in 4.0+. It would appear it is NO longer necessary to force the size of the view on every view, and the
[ -0.04973069950938225, 0.17992913722991943, 0.6171727180480957, -0.15041004121303558, 0.49849653244018555, -0.22180113196372986, 0.370156854391098, 0.23354017734527588, -0.2367316633462906, -0.19445374608039856, -0.08023980259895325, 0.39567750692367554, 0.044036731123924255, 0.110030114650...
specific serious problem of landscape "only working the first time" has been resolved. As of April 2011, it is not possible to test or even build anything below 4.0, so the question is purely a historic curiosity. It's incredible how much trouble it caused developers for so long! --- Here is the original discussion and solution. This is utterly irrelevant now, as these systems are not even operable. --- It is EXTREMELY DIFFICULT to make this work fully -- there are at least three problems/bugs at play. try this .. [interface builder landscape design](http://www.iphonedevsdk.com/forum/iphone-sdk-development/7366-interface-builder-landscape-design.html#post186977) Note in particular that where it says *"and you need to use shouldAutorotateToInterfaceOrientation
[ -0.133313849568367, 0.14461544156074524, 0.42374083399772644, -0.38056185841560364, 0.1840820610523224, -0.07044541835784912, 0.3705439865589142, -0.23509034514427185, -0.2048121690750122, -0.45457762479782104, -0.03229561448097229, 0.6708493232727051, -0.3510569930076599, -0.0782034918665...
properly everywhere"* it means everywhere, all your fullscreen views. Hope it helps in this nightmare! An important reminder of the ADDITIONAL well-known problem at hand here: if you are trying to swap between ***MORE THAN ONE*** view (all landscape), ***IT SIMPLY DOES NOT WORK***. It is essential to remember this or you will waste days on the problem. It is literally NOT POSSIBLE. It is the biggest open, known, bug on the iOS platform. There is literally no way to make the hardware make the second view you load, be landscape. The annoying but simple workaround, and what you must do, is
[ 0.7506231665611267, -0.18814224004745483, 0.5110433101654053, 0.21256954967975616, 0.22858548164367676, -0.1749671995639801, 0.4819462299346924, 0.2427414208650589, -0.4987559914588928, -0.6151233911514282, -0.14066073298454285, 0.7976043224334717, -0.5780196189880371, -0.21827884018421173...
have a trivial master UIViewController that does nothing but sit there and let you swap between your views. In other words, in iOS because of a major know bug: ``` [window addSubview:happyThing.view]; [window makeKeyAndVisible]; ``` ***You can do that only once***. Later, if you try to remove happyThing.view, and instead put in there newThing.view, IT DOES NOT WORK - AND THAT'S THAT. The machine will never rotate the view to landscape. There is no trick fix, even Apple cannot make it work. The workaround you must adopt is having an overall UIViewController that simply sits there and just holds your various views (happyThing, newThing, etc). Hope
[ 0.06516248732805252, -0.19244761765003204, 0.6117445826530457, 0.15925465524196625, -0.005877574905753136, 0.009128079749643803, 0.4468650221824646, 0.03109302930533886, -0.21011897921562195, -0.9164502620697021, -0.19755248725414276, 0.5488723516464233, -0.47687655687332153, 0.04717582836...
it helps!
[ 0.13970184326171875, 0.318431556224823, 0.11038588732481003, 0.054232385009527206, 0.11053875833749771, -0.09183011204004288, 0.3095228970050812, 0.22899043560028076, -0.08420000970363617, -0.3054017126560211, 0.16388341784477234, 0.24865098297595978, 0.3417918086051941, 0.0014685764908790...
I have a cross-platform (Python) application which needs to generate a JPEG preview of the first page of a PDF. On the Mac I am spawning [sips](http://web.archive.org/web/20090309234215/http://developer.apple.com:80/documentation/Darwin/Reference/ManPages/man1/sips.1.html). Is there something similarly simple I can do on Windows? ImageMagick delegates the PDF->bitmap conversion to GhostScript anyway, so here's a command you can use (it's based on the actual command listed by the `ps:alpha` delegate in ImageMagick, just adjusted to use JPEG as output): ``` gs -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT \ -dMaxBitmap=500000000 -dLastPage=1 -dAlignToPixels=0 -dGridFitTT=0 \ -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r72x72 \ -sOutputFile=$OUTPUT -f$INPUT ``` where `$OUTPUT` and `$INPUT` are the output and input filenames. Adjust the `72x72` to whatever
[ 0.07582158595323563, -0.09093516319990158, 0.5218530893325806, 0.04107962176203728, -0.39708632230758667, -0.01908615045249462, 0.4977585971355438, -0.2298607975244522, -0.19221679866313934, -0.6739040017127991, 0.061241038143634796, 0.33824676275253296, -0.26177215576171875, 0.19790013134...
resolution you need. (Obviously, strip out the backslashes if you're writing out the whole command as one line.) This is good for two reasons: 1. You don't need to have ImageMagick installed anymore. Not that I have anything against ImageMagick (I love it to bits), but I believe in simple solutions. 2. ImageMagick does a two-step conversion. First PDF->PPM, then PPM->JPEG. This way, the conversion is one-step. Other things to consider: with the files I've tested, PNG compresses better than JPEG. If you want to use PNG, change the `-sDEVICE=jpeg` to `-sDEVICE=png16m`.
[ -0.36048001050949097, -0.4146837592124939, 0.8458788394927979, 0.15590344369411469, -0.3622385263442993, -0.03160135820508003, 0.020007360726594925, -0.29566073417663574, -0.48581570386886597, -0.9996569156646729, -0.02836833894252777, 0.895606279373169, 0.05102882906794548, -0.04616586863...
> #### Moderator note: > > > This question is not a good fit for our question and answer format with the [topicality rules](/help/on-topic) which currently apply for Stack Overflow. We normally use a "historical lock" for such questions where the content still has value. However, the answers on this question are actively maintained and a historical lock doesn't permit editing of the answers. As such, a "wiki answer" lock has been applied to allow the answers to be edited. You should assume the topicality issues which are normally handled by a historical lock are present (i.e. this question not a
[ 0.07966691255569458, 0.15525291860103607, 0.44983088970184326, 0.2561293840408325, -0.23411990702152252, -0.49853184819221497, 0.22523850202560425, -0.10259933024644852, -0.22429516911506653, -0.3592158257961273, -0.21331602334976196, 0.4611688256263733, -0.045858222991228104, 0.2043298929...
good example of an on-topic question for Stack Overflow). Form-based authentication for websites -------------------------------------- We believe that Stack Overflow should not just be a resource for very specific technical questions, but also for general guidelines on how to solve variations on common problems. "Form based authentication for websites" should be a fine topic for such an experiment. ### It should include topics such as: * How to log in * How to log out * How to remain logged in * Managing cookies (including recommended settings) * SSL/HTTPS encryption * How to store passwords * Using secret questions * Forgotten username/password functionality * Use of [nonces](https://en.wikipedia.org/wiki/Cryptographic_nonce) to prevent [cross-site request forgeries (CSRF)](https://en.wikipedia.org/wiki/Cross-site_request_forgery) * [OpenID](http://openid.net/) * "Remember
[ -0.0895659551024437, 0.13712942600250244, 0.2559617757797241, 0.2734670639038086, 0.13677257299423218, -0.5666630268096924, 0.33419299125671387, -0.2783257067203522, -0.383955717086792, -0.5138978958129883, -0.38583824038505554, 0.5481789708137512, 0.0704377219080925, -0.18033301830291748,...
me" checkbox * Browser autocompletion of usernames and passwords * Secret URLs (public [URL](https://en.wikipedia.org/wiki/Uniform_Resource_Locator) protected by digest) * Checking password strength * E-mail validation * *and much more about* [form based authentication](http://en.wikipedia.org/wiki/Form-based_authentication)... ### It should not include things like: * Roles and authorization * HTTP basic authentication ### Please help us by: 1. Suggesting subtopics 2. Submitting good articles about this subject 3. Editing the official answer PART I: How To Log In --------------------- We'll assume you already know how to build a login+password HTML form which POSTs the values to a script on the server side for authentication. The sections below will deal with patterns for sound practical auth, and how to avoid the
[ 0.49692994356155396, 0.3356494903564453, 0.2610229551792145, 0.18931804597377777, -0.17203879356384277, -0.3013196289539337, 0.37877073884010315, -0.18109534680843353, 0.19967851042747498, -0.7110591530799866, -0.10029840469360352, 0.48966094851493835, -0.07891063392162323, -0.150583609938...
most common security pitfalls. **To HTTPS or not to HTTPS?** Unless the connection is already secure (that is, tunneled through HTTPS using SSL/TLS), your login form values will be sent in cleartext, which allows anyone eavesdropping on the line between browser and web server will be able to read logins as they pass through. This type of wiretapping is done routinely by governments, but in general, we won't address 'owned' wires other than to say this: Just use HTTPS. In essence, the only **practical** way to protect against wiretapping/packet sniffing during login is by using HTTPS or another certificate-based encryption scheme (for example,
[ 0.8677945733070374, -0.19773654639720917, 0.36296701431274414, 0.2552074193954468, 0.258044958114624, -0.6660443544387817, 0.3797481954097748, -0.12879931926727295, -0.43396231532096863, -0.42004653811454773, -0.36532166600227356, 0.44594237208366394, -0.28311118483543396, 0.02376027777791...
[TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security)) or a proven & tested challenge-response scheme (for example, the [Diffie-Hellman](https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange)-based SRP). *Any other method can be easily circumvented* by an eavesdropping attacker. Of course, if you are willing to get a little bit impractical, you could also employ some form of two-factor authentication scheme (e.g. the Google Authenticator app, a physical 'cold war style' codebook, or an RSA key generator dongle). If applied correctly, this could work even with an unsecured connection, but it's hard to imagine that a dev would be willing to implement two-factor auth but not SSL. **(Do not) Roll-your-own JavaScript encryption/hashing** Given the perceived (though now [avoidable](https://letsencrypt.org/))
[ 0.4126549959182739, -0.35779449343681335, 0.2129797637462616, 0.2921864688396454, -0.11971575021743774, -0.4651317000389099, 0.5733652114868164, -0.1071239709854126, -0.31743642687797546, -0.5704998970031738, -0.5823391675949097, 0.4533231854438782, -0.38576561212539673, -0.001385667826980...
cost and technical difficulty of setting up an SSL certificate on your website, some developers are tempted to roll their own in-browser hashing or encryption schemes in order to avoid passing cleartext logins over an unsecured wire. While this is a noble thought, it is essentially useless (and can be a [security flaw](https://stackoverflow.com/questions/1380168/does-it-make-security-sense-to-hash-password-on-client-end)) unless it is combined with one of the above - that is, either securing the line with strong encryption or using a tried-and-tested challenge-response mechanism (if you don't know what that is, just know that it is one of the most difficult to prove, most difficult to design,
[ 0.3658970296382904, 0.17728807032108307, 0.25594377517700195, 0.22208045423030853, 0.0049082618206739426, -0.6592990756034851, 0.5260458588600159, 0.07582507282495499, -0.2485767900943756, -0.4733107089996338, -0.2620237469673157, 0.02031552977859974, -0.0892016589641571, 0.042649429291486...
and most difficult to implement concepts in digital security). While it is true that hashing the password *can be* effective against **password disclosure**, it is vulnerable to replay attacks, Man-In-The-Middle attacks / hijackings (if an attacker can inject a few bytes into your unsecured HTML page before it reaches your browser, they can simply comment out the hashing in the JavaScript), or brute-force attacks (since you are handing the attacker both username, salt and hashed password). **CAPTCHAS against humanity** [CAPTCHA](https://en.wikipedia.org/wiki/CAPTCHA) is meant to thwart one specific category of attack: automated dictionary/brute force trial-and-error with no human operator. There is no doubt that this
[ -0.14392082393169403, 0.02532622218132019, 0.015984874218702316, 0.23535311222076416, -0.15822428464889526, -0.288822740316391, 0.3136886954307556, -0.015527425333857536, -0.19032567739486694, -0.7735961675643921, -0.3559562861919403, 0.31220027804374695, -0.13823826611042023, 0.2593834996...
is a real threat, however, there are ways of dealing with it seamlessly that don't require a CAPTCHA, specifically properly designed server-side login throttling schemes - we'll discuss those later. Know that CAPTCHA implementations are not created alike; they often aren't human-solvable, most of them are actually ineffective against bots, all of them are ineffective against cheap third-world labor (according to [OWASP](https://en.wikipedia.org/wiki/OWASP), the current sweatshop rate is $12 per 500 tests), and some implementations may be technically illegal in some countries (see [OWASP Authentication Cheat Sheet](https://www.owasp.org/index.php/Authentication_Cheat_Sheet)). If you must use a CAPTCHA, use Google's [reCAPTCHA](https://en.wikipedia.org/wiki/ReCAPTCHA), since it is OCR-hard by definition
[ 0.5729320645332336, 0.10574066638946533, 0.432923287153244, 0.1308511197566986, 0.21833640336990356, -0.35081297159194946, 0.6080067157745361, 0.15410025417804718, -0.4103837013244629, -0.49972206354141235, -0.062066733837127686, 0.34521549940109253, -0.41216838359832764, -0.24493137001991...
(since it uses already OCR-misclassified book scans) and tries very hard to be user-friendly. Personally, I tend to find CAPTCHAS annoying, and use them only as a last resort when a user has failed to log in a number of times and throttling delays are maxed out. This will happen rarely enough to be acceptable, and it strengthens the system as a whole. **Storing Passwords / Verifying logins** This may finally be common knowledge after all the highly-publicized hacks and user data leaks we've seen in recent years, but it has to be said: Do not store passwords in cleartext in your database.
[ 0.2773246169090271, 0.17587566375732422, 0.15256282687187195, 0.12738268077373505, 0.2649443447589874, -0.7044089436531067, 0.9100233316421509, 0.4081646502017975, -0.22179964184761047, -0.6438577771186829, -0.26629844307899475, 0.4927423298358917, 0.0028146563563495874, 0.0557560808956623...
User databases are routinely hacked, leaked or gleaned through SQL injection, and if you are storing raw, plaintext passwords, that is instant game over for your login security. So if you can't store the password, how do you check that the login+password combination POSTed from the login form is correct? The answer is hashing using a [key derivation function](https://en.wikipedia.org/wiki/Key_derivation_function). Whenever a new user is created or a password is changed, you take the password and run it through a KDF, such as Argon2, bcrypt, scrypt or PBKDF2, turning the cleartext password ("correcthorsebatterystaple") into a long, random-looking string, which is a lot
[ -0.02505265735089779, 0.03713662549853325, -0.027498705312609673, 0.36796990036964417, 0.02988729067146778, -0.30367469787597656, 0.24209603667259216, 0.16141760349273682, -0.27441948652267456, -0.6600226759910583, -0.19959400594234467, 0.36239489912986755, -0.29616889357566833, 0.33829194...
safer to store in your database. To verify a login, you run the same hash function on the entered password, this time passing in the salt and compare the resulting hash string to the value stored in your database. Argon2, bcrypt and scrypt store the salt with the hash already. Check out this [article](https://security.stackexchange.com/a/31846/8340) on sec.stackexchange for more detailed information. The reason a salt is used is that hashing in itself is not sufficient -- you'll want to add a so-called 'salt' to protect the hash against [rainbow tables](https://en.wikipedia.org/wiki/Rainbow_table). A salt effectively prevents two passwords that exactly match from being stored
[ 0.1410219520330429, 0.04705348238348961, 0.0010325413895770907, 0.1819935441017151, 0.12347149103879929, -0.4480457603931427, 0.3664543330669403, -0.3963938355445862, 0.017959102988243103, -0.7847141027450562, 0.06480883806943893, 0.429443895816803, -0.16983886063098907, -0.053714696317911...
as the same hash value, preventing the whole database being scanned in one run if an attacker is executing a password guessing attack. A cryptographic hash should not be used for password storage because user-selected passwords are not strong enough (i.e. do not usually contain enough entropy) and a password guessing attack could be completed in a relatively short time by an attacker with access to the hashes. This is why KDFs are used - these effectively ["stretch the key"](https://en.wikipedia.org/wiki/Key_stretching), which means that every password guess an attacker makes causes multiple repetitions of the hash algorithm, for example 10,000 times, which
[ 0.31954389810562134, -0.2907404601573944, 0.21036700904369354, -0.016327308490872383, -0.0029092675540596247, -0.3990248441696167, 0.34798184037208557, -0.38986316323280334, -0.45144590735435486, -0.5040165781974792, -0.27432680130004883, 0.3216399848461151, -0.1513478010892868, 0.13552683...
causes the attacker to guess the password 10,000 times slower. **Session data - "You are logged in as Spiderman69"** Once the server has verified the login and password against your user database and found a match, the system needs a way to remember that the browser has been authenticated. This fact should only ever be stored server side in the session data. > If you are unfamiliar with session data, here's how it works: A single randomly-generated string is stored in an expiring cookie and used to reference a collection of data - the session data - which is stored on the server.
[ 0.35861292481422424, -0.22095036506652832, 0.37160035967826843, 0.08743652701377869, -0.03405648097395897, -0.2124893069267273, 0.4768889248371124, 0.27494120597839355, -0.371503621339798, -0.7891873121261597, 0.16208449006080627, 0.13120800256729126, -0.21529322862625122, 0.12193848192691...
If you are using an MVC framework, this is undoubtedly handled already. If at all possible, make sure the session cookie has the secure and HTTP Only flags set when sent to the browser. The HttpOnly flag provides some protection against the cookie being read through XSS attack. The secure flag ensures that the cookie is only sent back via HTTPS, and therefore protects against network sniffing attacks. The value of the cookie should not be predictable. Where a cookie referencing a non-existent session is presented, its value should be replaced immediately to prevent [session fixation](https://owasp.org/www-community/attacks/Session_fixation). Session state can also be maintained
[ 0.15187513828277588, 0.0363033302128315, 0.4173707962036133, 0.10223358124494553, -0.10388214886188507, -0.3856567442417145, 0.7412837743759155, 0.07753101736307144, -0.3921130895614624, -0.5961609482765198, -0.41120508313179016, 0.49809181690216064, -0.4371883273124695, 0.0565884411334991...
on the client side. This is achieved by using techniques like JWT (JSON Web Token). PART II: How To Remain Logged In - The Infamous "Remember Me" Checkbox ---------------------------------------------------------------------- Persistent Login Cookies ("remember me" functionality) are a danger zone; on the one hand, they are entirely as safe as conventional logins when users understand how to handle them; and on the other hand, they are an enormous security risk in the hands of careless users, who may use them on public computers and forget to log out, and who may not know what browser cookies are or how to delete them. Personally, I like
[ 0.11777141690254211, 0.10314314812421799, 0.5969565510749817, 0.17820177972316742, 0.15586784482002258, -0.49258023500442505, 0.4209999144077301, 0.07828778028488159, -0.3587895929813385, -0.4628031849861145, -0.30597513914108276, 0.5514276027679443, 0.3108619153499603, 0.06905423849821091...
persistent logins for the websites I visit on a regular basis, but I know how to handle them safely. If you are positive that your users know the same, you can use persistent logins with a clean conscience. If not - well, then you may subscribe to the philosophy that users who are careless with their login credentials brought it upon themselves if they get hacked. It's not like we go to our user's houses and tear off all those facepalm-inducing Post-It notes with passwords they have lined up on the edge of their monitors, either. Of course, some systems can't
[ 0.3832157552242279, 0.3113613724708557, 0.4953712224960327, 0.1454460769891739, -0.072141133248806, -0.22765663266181946, 0.48681262135505676, 0.5349184274673462, -0.5803166627883911, -0.3667389154434204, 0.15695872902870178, 0.46144357323646545, -0.1771395057439804, 0.2738408148288727, ...
afford to have *any* accounts hacked; for such systems, there is no way you can justify having persistent logins. **If you DO decide to implement persistent login cookies, this is how you do it:** 1. First, take some time to read [Paragon Initiative's article](https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence) on the subject. You'll need to get a bunch of elements right, and the article does a great job of explaining each. 2. And just to reiterate one of the most common pitfalls, **DO NOT STORE THE PERSISTENT LOGIN COOKIE (TOKEN) IN YOUR DATABASE, ONLY A HASH OF IT!** The login token is Password Equivalent, so if an attacker
[ 0.20469479262828827, 0.153934508562088, 0.061817992478609085, 0.1603022813796997, 0.3128328025341034, -0.13379086554050446, 0.2606913447380066, -0.05545835196971893, -0.15625151991844177, -0.886481523513794, 0.385600745677948, 0.9097573161125183, -0.0799732506275177, -0.09206723421812057, ...
got their hands on your database, they could use the tokens to log in to any account, just as if they were cleartext login-password combinations. Therefore, use hashing (according to <https://security.stackexchange.com/a/63438/5002> a weak hash will do just fine for this purpose) when storing persistent login tokens. PART III: Using Secret Questions -------------------------------- **Don't implement 'secret questions'**. The 'secret questions' feature is a security anti-pattern. Read the paper from link number 4 from the MUST-READ list. You can ask Sarah Palin about that one, after her Yahoo! email account got hacked during a previous presidential campaign because the answer to her security question was...
[ 0.5353406071662903, -0.10739604383707047, 0.07202023267745972, 0.34225380420684814, 0.24190649390220642, -0.25971052050590515, 0.2823202311992645, 0.021474819630384445, -0.5197387337684631, -0.26918312907218933, 0.21096017956733704, 0.4134982228279114, -0.06168166548013687, -0.111859083175...
"Wasilla High School"! Even with user-specified questions, it is highly likely that most users will choose either: * A 'standard' secret question like mother's maiden name or favorite pet * A simple piece of trivia that anyone could lift from their blog, LinkedIn profile, or similar * Any question that is easier to answer than guessing their password. Which, for any decent password, is every question you can imagine **In conclusion, security questions are inherently insecure in virtually all their forms and variations, and should not be employed in an authentication scheme for any reason.** The true reason why security questions even exist in the wild
[ 0.29948678612709045, -0.17163927853107452, 0.21782830357551575, 0.26454269886016846, 0.03141559660434723, -0.48250892758369446, 0.32121458649635315, 0.3116028308868408, -0.17905472218990326, 0.0507374070584774, -0.0901956707239151, -0.09337826818227768, 0.10481160134077072, 0.1519498676061...
is that they conveniently save the cost of a few support calls from users who can't access their email to get to a reactivation code. This at the expense of security and Sarah Palin's reputation. Worth it? Probably not. PART IV: Forgotten Password Functionality ----------------------------------------- I already mentioned why you should **never use security questions** for handling forgotten/lost user passwords; it also goes without saying that you should never e-mail users their actual passwords. There are at least two more all-too-common pitfalls to avoid in this field: 1. Don't *reset* a forgotten password to an autogenerated strong password - such passwords are notoriously hard
[ 0.18082734942436218, 0.05069168657064438, 0.15703491866588593, 0.2767123281955719, 0.24250565469264984, 0.09209460765123367, 0.5763548016548157, -0.04960213974118233, -0.36218640208244324, -0.09297844767570496, 0.0315001979470253, 0.856705367565155, 0.19990351796150208, 0.01139040105044841...
to remember, which means the user must either change it or write it down - say, on a bright yellow Post-It on the edge of their monitor. Instead of setting a new password, just let users pick a new one right away - which is what they want to do anyway. (An exception to this might be if the users are universally using a password manager to store/manage passwords that would normally be impossible to remember without writing it down). 2. Always hash the lost password code/token in the database. ***AGAIN***, this code is another example of a Password Equivalent, so
[ 0.3460043966770172, -0.015400408767163754, 0.341427206993103, 0.09779924154281616, 0.27358588576316833, -0.20658905804157257, 0.45649221539497375, 0.2079637050628662, -0.322510302066803, -0.7435687184333801, -0.027230937033891678, 0.658446192741394, 0.07874175906181335, -0.0829090401530265...
it MUST be hashed in case an attacker got their hands on your database. When a lost password code is requested, send the plaintext code to the user's email address, then hash it, save the hash in your database -- and *throw away the original*. Just like a password or a persistent login token. A final note: always make sure your interface for entering the 'lost password code' is at least as secure as your login form itself, or an attacker will simply use this to gain access instead. Making sure you generate very long 'lost password codes' (for example, 16
[ 0.10607126355171204, 0.1478053480386734, 0.266940712928772, 0.11269228905439377, 0.1188490092754364, -0.11460539698600769, 0.46178701519966125, 0.011006202548742294, -0.31964433193206787, -0.4887333810329437, -0.12051611393690109, 0.4546246826648712, -0.04457622393965721, 0.116149365901947...
case-sensitive alphanumeric characters) is a good start, but consider adding the same throttling scheme that you do for the login form itself. PART V: Checking Password Strength ---------------------------------- First, you'll want to read this small article for a reality check: [The 500 most common passwords](http://www.whatsmypass.com/?p=415) Okay, so maybe the list isn't the *canonical* list of most common passwords on *any* system *anywhere ever*, but it's a good indication of how poorly people will choose their passwords when there is no enforced policy in place. Plus, the list looks frighteningly close to home when you compare it to publicly available analyses of recently stolen passwords. So:
[ -0.11852725595235825, -0.02045506425201893, 0.5427528619766235, 0.3969467878341675, 0.20919635891914368, -0.22019332647323608, 0.19626973569393158, -0.03502345457673073, -0.20788055658340454, -0.43481507897377014, -0.19162581861019135, 0.8223466873168945, 0.028592580929398537, 0.1465478390...
With no minimum password strength requirements, 2% of users use one of the top 20 most common passwords. Meaning: if an attacker gets just 20 attempts, 1 in 50 accounts on your website will be crackable. Thwarting this requires calculating the entropy of a password and then applying a threshold. The National Institute of Standards and Technology (NIST) [Special Publication 800-63](https://en.wikipedia.org/wiki/Password_strength#NIST_Special_Publication_800-63) has a set of very good suggestions. That, when combined with a dictionary and keyboard layout analysis (for example, 'qwertyuiop' is a bad password), can [reject 99% of all poorly selected passwords](https://cubicspot.blogspot.com/2012/01/how-to-calculate-password-strength-part.html) at a level of 18 bits of entropy.
[ -0.21267203986644745, 0.09685107320547104, 0.09323965013027191, 0.10618294030427933, -0.08082837611436844, -0.0007160318200476468, 0.5402998328208923, -0.18269866704940796, -0.09378274530172348, -0.661452054977417, -0.2062499225139618, 0.5200908184051514, 0.11960896849632263, 0.06920076161...
Simply calculating password strength and [showing a visual strength meter](https://blogs.dropbox.com/tech/2012/04/zxcvbn-realistic-password-strength-estimation/) to a user is good, but insufficient. Unless it is enforced, a lot of users will most likely ignore it. And for a refreshing take on user-friendliness of high-entropy passwords, Randall Munroe's [Password Strength xkcd](https://xkcd.com/936/) is highly recommended. Utilize Troy Hunt's [Have I Been Pwned API](https://haveibeenpwned.com/API/) to check users passwords against passwords compromised in public data breaches. PART VI: Much More - Or: Preventing Rapid-Fire Login Attempts ------------------------------------------------------------- First, have a look at the numbers: [Password Recovery Speeds - How long will your password stand up](https://www.lockdown.co.uk/?pg=combi&s=articles) If you don't have the time to look through the
[ -0.02120819315314293, -0.20438960194587708, 0.216720312833786, 0.20392069220542908, -0.12673042714595795, -0.2440011203289032, 0.3281624913215637, -0.5056613683700562, -0.11119028180837631, -0.4502827525138855, -0.07764344662427902, 0.8110529780387878, 0.030205506831407547, -0.240145698189...
tables in that link, here's the list of them: 1. It takes *virtually no time* to crack a weak password, even if you're cracking it with an abacus 2. It takes *virtually no time* to crack an alphanumeric 9-character password if it is **case insensitive** 3. It takes *virtually no time* to crack an intricate, symbols-and-letters-and-numbers, upper-and-lowercase password if it is **less than 8 characters long** (a desktop PC can search the entire keyspace up to 7 characters in a matter of days or even hours) 4. **It would, however, take an inordinate amount of time to crack even a 6-character password, *if you
[ -0.42716625332832336, 0.20683550834655762, 0.10953456908464432, 0.08989793062210083, -0.12173443287611008, 0.18923978507518768, 0.49036741256713867, -0.08578729629516602, -0.46533486247062683, -0.7445547580718994, -0.321148157119751, 0.45977213978767395, 0.013722884468734264, -0.2566199898...
were limited to one attempt per second!*** So what can we learn from these numbers? Well, lots, but we can focus on the most important part: the fact that preventing large numbers of rapid-fire successive login attempts (ie. the *brute force* attack) really isn't that difficult. But preventing it *right* isn't as easy as it seems. Generally speaking, you have three choices that are all effective against brute-force attacks *(and dictionary attacks, but since you are already employing a strong passwords policy, they shouldn't be an issue)*: * Present a **CAPTCHA** after N failed attempts (annoying as hell and often ineffective -- but
[ 0.14304669201374054, 0.06608716398477554, 0.4344373345375061, 0.3114873468875885, -0.0866471454501152, -0.033347051590681076, 0.7954061031341553, -0.010756087489426136, -0.30425167083740234, -0.7143234014511108, -0.30499038100242615, 0.4573097229003906, -0.05214175954461098, -0.11549408733...
I'm repeating myself here) * **Locking accounts** and requiring email verification after N failed attempts (this is a [DoS](https://en.wikipedia.org/wiki/Denial-of-service_attack) attack waiting to happen) * And finally, **login throttling**: that is, setting a time delay between attempts after N failed attempts (yes, DoS attacks are still possible, but at least they are far less likely and a lot more complicated to pull off). **Best practice #1:** A short time delay that increases with the number of failed attempts, like: * 1 failed attempt = no delay * 2 failed attempts = 2 sec delay * 3 failed attempts = 4 sec delay * 4 failed attempts = 8
[ 0.24314028024673462, 0.08399955928325653, 0.4569253623485565, -0.146473690867424, 0.06415842473506927, -0.0580185241997242, 1.1844635009765625, -0.1745186299085617, -0.6153773665428162, -0.5822100639343262, -0.2207861691713333, 0.47921222448349, 0.002629714785143733, 0.14484526216983795, ...
sec delay * 5 failed attempts = 16 sec delay * etc. DoS attacking this scheme would be very impractical, since the resulting lockout time is slightly larger than the sum of the previous lockout times. > To clarify: The delay is *not* a delay before returning the response to the browser. It is more like a timeout or refractory period during which login attempts to a specific account or from a specific IP address will not be accepted or evaluated at all. That is, correct credentials will not return in a successful login, and incorrect credentials will not trigger a delay increase. **Best practice
[ -0.015172864310443401, -0.23515768349170685, 0.43844521045684814, -0.029075678437948227, 0.09392638504505157, -0.1659371554851532, 0.908240556716919, -0.3629872500896454, -0.3976159989833832, -0.4632507860660553, -0.3207376301288605, 0.4588833749294281, -0.15800659358501434, 0.139974117279...
#2:** A medium length time delay that goes into effect after N failed attempts, like: * 1-4 failed attempts = no delay * 5 failed attempts = 15-30 min delay DoS attacking this scheme would be quite impractical, but certainly doable. Also, it might be relevant to note that such a long delay can be very annoying for a legitimate user. Forgetful users will dislike you. **Best practice #3:** Combining the two approaches - either a fixed, short time delay that goes into effect after N failed attempts, like: * 1-4 failed attempts = no delay * 5+ failed attempts = 20 sec delay Or, an increasing
[ 0.09477401524782181, -0.1968659609556198, 0.4716191291809082, -0.1476992666721344, -0.07430966943502426, -0.22009490430355072, 0.7534114122390747, -0.4052373170852661, -0.2908158004283905, -0.38360095024108887, -0.2602291405200958, 0.9041966199874878, 0.0042427908629179, -0.189575210213661...
delay with a fixed upper bound, like: * 1 failed attempt = 5 sec delay * 2 failed attempts = 15 sec delay * 3+ failed attempts = 45 sec delay This final scheme was taken from the OWASP best-practices suggestions (link 1 from the MUST-READ list) and should be considered best practice, even if it is admittedly on the restrictive side. > *As a rule of thumb, however, I would say: the stronger your password policy is, the less you have to bug users with delays. If you require strong (case-sensitive alphanumerics + required numbers and symbols) 9+ character passwords, you could give the
[ 0.02907049097120762, -0.15877476334571838, 0.32532721757888794, 0.036060310900211334, 0.2735365033149719, -0.007620958145707846, 0.48136216402053833, -0.25946611166000366, -0.443037748336792, -0.4282294511795044, -0.2424641102552414, 0.41648587584495544, -0.11233717948198318, -0.1201897710...
users 2-4 non-delayed password attempts before activating the throttling.* DoS attacking this final login throttling scheme would be ***very*** impractical. And as a final touch, always allow persistent (cookie) logins (and/or a CAPTCHA-verified login form) to pass through, so legitimate users won't even be delayed *while the attack is in progress*. That way, the very impractical DoS attack becomes an *extremely* impractical attack. Additionally, it makes sense to do more aggressive throttling on admin accounts, since those are the most attractive entry points PART VII: Distributed Brute Force Attacks ----------------------------------------- Just as an aside, more advanced attackers will try to circumvent login throttling by 'spreading
[ -0.012842293828725815, 0.16088272631168365, 0.7574519515037537, 0.11806804686784744, 0.0010642349952831864, -0.18923167884349823, 0.4846857786178589, 0.07167412340641022, -0.24528083205223083, -0.6238380670547485, -0.36265331506729126, 0.6761906743049622, -0.20646421611309052, 0.2401179522...
their activities': * Distributing the attempts on a botnet to prevent IP address flagging * Rather than picking one user and trying the 50.000 most common passwords (which they can't, because of our throttling), they will pick THE most common password and try it against 50.000 users instead. That way, not only do they get around maximum-attempts measures like CAPTCHAs and login throttling, their chance of success increases as well, since the number 1 most common password is far more likely than number 49.995 * Spacing the login requests for each user account, say, 30 seconds apart, to sneak under the radar Here, the
[ 0.5532025694847107, -0.026791153475642204, 0.41127753257751465, -0.02165662869811058, 0.015376503579318523, -0.08463738858699799, 0.869541347026825, 0.049658384174108505, -0.5823779702186584, -0.5532810688018799, -0.19762642681598663, 0.37551507353782654, -0.09611841291189194, -0.179707303...
best practice would be **logging the number of failed logins, system-wide**, and using a running average of your site's bad-login frequency as the basis for an upper limit that you then impose on all users. Too abstract? Let me rephrase: Say your site has had an average of 120 bad logins per day over the past 3 months. Using that (running average), your system might set the global limit to 3 times that -- ie. 360 failed attempts over a 24 hour period. Then, if the total number of failed attempts across all accounts exceeds that number within one day (or even
[ 0.2775818407535553, 0.16400471329689026, 0.2623576521873474, 0.02185625024139881, 0.05572870373725891, -0.14024144411087036, 1.0419230461120605, 0.17655503749847412, -0.662906289100647, -0.6067965626716614, -0.14113618433475494, 0.43019336462020874, -0.3278115391731262, 0.08602536469697952...
better, monitor the rate of acceleration and trigger on a calculated threshold), it activates system-wide login throttling - meaning short delays for ALL users (still, with the exception of cookie logins and/or backup CAPTCHA logins). I also posted a question with [more details and a really good discussion of how to avoid tricky pitfals](https://stackoverflow.com/questions/479233/what-is-the-best-distributed-brute-force-countermeasure) in fending off distributed brute force attacks PART VIII: Two-Factor Authentication and Authentication Providers ----------------------------------------------------------------- Credentials can be compromised, whether by exploits, passwords being written down and lost, laptops with keys being stolen, or users entering logins into phishing sites. Logins can be further protected with two-factor authentication, which uses
[ -0.0034758325200527906, -0.0711851641535759, 0.2379545271396637, 0.22222165763378143, -0.06676912307739258, -0.1676284521818161, 0.3080863654613495, -0.3648296296596527, -0.20798052847385406, -0.573032021522522, -0.2770441472530365, 0.7711486220359802, -0.14737293124198914, -0.101501904428...
out-of-band factors such as single-use codes received from a phone call, SMS message, app, or dongle. Several providers offer two-factor authentication services. Authentication can be completely delegated to a single-sign-on service, where another provider handles collecting credentials. This pushes the problem to a trusted third party. Google and Twitter both provide standards-based SSO services, while Facebook provides a similar proprietary solution. MUST-READ LINKS About Web Authentication ---------------------------------------- 1. [OWASP Guide To Authentication](https://www.owasp.org/index.php/Authentication_Cheat_Sheet) / [OWASP Authentication Cheat Sheet](https://www.owasp.org/index.php/Authentication_Cheat_Sheet) 2. [Dos and Don’ts of Client Authentication on the Web (very readable MIT research paper)](https://pdos.csail.mit.edu/papers/webauth:sec10.pdf) 3. [Wikipedia: HTTP cookie](https://en.wikipedia.org/wiki/HTTP_cookie#Drawbacks_of_cookies) 4. [Personal knowledge questions for fallback authentication: Security questions in the
[ 0.0694560781121254, -0.0331108383834362, 0.5138183832168579, 0.07596862316131592, 0.14624923467636108, -0.428874671459198, 0.23841974139213562, -0.5725724101066589, -0.10640627145767212, -0.4476015269756317, -0.30056220293045044, 0.4441419839859009, -0.21459665894508362, -0.533177375793457...
era of Facebook (very readable Berkeley research paper)](https://cups.cs.cmu.edu/soups/2008/proceedings/p13Rabkin.pdf)
[ -0.26075080037117004, -0.2740252912044525, -0.0279899463057518, 0.027741655707359314, -0.17707166075706482, -0.16844291985034943, 0.1468452662229538, 0.19811564683914185, -0.8765004277229309, -0.5172766447067261, -0.15876953303813934, -0.08667632192373276, -0.13480208814144135, -0.22133757...
I would like to test a function with a tuple from a set of fringe cases and normal values. For example, while testing a function which returns `true` whenever given three lengths that form a valid triangle, I would have specific cases, negative / small / large numbers, values close-to being overflowed, etc.; what is more, main aim is to generate combinations of these values, *with* or *without* repetition, in order to get a set of test data. ``` (inf,0,-1), (5,10,1000), (10,5,5), (0,-1,5), (1000,inf,inf), ... ``` > *As a note: I actually know the answer to this, but it might be helpful for others, and
[ 0.3709832429885864, 0.1377440243959427, -0.012933465652167797, 0.032432738691568375, -0.2481953650712967, 0.37501034140586853, 0.36476221680641174, -0.4704310894012451, -0.10588415712118149, -0.5057061314582825, -0.09082762151956558, 0.2231709510087967, -0.17408055067062378, 0.049194082617...
a challenge for people here! --will post my answer later on.* Absolutely, especially dealing with lots of these permutations/combinations I can definitely see that the first pass would be an issue. Interesting implementation in python, though I wrote a nice one in C and Ocaml based on "Algorithm 515" (see below). He wrote his in Fortran as it was common back then for all the "Algorithm XX" papers, well, that assembly or c. I had to re-write it and make some small improvements to work with arrays not ranges of numbers. This one does random access, I'm still working on getting some
[ -0.003284446196630597, 0.017260350286960602, 0.16235709190368652, 0.20630906522274017, -0.2214830219745636, -0.05035114660859108, 0.07775429636240005, -0.03072407841682434, -0.36146923899650574, -0.5775045156478882, 0.06712400913238525, 0.3856951594352722, -0.18785974383354187, -0.36667999...
nice implementations of the ones mentioned in Knuth 4th volume fascicle 2. I'll an explanation of how this works to the reader. Though if someone is curious, I wouldn't object to writing something up. ``` /** [combination c n p x] * get the [x]th lexicographically ordered set of [p] elements in [n] * output is in [c], and should be sizeof(int)*[p] */ void combination(int* c,int n,int p, int x){ int i,r,k = 0; for(i=0;i<p-1;i++){ c[i] = (i != 0) ? c[i-1] : 0;
[ -0.07917463779449463, -0.03602347895503044, 0.3652041554450989, -0.061928197741508484, -0.11876033246517181, 0.11252900213003159, 0.3053654730319977, -0.4352937340736389, -0.17980772256851196, -0.5691519975662231, -0.09645383059978485, 0.5290946364402771, -0.32358795404434204, -0.217169597...
do { c[i]++; r = choose(n-c[i],p-(i+1)); k = k + r; } while(k < x); k = k - r; } c[p-1] = c[p-2] + x - k; } ``` ~"Algorithm 515: Generation of a Vector from the Lexicographical Index"; Buckles, B. P., and Lybanon, M. ACM Transactions on
[ -0.4661000669002533, -0.08662482351064682, -0.07111882418394089, -0.01846289075911045, 0.08365461975336075, 0.5111071467399597, -0.06839189678430557, -0.5670270323753357, -0.04398774355649948, -0.3896195888519287, -0.3753832280635834, 0.45402634143829346, -0.46319255232810974, -0.162613660...
Mathematical Software, Vol. 3, No. 2, June 1977.
[ -0.7335292100906372, -0.061403919011354446, 0.1757843792438507, -0.11374242603778839, -0.040612366050481796, 0.11879425495862961, 0.08319538831710815, -0.2892390489578247, 0.010085704736411572, -0.0033438014797866344, -0.30681708455085754, 0.7403502464294434, 0.00890745222568512, -0.284633...
I want to print the first 10000 prime numbers. Can anyone give me the most efficient code for this? Clarifications: 1. It does not matter if your code is inefficient for n >10000. 2. The size of the code does not matter. 3. You cannot just hard code the values in any manner. [The Sieve of Atkin](http://en.wikipedia.org/wiki/Sieve_of_Atkin) is probably what you're looking for, its upper bound running time is O(N/log log N). If you only run the numbers 1 more and 1 less than the multiples of 6, it could be even faster, as all prime numbers above 3 are 1 away from some multiple of six.
[ 0.13942851126194, -0.004167196340858936, 0.20387248694896698, 0.053491752594709396, -0.32485586404800415, 0.5113338232040405, 0.3233569860458374, -0.32484349608421326, -0.14739473164081573, -0.5968269109725952, 0.12676139175891876, 0.5281039476394653, -0.26085785031318665, 0.12296049296855...
[Resource for my statement](http://primes.utm.edu/notes/faq/six.html)
[ 0.7138174772262573, 0.14910000562667847, 0.11058378964662552, -0.08562695980072021, 0.07547694444656372, 0.27733004093170166, 0.21611244976520538, -0.016024233773350716, -0.04766341298818588, -0.4431362450122833, 0.1335214525461197, 0.478677362203598, -0.23282629251480103, 0.40508615970611...
I would like the version property of my application to be incremented for each build but I'm not sure on how to enable this functionality in Visual Studio (2005/2008). I have tried to specify the AssemblyVersion as 1.0.\* but it doesn't get me exactly what I want. I'm also using a settings file and in earlier attempts when the assembly version changed my settings got reset to the default since the application looked for the settings file in another directory. I would like to be able to display a version number in the form of 1.1.38 so when a user
[ 0.28833118081092834, 0.21219098567962646, 0.46221330761909485, -0.6257929801940918, -0.312326580286026, 0.04285424202680588, 0.519008994102478, 0.026113135740160942, -0.35176366567611694, -0.6432396769523621, 0.08749046176671982, 0.7212860584259033, -0.42128077149391174, 0.0557720623910427...
finds a problem I can log the version they are using as well as tell them to upgrade if they have an old release. A short explanation of how the versioning works would also be appreciated. When does the build and revision number get incremented? With the "Built in" stuff, you can't, as using 1.0.\* or 1.0.0.\* will replace the revision and build numbers with a coded date/timestamp, which is usually also a good way. For more info, see the [Assembly Linker](http://msdn2.microsoft.com/en-us/library/c405shex(vs.80).aspx) Documentation in the /v tag. As for automatically incrementing numbers, use the AssemblyInfo Task: [AssemblyInfo Task](http://code.msdn.microsoft.com/AssemblyInfoTaskvers) This can be configured to automatically increment
[ 0.19982367753982544, 0.16577944159507751, 0.4741716980934143, -0.08880139887332916, 0.2438828945159912, -0.24058879911899567, 0.3413156569004059, 0.04804655909538269, -0.5159149765968323, -0.8676158785820007, -0.2652541697025299, 0.8159223198890686, -0.18279212713241577, 0.1896441429853439...
the build number. There are 2 Gotchas: 1. Each of the 4 numbers in the Version string is limited to 65535. This is a Windows Limitation and unlikely to get fixed. * [Why are build numbers limited to 65535?](http://blogs.msdn.com/msbuild/archive/2007/01/03/why-are-build-numbers-limited-to-65535.aspx) 2. Using with with Subversion requires a small change: * [Using MSBuild to generate assembly version info at build time (including SubVersion fix)](http://www.andrewconnell.com/blog/archive/2006/08/29/4078.aspx) Retrieving the Version number is then quite easy: ``` Version v = Assembly.GetExecutingAssembly().GetName().Version; string About = string.Format(CultureInfo.InvariantCulture, @"YourApp Version {0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision); ``` --- And, to clarify: In .net or at least in C#, the build is actually the THIRD number, not the fourth one as some
[ 0.04364645108580589, 0.1368645876646042, 0.6378651857376099, -0.3585399091243744, -0.12352863699197769, 0.0747729241847992, 0.6554841995239258, -0.25769004225730896, -0.39582905173301697, -0.4433371126651764, -0.38340866565704346, 0.4511652886867523, -0.2714816927909851, 0.2515759170055389...
people (for example Delphi Developers who are used to Major.Minor.Release.Build) might expect. In .net, it's Major.Minor.Build.Revision.
[ 0.11221632361412048, -0.20317614078521729, 0.18229053914546967, -0.3215096890926361, 0.035787586122751236, -0.668507993221283, 0.16107237339019775, 0.23220615088939667, -0.22753363847732544, -0.5373964309692383, -0.5099143981933594, 0.7238155007362366, -0.13519395887851715, 0.0764838233590...
I've been having trouble getting my ASP.NET application to automatically log users into the Intranet site I'm building. No matter the googling or the experimentation I applied, there is always a login box displayed by IE7. I've got Windows authentication mode set in the Web.config, disabled anonymous access and configured the correct default domain in IIS, but it's still asking the user to log in and, more annoyingly, the user is required to provide the domain too (*DOMAIN\auser*), which is causing problems with non-technical visitors. Thank Zeus for password remembering functionality. I'm not the network administrator so it's possible that something about
[ 0.413133442401886, 0.28948482871055603, 0.09722897410392761, -0.11464492976665497, -0.08643179386854172, -0.16967733204364777, 0.643929123878479, 0.3477479815483093, -0.32450157403945923, -0.8046095371246338, -0.15224382281303406, 0.61835116147995, -0.03738979622721672, 0.27421170473098755...
Active Directory is set up incorrectly, or it could just be me missing something very simple. Please note that I don't want to impersonate the user, I just need to know that the IPrincipal.Name property matches that of a valid record in my user database, hence authenticating the user to my application. To this end, it would be very useful to have a checklist of all configuration requirements for AD, ASP.NET and IIS to work together in this manner as a reference for debugging and hopefully reducing some user friction. It sounds like you've covered all the server-side bases--maybe it's a client
[ 0.2874602973461151, 0.15562252700328827, 0.5190608501434326, 0.17972305417060852, -0.027242371812462807, -0.4824121296405792, 0.338690847158432, 0.04218073934316635, -0.20689158141613007, -0.6677961945533752, 0.038531213998794556, 0.6103319525718689, -0.3350224196910858, 0.1895471513271331...
issue? I assume your users have integrated authentication enabled in IE7? (Tools -> Internet Options -> Advanced -> Security). This is enabled by default. Also, is your site correctly recognized by IE7 as being in the Local Intranet zone? The IE7 default is to allow automatic logon only in that zone, so users would be prompted if IE thinks your site is on the internet. I believe using a hostname with a dot in it causes IE to place the site into the Internet zone.
[ 0.041213274002075195, -0.08498066663742065, 0.6028229594230652, -0.3026679754257202, 0.3240528404712677, -0.49275749921798706, 0.5133795738220215, 0.22396160662174225, -0.4256393611431122, -0.7118021845817566, -0.3449307382106781, 0.3950777053833008, -0.37010714411735535, -0.09491812437772...
This is ASP classic, not .Net. We have to get a way to SFTP into a server to upload and download a couple of files, kicked off by a user. What have other people used to do SFTP in ASP classic? Not necessarily opposed to purchasing a control. If you have the ability to use WScript.Shell then you can just execute pscp.exe from the [Putty](http://www.chiark.greenend.org.uk/~sgtatham/putty/) package. Obviously this is less then ideal but it will get the job done and let you use SCP/SFTP in classic ASP.
[ 0.4383351504802704, -0.4067825376987457, 0.23300135135650635, 0.06545349210500717, -0.16739895939826965, -0.3355277478694916, 0.003404619637876749, -0.05559517815709114, -0.397230327129364, -0.42596134543418884, 0.06751643866300583, 0.3027692139148712, -0.4564627408981323, -0.0832824185490...