text stringlengths 0 30.5k | title stringclasses 1
value | embeddings listlengths 768 768 |
|---|---|---|
**Can a regular expression match whitespace *or* the start of a string?**
I'm trying to replace currency the abbreviation GBP with a £ symbol. I could just match anything starting GBP, but I'd like to be a bit more conservative, and look for certain delimiters around it.
```
>>> import re
>>> text = u'GBP 5 Off when ... | [
-0.08441566675901413,
0.15933258831501007,
0.5449532866477966,
-0.10955876857042313,
-0.34887707233428955,
0.13836036622524261,
0.35286378860473633,
-0.2756330668926239,
-0.17238019406795502,
-0.5659176707267761,
-0.4165865480899811,
0.39462754130363464,
-0.3532349467277527,
-0.13590040802... | |
I do both of the latter examples at the same time?
Use the OR "`|`" operator:
```
>>> re.sub(r'(^|\W)GBP([\W\d])', u'\g<1>£\g<2>', text)
u'\xa3 5 Off when you spend \xa375.00'
``` | [
0.23452837765216827,
0.2554383873939514,
0.4846140742301941,
-0.41578829288482666,
0.1279849261045456,
-0.017763596028089523,
0.4532211720943451,
-0.2733478248119354,
0.023360807448625565,
-0.38350823521614075,
-0.45106765627861023,
0.6163382530212402,
-0.00155066663865,
0.3224645256996155... | |
As the title says. Is there a way to integrate the two?
I'm sure it's possible if you're skilled with both, but the question on my lips and all the Seam developers is "why?"
Seam combines JSF and Hibernate. Where does Spring fit? What is it providing for you that the Seam stack doesn't?
I haven't done it. I use Sprin... | [
0.42527028918266296,
-0.3323996365070343,
-0.31308460235595703,
-0.0953495055437088,
-0.1059434711933136,
-0.0393739715218544,
0.20439712703227997,
-0.09074802696704865,
-0.3424507975578308,
-0.5897489786148071,
-0.0415615476667881,
0.37564435601234436,
0.1807161420583725,
-0.0904051139950... | |
on any Java EE app server, including JBOSS. | [
-0.04769715666770935,
-0.04834030941128731,
0.03862314671278,
-0.11265825480222702,
0.05096439644694328,
-0.07830147445201874,
0.14123371243476868,
0.45559483766555786,
-0.2481674700975418,
-0.7159092426300049,
-0.8266332745552063,
0.5157647132873535,
-0.23254187405109406,
0.01791270077228... | |
After reading [how to keep your dev machine from slowing down](https://stackoverflow.com/questions/420572/how-do-you-keep-your-windows-development-machine-from-slowing-down), I was reminded of my good intention a year ago to build a VM for my development machine.
However, I'm developing WPF and SilverLight GUIs on Vis... | [
0.47926267981529236,
0.12093967944383621,
0.6225668787956238,
0.04715600609779358,
-0.029357509687542915,
-0.06470166891813278,
0.2978028357028961,
0.012816355563700199,
-0.13138030469417572,
-0.669104278087616,
0.19990043342113495,
1.080153226852417,
-0.2186274528503418,
-0.03464372083544... | |
already create VMs with my VMWare Fusion on OS/X so just using the free VMWare Player is fine - I haven't been able to find any comments about differences in GPU support between Player and Workstation.
My main Windows dev machine is only a Dell laptop (Latitude 830) with 4GB RAM but I have to work on a laptop for clie... | [
0.4291558861732483,
0.17751595377922058,
0.6507192850112915,
0.18884500861167908,
-0.28971990942955017,
-0.061937086284160614,
0.278627872467041,
-0.17577755451202393,
-0.24627868831157684,
-0.7994421124458313,
0.18230438232421875,
0.5562490224838257,
-0.22628308832645416,
0.25577455759048... | |
on VMWare (albeit miles better than MS Virtual PC's non-existent DirectX support).
The problem you're going to face is that Visual Studio and Expression both constantly re-render your XAML while you're working on it, which requires heavy significant GPU bandwidth. Working inside a VM simply doesn't cut it and, dependi... | [
0.6632864475250244,
0.1042003333568573,
0.41375526785850525,
0.21847018599510193,
-0.08088967949151993,
-0.33950555324554443,
0.32460808753967285,
0.11758897453546524,
-0.2539835572242737,
-0.7425571084022522,
-0.06588531285524368,
0.7487511038780212,
-0.07598337531089783,
0.24461835622787... | |
I need advice on this snippet
```
$text = preg_replace('|(A.*)?A(.*)C|', '$1foo$2bar', $text);
```
This will match ABC in "AB ABC D", and replace it with "AB fooBbar D"; as you can see this matches the "AB " part at the beginning as well, which I have to repeat in the replacement string with $1, in order not to lose... | [
0.27691274881362915,
0.5186257362365723,
0.26896414160728455,
-0.134618878364563,
0.19278445839881897,
0.015831727534532547,
0.4057008624076843,
-0.2410261034965515,
-0.0063309804536402225,
-0.4479523003101349,
-0.10533716529607773,
0.5359882116317749,
-0.4340718388557434,
-0.0225052069872... | |
presented example is in fact buggy, as it matches only the second "ABC" in "ABC ABC".
**EDIT2**: I'm sorry, I've probably explained the problem very badly. The point is I'd want to match **whatever** is between two A,C string, so that there is no substring A in the match
Again thanks
As the question has been clarifie... | [
0.0513630136847496,
0.4036899209022522,
0.3532257676124573,
-0.20937234163284302,
0.17096078395843506,
-0.12831765413284302,
0.3966642916202545,
-0.18328949809074402,
-0.31685417890548706,
-0.3874019384384155,
-0.26128119230270386,
0.470756858587265,
-0.7420139312744141,
0.0176986381411552... | |
Say I have table with two columns: Name, Age.
I want to design a query that will return the names and ages sorted by age, but to also have an additional column which will run from 1 to N (the last row).
So for a table with the following rows:
```
John, 28
Jim, 30
Mike, 28
```
The following rows will be returned
`... | [
0.0725460797548294,
0.5608615875244141,
0.7238811254501343,
-0.31173065304756165,
0.17927542328834534,
0.42320892214775085,
0.04619172215461731,
-0.14879284799098969,
-0.15815557539463043,
-0.6361846327781677,
-0.010570663958787918,
0.2391897439956665,
-0.09119869768619537,
0.3054018318653... | |
you need to have unique values in one of the columns of the table , in this example I've used name but it could be any unique column)
```
select rank=count(*), a1.name, a1.age
from table1 a1, table1 a2
where a1.name >= a2.name
group by a1.name , a1.age
order by rank
``` | [
-0.07057281583547592,
0.4092409312725067,
0.2654367983341217,
-0.136531800031662,
0.14879366755485535,
0.2138073444366455,
0.031775470823049545,
-0.5385204553604126,
-0.4421943426132202,
-0.49072450399398804,
-0.23062478005886078,
0.14257624745368958,
0.19129638373851776,
0.175939038395881... | |
What is the best way to programmatically restore and give focus to a third-party application (say, GoogleTalk or Twhirl) running in the system tray? I am writing my utility in C#, but I obviously have no control over the third-party application.
Use something like FindWindow /[FindWindowEx](http://msdn.microsoft.com/en... | [
0.3138909935951233,
-0.049521129578351974,
0.3554089665412903,
0.06838743388652802,
-0.043468717485666275,
-0.12079477310180664,
0.2901879847049713,
0.022771190851926804,
-0.04358033463358879,
-0.7368274331092834,
-0.2355964481830597,
0.7872564792633057,
-0.07642752677202225,
-0.1159638464... | |
My current question is what does the << operator do in Ruby? But my real question is how would I search Google to find the answer?
Google for "ruby operators" (without the quotes), open the first link in a new window, use your browser to search for '<<' (without the quotes). | [
0.44190114736557007,
0.2157197743654251,
0.10910991579294205,
0.19592270255088806,
-0.21770095825195312,
-0.025982653722167015,
0.39103952050209045,
-0.0526568666100502,
0.028757866472005844,
-0.35665568709373474,
0.04088396206498146,
0.38414913415908813,
-0.41145259141921997,
0.0401116944... | |
How to override or extend .net main classes. for example
```
public class String
{
public boolean contains(string str,boolean IgnoreCase){...}
public string replace(string str,string str2,boolean IgnoreCase){...}
}
```
after
```
string aa="this is a Sample";
if(aa.contains("sample",false))
{...}
```
is it... | [
0.21702556312084198,
0.05035698041319847,
0.2814532518386841,
0.03517460450530052,
0.41342100501060486,
-0.21675454080104828,
0.26412031054496765,
-0.6209822297096252,
-0.10457757860422134,
-0.41369494795799255,
-0.494351863861084,
0.6797739267349243,
-0.49421536922454834,
0.20014004409313... | |
using VS 2008 in order to use extension methods. | [
0.03893253952264786,
-0.2685127854347229,
0.12507186830043793,
0.03916459530591965,
-0.3855341672897339,
-0.05118148401379585,
0.16058875620365143,
0.003007714869454503,
-0.14343419671058655,
-0.5306861400604248,
-0.15790680050849915,
0.2660548686981201,
-0.16941256821155548,
-0.1746533960... | |
How can I detect that my .NET application has crashed, and then restart it?
Another solution (based on [this example](http://community.bartdesmet.net/blogs/bart/archive/2006/08/30/4366.aspx)) is to create a launcher that controls the application:
```
class LauncherProgram
{
static int count = 3;
static void M... | [
0.4409239888191223,
-0.07013852894306183,
0.3482888638973236,
-0.1269286572933197,
0.4028914272785187,
-0.02976362034678459,
0.2320742905139923,
0.012211616151034832,
-0.4082179367542267,
-0.5081509351730347,
-0.43025001883506775,
0.35341429710388184,
-0.2814946472644806,
0.247478023171424... | |
process.EnableRaisingEvents = true;
process.Exited += LaunchIfCrashed;
}
static void LaunchIfCrashed(object o, EventArgs e)
{
Process process = (Process) o;
if (process.ExitCode != 0)
{
if (count-- > 0) // restart at max count times | [
-0.006068254821002483,
-0.1422477811574936,
0.5086802244186401,
-0.23726730048656464,
0.4205285906791687,
0.1801864057779312,
0.2908194661140442,
-0.07772120833396912,
-0.2471633404493332,
-0.34406545758247375,
-0.4778483808040619,
0.5297987461090088,
-0.21730594336986542,
0.03490805253386... | |
Launch();
else
Environment.Exit(process.ExitCode);
}
else
{
Environment.Exit(0);
}
}
``` | [
0.13500726222991943,
0.07216542959213257,
0.011535653844475746,
-0.10626688599586487,
0.46129366755485535,
-0.005804361309856176,
0.022120151668787003,
0.05875842645764351,
0.04230760037899017,
-0.5145371556282043,
-0.6257656812667847,
0.44175297021865845,
-0.3630814850330353,
0.2770246565... | |
How do I echo one or more tab characters using a bash script?
When I run this code
```
res=' 'x # res = "\t\tx"
echo '['$res']' # expect [\t\tx]
```
I get this
```
res=[ x] # that is [<space>x]
```
```
echo -e ' \t '
```
will echo 'space tab space newline' (`-e` means 'enable interpretation of backslash es... | [
0.17329169809818268,
0.15985292196273804,
0.31454384326934814,
-0.40703099966049194,
0.013322130776941776,
0.04489011690020561,
0.6131561398506165,
-0.7518416047096252,
-0.09497182071208954,
-0.2630835175514221,
-0.052257560193538666,
0.4899381399154663,
-0.4094182252883911,
-0.12605178356... | |
| . .|
``` | [
0.333307147026062,
0.5734086632728577,
0.2647308111190796,
0.007960053160786629,
-0.10815386474132538,
-0.06074319779872894,
0.3412073850631714,
0.05967029929161072,
0.19960519671440125,
-0.6349670886993408,
-0.38889551162719727,
0.3367893397808075,
-0.3261711597442627,
0.17076942324638367... | |
In Windows when you create a window, you must define a (c++)
```
LRESULT CALLBACK message_proc(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);
```
to handle all the messages sent from the OS to the window, like keypresses and such.
Im looking to do some reading on how the same system works in Linux. Maybe... | [
0.052934493869543076,
0.11458124220371246,
0.41821807622909546,
-0.27450692653656006,
-0.32102808356285095,
0.05747200548648834,
0.10445668548345566,
0.26145681738853455,
-0.2834068536758423,
-0.6226402521133423,
-0.35563379526138306,
0.5449510812759399,
-0.4302438199520111,
0.080308571457... | |
KDE) or is it handled on a lower level in the OS?
**Edit**: Ive looked into tools like QT and WxWidgets, but those frameworks seems to be geared more towards developing GUI extensive applications. Im rather looking for a way to create a basic window (restrict resize, borders/decorations) for my OGL graphics and retrie... | [
0.10687732696533203,
-0.0807110071182251,
0.4999144375324249,
0.2898330092430115,
-0.22749537229537964,
0.020755043253302574,
0.002041097730398178,
-0.18926121294498444,
-0.1533742994070053,
-0.6220546960830688,
-0.01808764599263668,
0.4371855556964874,
-0.1370745152235031,
0.0713397637009... | |
few basic features I want myself?
In principle it is absolutely the same. However, it has nothing to do with communication with the OS (nor does it on win32, using user32.dll is entirely optional)
A GUI application has an event loop somewhere, which processes messages from a queue at some level.
There are a lot of li... | [
0.3746829628944397,
0.025446776300668716,
0.1592346727848053,
-0.11152870953083038,
0.04827757179737091,
-0.14664573967456818,
0.23468078672885895,
0.07793138176202774,
-0.03232503682374954,
-0.5240676403045654,
-0.06414460390806198,
0.6886443495750427,
-0.31804853677749634,
-0.03599642217... | |
use the low-level GUI, or can use a library. Most use a library. Applications can also choose to do neither and operate without a GUI (server applications typically do this). Applications can create multiple threads, one of which sits in an event loop, and others work differently. This is a popular approach too.
* Mos... | [
0.3871757686138153,
-0.09126720577478409,
-0.060346875339746475,
0.449899822473526,
0.030878989025950432,
-0.38504889607429504,
-0.1356639862060547,
0.11902858316898346,
-0.4017783999443054,
-0.6557931900024414,
-0.1989869773387909,
0.6334540247917175,
-0.4135618209838867,
-0.0148378144949... | |
process their event loop.
* These things are largely true on Win32 and Linux. | [
0.18852442502975464,
-0.0725056603550911,
-0.05871144309639931,
0.2129010409116745,
-0.16689598560333252,
-0.27593761682510376,
0.26147547364234924,
0.22590486705303192,
-0.3140374720096588,
-0.5832491517066956,
-0.00494277523830533,
0.5138140916824341,
-0.24533502757549286,
0.038503240793... | |
Such as:
* Sealed Methods you might have liked to extend
* Exceptions thrown are more vague than is helpful
* Elimination of **Connected Content** which was a major feature in **MCMS 2002**
* HTML is stripped from fields when stored and returned. No easy option to work around this problem
* Creating an SPWeb takes an ... | [
0.18568335473537445,
0.02833915874361992,
0.2735927402973175,
0.13402871787548065,
-0.2498621940612793,
-0.5431817770004272,
0.46929025650024414,
-0.13907001912593842,
-0.5723055005073547,
-0.8209381103515625,
-0.06086090952157974,
0.24753153324127197,
-0.45421111583709717,
0.1261262446641... | |
not get called in a WSS app. And I thought the reason for moving to .NET was to free developers from having to deal with memory management... | [
0.28943338990211487,
-0.009795538149774075,
0.0205899178981781,
0.03869777172803879,
-0.09153159707784653,
-0.3869907259941101,
0.25721055269241333,
0.31864041090011597,
0.07279888540506363,
-0.40645864605903625,
0.001407063566148281,
0.429686963558197,
-0.4216552674770355,
0.1264177113771... | |
How can I add a background image to my delphi form? I added a TImage, but now the labels aren't visible any more, and the texts of my checkboxes are in a blue "box" (blue is the background color i chose). This blue doesn't look very good on the background image, and the hidden labels also don't look good. How do I fix ... | [
0.2031862735748291,
-0.12196042388677597,
0.3303874731063843,
0.19467617571353912,
0.08106053620576859,
0.11230708658695221,
0.20685125887393951,
0.13314366340637207,
-0.162795752286911,
-0.5587316155433655,
0.057822372764348984,
0.2435586005449295,
-0.37464219331741333,
-0.060262002050876... | |
"Send to back" command on the TImage component in design mode, it will make all other non-windowed controls appear on top of it.
For the checkboxes I don't know what the problem in your case is, in Delphi 2007 checkboxes appear properly transparent when put over a TImage. Maybe you use an earlier Delphi version? If so... | [
-0.2429746389389038,
-0.5290535688400269,
0.4422619342803955,
-0.09405690431594849,
-0.4711509943008423,
-0.03369457274675369,
0.04126430302858353,
0.1539595127105713,
-0.5220230221748352,
-0.40612494945526123,
0.036225441843271255,
0.6499510407447815,
-0.3125389516353607,
0.04338816180825... | |
I am having problems getring a simple redirect statement to take effect on my Godaddy account. I have the following statements in my .htaccess file:
```
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.net$ [NC]
RewriteRule ^(.*)$ http://mydomain.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^mydomain.net$ [NC]
R... | [
0.1133282259106636,
0.2307981550693512,
0.9376621842384338,
-0.17950516939163208,
-0.0395192988216877,
-0.11412752419710159,
0.62286776304245,
-0.18048840761184692,
-0.1547500193119049,
-0.7189319133758545,
-0.07287860661745071,
0.5769806504249573,
-0.19584304094314575,
0.2029593139886856,... | |
prefix (which always is the same for a specific directory) is automatically *removed* for the pattern matching and automatically *added* after the substitution has been done.
>
> – <http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule>
So just leave the leading slash out of the pattern. | [
0.18738898634910583,
-0.43538281321525574,
0.7045689225196838,
-0.11946956068277359,
-0.08939561992883682,
-0.03155573457479477,
0.3666793704032898,
-0.23504075407981873,
-0.307538777589798,
-0.8195769190788269,
-0.1310240477323532,
0.26662003993988037,
-0.2187846601009369,
0.0925663188099... | |
I am doing some socket programming in C, and trying to wrestle with byte order problems. My request (send) is fine but when I receive data my bytes are all out of order. I start with something like this:
```
char * aResponse= (char *)malloc(512);
int total = recv(sock, aResponse, 511, 0);
```
When dealing with this ... | [
0.31694647669792175,
-0.157313734292984,
0.3550475239753723,
-0.28705093264579773,
0.014198504388332367,
0.3084685504436493,
0.44724756479263306,
-0.20738352835178375,
-0.42324018478393555,
-0.6657950282096863,
-0.14403782784938812,
0.49794894456863403,
-0.2958610951900482,
0.1597910821437... | |
= 0; i < total; ++i)
{
newhostOrder[i] = ntohs(_netOrder[i]);
}
```
This works ok when I am treating the data as a short, however if I cast the pointer to a char again the bytes are reversed. What am I doing wrong?
Ok, there seems to be problems with what you are doing on two different levels. Part o... | [
0.19207580387592316,
0.13439637422561646,
0.3540279269218445,
-0.3030704855918884,
0.12128325551748276,
-0.08214280754327774,
0.5676533579826355,
-0.3061716854572296,
-0.315392404794693,
-0.358551561832428,
-0.06111212074756622,
0.4958004951477051,
-0.23555651307106018,
0.19704847037792206... | |
the memory pointed to by the pointer(s).
The encoding of multi-byte entities in memory is what is referred to as endianess. The two common encodings are referred to as ***Little Endian*** (LE) and **Big Endian** (BE). With LE, a 16-bit quantity like a short is encoded least significant byte (LSB) first. Under BE, the ... | [
-0.05633348226547241,
-0.20142002403736115,
0.056215882301330566,
-0.12235622853040695,
0.05592058226466179,
0.5089002251625061,
-0.05695218965411186,
0.0824107974767685,
-0.22956620156764984,
-0.5775817632675171,
-0.36207565665245056,
0.16483575105667114,
-0.18823906779289246,
0.080095186... | |
into conversion problems. However, your code would then be platform dependent on the BE convention. If you want to write portable code that works correctly on both LE and BE platforms, you should not assume the platform's endianess.
Achieving endian portability is the purpose of routines like ***ntohs()***, ***ntohl()... | [
-0.0072798640467226505,
-0.09109776467084885,
0.32323285937309265,
-0.10777197033166885,
-0.17482799291610718,
0.2394612580537796,
0.21678902208805084,
-0.3656964898109436,
-0.09358809888362885,
-0.80161052942276,
-0.22069253027439117,
0.5999283194541931,
-0.2340901643037796,
-0.0101616131... | |
value from network order to host order (after receive)
* ***ntohl()*** - Convert long value from network order to host order (after receive)
Understand that your comment about accessing the memory when cast back to characters has no affect on the actual order of entities in memory. That is, if you access the buffer as... | [
0.018865592777729034,
-0.2965123653411865,
0.6316273212432861,
-0.15266354382038116,
-0.0015010508941486478,
0.19598333537578583,
0.0006368766189552844,
-0.15240123867988586,
-0.48141276836395264,
-0.5840478539466858,
-0.3629917502403259,
0.3654910624027252,
-0.013654318638145924,
0.443611... | |
always. If you look at the output buffer after your have converted back to host order, if you have BE machine, the byte order will be unchanged. Conversely, on a LE machine, the bytes will all now be reversed in the converted buffer.
Finally, in your conversion loop, the variable `total` refers to bytes. However, you ... | [
0.41982412338256836,
-0.40137603878974915,
0.1055545061826706,
-0.09166723489761353,
0.20792515575885773,
0.27639445662498474,
0.13299664855003357,
0.023199355229735374,
-0.5984949469566345,
-0.718220055103302,
-0.41985636949539185,
0.4269217252731323,
-0.14236627519130707,
0.0254644192755... | |
I've got a problem that keeps coming up with normalized databases and was looking for the best solution.
Suppose I've got an album information database. I want to setup the schema in a normalized fashion, so I setup two tables - albums, which has one listing for each album, and songs, which lists all songs contained b... | [
0.342124342918396,
0.3615310490131378,
0.1053747683763504,
0.21564972400665283,
0.3035189211368561,
0.007852348499000072,
-0.23089271783828735,
-0.4358600378036499,
-0.48730358481407166,
-0.4043908715248108,
0.15474793314933777,
0.8395639657974243,
-0.03621526062488556,
0.09511654078960419... | |
a single album is simple, but how do you grab multiple albums at once in a single query?
Thus far, the best answer I have come up with is grouping by aid and converting the songs information as arrays. For example, the result would look something like this:
```
aid, sids, lengths
1, [1, 2], [1:04, 5:45]
2, ... | [
0.246326744556427,
0.29907289147377014,
0.13592177629470825,
0.16315151751041412,
-0.10837949812412262,
0.08196359872817993,
-0.03226397931575775,
-0.7115700244903564,
-0.2792479693889618,
-0.2611869275569916,
0.2181154042482376,
0.5230194330215454,
-0.08258062601089478,
-0.017302352935075... | |
values just to separate them later.
My question: What is the best way to access a database with this sort of schema? Am I stuck with multiple arrays? Should I store the entirety of a song's information in an object and then those songs into a single array, instead of having multiple arrays? Or is there a way of adding... | [
0.1636689156293869,
0.2172369360923767,
0.38479161262512207,
0.3703770339488983,
-0.09142103791236877,
0.17293433845043182,
0.28657713532447815,
-0.2986268103122711,
-0.3049631714820862,
-0.26368391513824463,
0.2678951621055603,
0.4645751714706421,
-0.13244980573654175,
0.2292730212211609,... | |
it makes any difference, I'm using a PostgreSQL db along with a PHP front-end.
I have difficulty seeing your point. What exactly do you mean by "how do you grab multiple albums at once in a single query"? What exactly do you have difficulties with?
Intuitively I would say:
```
SELECT
a.aid album_id,
a.name a... | [
0.07838010042905807,
0.19463461637496948,
0.33817264437675476,
0.016261883080005646,
-0.2949017882347107,
0.04380602017045021,
0.1492718756198883,
-0.7380589842796326,
-0.0017056369688361883,
-0.4247978925704956,
0.13623027503490448,
0.7035470008850098,
-0.15942975878715515,
0.054501838982... | |
album_id,
a.name album_name,
COUNT(s.sid) count_songs,
SUM(s.length) sum_length /* assuming you store an integer seconds value */
FROM /* here, not a string containing '3:18' or such */
albums a
INNER JOIN songs s ON a.aid = s.aid
WHERE
a.aid IN (1, 2, 3)
GROUP BY
a.aid
... | [
0.10155735909938812,
0.3492268919944763,
0.43661752343177795,
-0.07409026473760605,
-0.08018871396780014,
0.18561173975467682,
0.33464041352272034,
-0.8327499032020569,
-0.10494677722454071,
-0.36613211035728455,
-0.04518831521272659,
0.6723782420158386,
-0.01666119508445263,
0.23917642235... | |
you calculate it yourself out of the query result #1 in your app.
Depending on how much data is cached in your app, and how long queries take the one strategy can be faster than the other. I would recommend querying the DB, though. DBs are made for this kind of stuff. | [
0.32493725419044495,
-0.08491939306259155,
0.1604491025209427,
0.3613578975200653,
-0.11340208351612091,
-0.06302851438522339,
0.06787603348493576,
-0.08146237581968307,
0.015192347578704357,
-0.5307292938232422,
0.3251113295555115,
0.41122639179229736,
0.01251535676419735,
-0.250478476285... | |
Yet another argument with a friend of mine. Consider this code:
```
class User < ActiveRecord::Base
has_many :groups
def in_group?(group)
groups.include?(group)
end
end
class Group < ActiveRecord::Base
has_many :members
def add_user(user)
members << user
end
end
```
My opinion is that these m... | [
0.009982249699532986,
0.38878387212753296,
0.11544406414031982,
-0.2248450666666031,
-0.12220197916030884,
-0.19255517423152924,
0.35150864720344543,
-0.3556877672672272,
-0.024271676316857338,
-0.6115077137947083,
0.2696484625339508,
0.6457377672195435,
-0.2301482856273651,
-0.14309063553... | |
User#groups.include?(group) and Group#members << user. They are easily guessable and in case if I'll need some extra functionality, I can use callbacks for has\_many :members and override User#groups.include? in the association extension module if that would be necessary.
However friend of mine argues that it is bette... | [
0.3106716275215149,
0.05932806804776192,
-0.015946319326758385,
-0.019792377948760986,
-0.1462727040052414,
-0.2618033289909363,
0.11311257630586624,
-0.18809981644153595,
-0.29811063408851624,
-0.4701908826828003,
0.23571550846099854,
0.5848706364631653,
-0.5393471121788025,
0.01491540111... | |
objects. That's the job of the association proxy. I'd also beware of overriding association proxy behaviors, since you're liable to see some strange side effects due to the way the proxies are implemented. | [
0.219961017370224,
0.17227473855018616,
0.24025802314281464,
0.5817727446556091,
-0.3334850072860718,
-0.03851354122161865,
0.36895373463630676,
0.2059209942817688,
-0.16641587018966675,
-0.3788640797138214,
-0.15112973749637604,
0.5513762831687927,
-0.38393789529800415,
0.0583461262285709... | |
As part of my application, I'm putting together a set of small Dom nodes that are not shown all at once. I'm storing them in an internal array. The user can invoke their display in which case I reparent them to the div that is used to display them. That's all well and good. But when it's time to replace all of them wit... | [
0.21741454303264618,
0.04293372109532356,
0.5604134202003479,
-0.03330644592642784,
0.14328892529010773,
0.1060490533709526,
0.2160651981830597,
0.013259473256766796,
-0.2255251556634903,
-0.8295788168907166,
-0.16228453814983368,
0.5942802429199219,
-0.21537767350673676,
0.298520773649215... | |
the items in my array of Dom nodes to null enough? Is there something else I have to do? Or maybe I don't have to worry about this at all?
Try SelectMany.
```
IEnumerable<int> Collapse(IEnumerable<IEnumerable<int>> e){
return e.SelectMany(x => x );
}
```
The purpose of this function is to flatten a group of IEnumer... | [
-0.1822342872619629,
-0.23865565657615662,
0.49337977170944214,
-0.35996076464653015,
0.14794863760471344,
-0.0085398955270648,
0.34769004583358765,
-0.3186628520488739,
-0.15231141448020935,
-0.8226145505905151,
-0.3985755443572998,
0.7608665823936462,
-0.2619568407535553,
0.4300343394279... | |
I'm aware that you can get session variables using `request.session['variable_name']`, but there doesn't seem to be a way to grab the session id as a variable in a similar way. Is this documented anywhere? I can't find it.
```
request.session.session_key
```
Note the key will only exist if there is a session, no key,... | [
0.5431482195854187,
0.15387026965618134,
-0.16921524703502655,
0.13527776300907135,
0.032126810401678085,
-0.47049856185913086,
0.27572694420814514,
0.11255182325839996,
-0.27714329957962036,
-0.6284768581390381,
0.2384154349565506,
0.7031559348106384,
-0.23150841891765594,
0.5131508708000... | |
Is it possible to compute the ranges of float, double and long double data types in a portable way without reading float.h and using ANSI C? By portable, I mean including those cases when the target machine does not adhere to IEEE 754 standard.
I'm reading the K&R book and exercise 2-1 asks me to "compute" them so I s... | [
0.3314172625541687,
0.3198182284832001,
0.16127824783325195,
0.2336929738521576,
-0.015504211187362671,
-0.14127254486083984,
0.18751458823680878,
-0.3207956552505493,
-0.11259111016988754,
-0.4107300341129303,
0.016322098672389984,
0.7455928325653076,
-0.2117798924446106,
-0.3365486264228... | |
header is provided - because there isn't a portable way to derive the information contained in it. | [
0.3314093351364136,
0.008899882435798645,
-0.12726809084415436,
0.3946428894996643,
-0.01578371413052082,
-0.5478437542915344,
-0.31528207659721375,
-0.017417510971426964,
-0.06698787212371826,
-0.4426555931568146,
-0.3173958957195282,
0.01718808338046074,
-0.13610796630382538,
-0.15289995... | |
Is there any other reasoning other than the timeout setting in the web.config not being used? It might be the default timeout of 30 minutes but it is definitely less than 30 minutes.
```
<authentication mode="Forms">
<forms timeout="50000000" loginUrl="content/login.aspx"/>
</authentication>
```
... | [
0.050241418182849884,
-0.10666705667972565,
0.9869222044944763,
-0.08581499755382538,
0.29769694805145264,
-0.35289639234542847,
0.5413545370101929,
-0.5524016618728638,
-0.2902693450450897,
-0.7053472399711609,
-0.12428590655326843,
0.5703250765800476,
0.2520865797996521,
-0.0643405467271... | |
{
FailureText.Text = "<br/>Login Failed. Please try again";
}
}
```
[Edit]
I believe the timeout occurs around 10 minutes of idleness..
The ASP.NET authentication timeout can be set in the web.config file (as you've shown in your question), however, this can also be set in code. Do you have any areas of... | [
0.36707067489624023,
0.006247050128877163,
0.6480611562728882,
-0.11542338877916336,
0.18932829797267914,
-0.3452971875667572,
0.7486902475357056,
-0.27718615531921387,
-0.2709427773952484,
-0.8421964645385742,
-0.04065409302711487,
0.5966494083404541,
0.08751639723777771,
-0.3198880851268... | |
code, with something like the following:
```
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
name, | [
0.2606601417064667,
-0.2714051902294159,
0.38300424814224243,
0.7614731788635254,
0.3230932652950287,
-0.24604938924312592,
0.09006249904632568,
-0.18678884208202362,
0.06169942393898964,
-0.6282299160957336,
-0.14320364594459534,
0.25968897342681885,
-0.24134774506092072,
-0.0637774839997... | |
isPersistent,
expirationTime);
```
If you create a specific FormsAuthenticationTicket with a timeout setting of | [
0.2118590772151947,
-0.10647350549697876,
0.5974779725074768,
-0.2738198935985565,
0.38664886355400085,
-0.1589071899652481,
0.09613613784313202,
-0.2420710325241089,
0.12703734636306763,
-0.6670297980308533,
-0.40856707096099854,
0.42872855067253113,
-0.039897240698337555,
0.1904343515634... | |
(for example) 60 minutes, whilst your web.config setting indicates 30 minutes, the ticket set from within code will override the web.config setting.
Please note that the ASP.NET Session and the IIS Session time out values should have no effect on your forms authentication timeouts.
Of course, as a last possibility, s... | [
0.5223866701126099,
-0.14652103185653687,
0.4554407596588135,
0.17715808749198914,
-0.003978447522968054,
-0.5073087811470032,
0.37042543292045593,
-0.6349712014198303,
-0.21776816248893738,
-0.4593096971511841,
-0.02273613214492798,
-0.03535163402557373,
-0.11188806593418121,
0.0045681386... | |
these very issues. | [
0.058775659650564194,
0.27507051825523376,
-0.09720155596733093,
0.23374362289905548,
-0.01839582435786724,
0.3256446421146393,
-0.17844095826148987,
-0.19185088574886322,
-0.10160186886787415,
-0.4464614987373352,
0.04471758380532265,
0.5731821656227112,
-0.1290629655122757,
0.26607406139... | |
We are working on a project that requires us to allow users to register to receive email notifications of certain events. There will potentially be tens or hundreds of thousands of email messages based on any one event.
I know that this is done every day all over the web, but what I don't know is how email campaigns a... | [
0.8135590553283691,
0.2594417631626129,
0.060321416705846786,
0.12502434849739075,
-0.01666143722832203,
-0.3202948570251465,
0.44371357560157776,
0.32593798637390137,
-0.4549773633480072,
-0.21534176170825958,
0.2183753252029419,
0.18850688636302948,
-0.18574298918247223,
-0.0031725347507... | |
likely receive the bulk of the messages that we send.
Is there a standard methodology that is employed in order to conduct legitimate email campaigns that users have voluntarily registered for?
Four steps that will significantly increase your chances:
1. Make sure that your outgoing mail server is using well-behaved ... | [
0.3899949789047241,
-0.02782589942216873,
0.5393396019935608,
0.30389824509620667,
0.1284734308719635,
-0.20128050446510315,
0.34415170550346375,
-0.33755967020988464,
0.029508128762245178,
-0.6692492365837097,
0.09980493038892746,
0.4642062783241272,
-0.1897970587015152,
-0.27616500854492... | |
Set up DomainKeys for your domain, which can be a little complex.
5. Sign up for ISP feedback loops – (e.g. [Yahoo's](http://feedbackloop.yahoo.net/))
When rolling out one of our websites, our mail server was throttled by Yahoo! because of the volume of e-mail we were sending – all of which was sign-up notifications. ... | [
0.6948942542076111,
-0.20825839042663574,
0.5266237854957581,
0.14029279351234436,
-0.08440018445253372,
-0.2407192587852478,
0.39919331669807434,
0.14605475962162018,
-0.3669070303440094,
-0.5134545564651489,
0.1992522031068802,
0.10668907314538956,
-0.06796836853027344,
0.227972656488418... | |
third-party service, like [CertifiedEmail](http://www.certifiedemail.net/), which may cost money but which may also ensure a higher rate of delivery.
Finally, send test messages through your system to test accounts on all free webmail services, every ISP you can find, and every mail client you can get your hands on. O... | [
0.9562531113624573,
-0.1253221482038498,
-0.03937039524316788,
0.3815692365169525,
0.06648915261030197,
-0.397857129573822,
0.4972696900367737,
-0.05795526131987572,
-0.035683780908584595,
-0.6061280965805054,
0.06866704672574997,
0.2462397664785385,
0.05243534967303276,
-0.232310354709625... | |
I have a bunch of keys that each have an unlikeliness variable. I want to randomly choose one of these keys, yet I want it to be more unlikely for unlikely (key, values) to be chosen than a less unlikely (a more likely) object. I am wondering if you would have any suggestions, preferably an existing python module that ... | [
0.5159443616867065,
0.1507314294576645,
-0.21686774492263794,
0.20705246925354004,
0.130559042096138,
0.16953928768634796,
0.07343846559524536,
0.13658641278743744,
-0.23626768589019775,
-0.4764464795589447,
0.2701145112514496,
0.31171363592147827,
-0.20395977795124054,
0.2377202808856964,... | |
2,455 objects. Each set will exchange objects among each other so the random chooser needs to be dynamic. With 1000 sets of 2,433 objects, that is 2,433 million objects; low memory consumption is crucial. And since these choices are not the bulk of the algorithm, I need this process to be quite fast; CPU-time is limite... | [
0.14598596096038818,
-0.2652945816516876,
0.12869702279567719,
0.237840935587883,
-0.14528873562812805,
0.48801836371421814,
0.27083754539489746,
-0.23791126906871796,
-0.5263218283653259,
-0.7383815050125122,
-0.09319514036178589,
0.2634361982345581,
-0.3274673819541931,
0.250915408134460... | |
little in the hope of making more efficient:
```
def windex(dict, sum, max):
'''an attempt to make a random.choose() function that makes
weighted choices accepts a dictionary with the item_key and
certainty_value as a pair like:
>>> x = [('one', 20), ('two', 2), ('three', 50)], the
maximum certaint... | [
-0.19680331647396088,
-0.23448733985424042,
0.03615248203277588,
0.18006400763988495,
-0.16474883258342743,
0.31642040610313416,
-0.015877390280365944,
-0.34971392154693604,
-0.018754838034510612,
-0.34373030066490173,
-0.144512340426445,
0.46642136573791504,
-0.0071476781740784645,
0.0317... | |
float(max-certainty)/sum
if n < weight:
break
n = n - weight
return key
```
I am hoping to get an efficiency gain from dynamically maintaining the sum of certainties and the maximum certainty. Any further suggestions are welcome. You guys saves me so much time and effort, while increas... | [
0.5894181728363037,
-0.05965583771467209,
0.41944438219070435,
0.23652760684490204,
0.10662846267223358,
-0.40110114216804504,
0.17739108204841614,
-0.4958914518356323,
0.06399465352296829,
-0.46445661783218384,
0.17508649826049805,
0.9061400890350342,
-0.12664659321308136,
-0.120920374989... | |
in an acceptable loss in precision in my algo for it is dynamic in nature. Anyway, here is what I have now:
```
def weightedChoices(dict, sum, max, choices=10):
'''an attempt to make a random.choose() function that makes
weighted choices accepts a dictionary with the item_key and
certainty_value as a pair ... | [
-0.20363552868366241,
-0.0920485258102417,
0.13859784603118896,
0.058389145880937576,
-0.14801256358623505,
0.2590303122997284,
-0.11980649083852768,
-0.3525947630405426,
0.031143339350819588,
-0.5583932995796204,
0.03506728634238243,
0.5527962446212769,
-0.19258345663547516,
0.03679861873... | |
= relavate(list.sort())
keys = []
sum = max*len(list)-sum
for key, certainty in dict.iteritems():
weight = float(max-certainty)/sum
if n < weight:
keys.append(key)
if list: (n, list) = relavate(list)
else: break
n = n - weight | [
-0.28492578864097595,
-0.2068604975938797,
0.46135398745536804,
-0.0329001322388649,
0.2659294903278351,
0.18087436258792877,
0.09888523817062378,
-0.896448016166687,
-0.36415600776672363,
0.024395253509283066,
-0.1895270198583603,
0.7449444532394409,
0.08298611640930176,
0.062225818634033... | |
return keys
def relavate(list):
min = list[0]
new = [l - min for l in list[1:]]
return (min, new)
```
I haven't tried it out yet. If you have any comments/suggestions, please do not hesitate. Thx!
Update3:
I have been working all day on a task-tailored version of Rex Logan's answer. Instead of a 2 array... | [
0.026937682181596756,
-0.1272081583738327,
0.32251986861228943,
0.03088265471160412,
0.048878204077482224,
0.04743713513016701,
0.47695392370224,
-0.23262788355350494,
0.0679192915558815,
-0.6157804727554321,
-0.11394142359495163,
0.6355956792831421,
-0.24518059194087982,
0.093199819326400... | |
(but I can't really know until I try!). The basic principle is: the more a key is randomly generated often, the more unlikely it will be generated again:
```
import random, time
import psyco
psyco.full()
class ProbDict():
"""
Modified version of Rex Logans RandomObject class. The more a key is randomly
c... | [
0.09978868067264557,
-0.3585715591907501,
0.06161811947822571,
-0.035085100680589676,
0.16812892258167267,
-0.05287759751081467,
0.2254886031150818,
-0.32920965552330017,
-0.03788387402892113,
-0.2120548039674759,
0.006354710552841425,
0.6236813068389893,
-0.25691327452659607,
0.2361440360... | |
self._findSeniors()
self._effort = 0.15
self._fails = 0
def __iter__(self):
return self.next()
def __getitem__(self, key):
return self._kw[key]
def __setitem__(self, key, value):
self.append(key, value)
def __len__(self):
return self._len
def next(self... | [
-0.19308242201805115,
0.08378076553344727,
0.2478063553571701,
-0.25178807973861694,
0.10206691920757294,
0.4593826234340668,
0.31892940402030945,
-0.6777793169021606,
-0.30713143944740295,
-0.7755540609359741,
-0.0796642005443573,
1.0248717069625854,
-0.09482720494270325,
0.01079609431326... | |
while key:
yield key
key = self._key()
def __contains__(self, key):
return key in self._kw
def items(self):
return self._kw.items()
def pop(self, key):
try:
(w, value) = self._kw.pop(key) | [
0.018483126536011696,
-0.116094209253788,
0.35630881786346436,
-0.04251343384385109,
0.12983527779579163,
0.34177905321121216,
0.38510653376579285,
-0.5914461016654968,
-0.2182011753320694,
-0.5490923523902893,
-0.3500550389289856,
0.8006854057312012,
-0.012290413491427898,
0.0574881471693... | |
self._len -=1
if w == self._seniorW:
self._seniors -= 1
if not self._seniors:
#costly but unlikely: | [
-0.09258574992418289,
0.14461584389209747,
0.207985982298851,
0.12809881567955017,
0.2828020751476288,
0.17203986644744873,
0.21369394659996033,
-0.21964657306671143,
-0.19115884602069855,
-0.5447470545768738,
-0.11716779321432114,
0.6993650794029236,
0.28222501277923584,
-0.03985497727990... | |
self._findSeniors()
return [w, value]
except KeyError:
return None
def popitem(self):
return self.pop(self._key())
def values(self):
values = []
for key in self._keys:
try: | [
-0.10245086997747421,
0.10821717977523804,
0.34143728017807007,
-0.11121489107608795,
0.45577478408813477,
0.16512861847877502,
0.4042028784751892,
-0.40005946159362793,
-0.2591310143470764,
-0.48721572756767273,
-0.282985657453537,
0.8293210864067078,
-0.23455564677715302,
-0.085529282689... | |
values.append(self._kw[key][1])
except KeyError:
pass
return values
def weights(self):
weights = []
for key in self._keys:
try:
weights.append(self._kw[key][0]) | [
-0.11364094167947769,
0.11606866121292114,
0.28487706184387207,
-0.2112063318490982,
-0.04915531724691391,
0.175048366189003,
0.41155868768692017,
-0.8212823867797852,
-0.08119846880435944,
-0.3364986181259155,
-0.1035718023777008,
0.6134040951728821,
-0.2768324911594391,
-0.23201812803745... | |
except KeyError:
pass
return weights
def keys(self, imperfect=False):
if imperfect: return self._keys
return self._kw.keys()
def append(self, key, value=None):
if key not in self._kw:
self._len +=1 | [
-0.18464581668376923,
-0.13858334720134735,
0.21613802015781403,
-0.12601876258850098,
-0.26758649945259094,
0.17543300986289978,
0.6868928074836731,
-0.6965652704238892,
-0.034753989428281784,
-0.29103440046310425,
-0.3754931688308716,
0.8811759948730469,
-0.13363005220890045,
-0.18047769... | |
self._kw[key] = [0, value]
self._keys.append(key)
else:
self._kw[key][1]=value
def _key(self):
for i in range(int(self._effort*self._len)):
ri=random.randint(0,self._len-1) #choose a random object
rx=random.uniform(0,self._seniorW)
rkey = | [
-0.14067748188972473,
-0.2811512351036072,
0.12682786583900452,
-0.1506609171628952,
-0.10236029326915741,
0.4993872046470642,
0.08473655581474304,
-0.6778874397277832,
-0.1888083517551422,
-0.5284432768821716,
0.04806441813707352,
0.6318795084953308,
0.02115527354180813,
0.190138384699821... | |
self._keys[ri]
try:
w = self._kw[rkey][0]
if rx >= w: # test to see if that is the value we want
w += 1 | [
0.11427310109138489,
0.10937654972076416,
0.3671320676803589,
-0.32410845160484314,
0.03908165171742439,
0.2243255078792572,
0.40866711735725403,
-0.8036158680915833,
0.1473655104637146,
-0.3882518708705902,
0.2561447024345398,
0.7992536425590515,
-0.13138282299041748,
-0.05784229189157486... | |
self._warnSeniors(w)
self._kw[rkey][0] = w
return rkey
except KeyError:
self._keys.pop(ri)
# if you do not find one after 100 tries then just get a random one | [
0.1776442974805832,
-0.11390029639005661,
0.3771868646144867,
0.06020933389663696,
0.2310142070055008,
0.28283175826072693,
0.6497886776924133,
-0.5217083096504211,
-0.052907831966876984,
-0.6264206767082214,
0.1991995871067047,
0.7795403599739075,
-0.26187893748283386,
0.04301781579852104... | |
self._fails += 1 #for confirming effectiveness only
for key in self._keys:
if key in self._kw:
w = self._kw[key][0] + 1
self._warnSeniors(w)
self._kw[key][0] = w | [
-0.030493121594190598,
0.28765326738357544,
0.5102740526199341,
-0.12492988258600235,
0.09541147202253342,
0.36736759543418884,
0.8754003643989563,
-0.7395117282867432,
0.1034446582198143,
-0.7115190625190735,
0.34613391757011414,
0.9674862027168274,
-0.08912865072488785,
-0.16775979101657... | |
return key
return None
def _findSeniors(self):
'''this function finds the seniors, counts them and assess their age. It
is costly but unlikely.'''
seniorW = 0
seniors = 0
for w in self._kw.itervalues():
if w >= seniorW: | [
-0.1455593854188919,
0.09731020778417587,
0.4355461299419403,
-0.2267484962940216,
0.4630395472049713,
0.0768185630440712,
0.39715859293937683,
-0.495980441570282,
-0.00009044642501976341,
-0.4497586488723755,
-0.34569036960601807,
0.7100226283073425,
0.2938416004180908,
0.1092278584837913... | |
if w == seniorW:
seniors += 1
else:
seniorsW = w
seniors = 1 | [
-0.20943740010261536,
0.2035982459783554,
0.5219628214836121,
-0.28399547934532166,
0.06807304918766022,
-0.12293791770935059,
0.24600310623645782,
-0.20694123208522797,
-0.3969375491142273,
-0.32116934657096863,
-0.37330618500709534,
0.3066268563270569,
0.2739206552505493,
-0.027435356751... | |
self._seniors = seniors
self._seniorW = seniorW
def _warnSeniors(self, w):
#a weight can only be incremented...good
if w >= self._seniorW:
if w == self._seniorW:
self._seniors+=1
else: | [
0.009917076677083969,
0.38497036695480347,
0.570929765701294,
-0.4335402548313141,
0.15036600828170776,
0.03876778855919838,
0.4744395613670349,
-0.4452294707298279,
-0.2712031602859497,
-0.29682064056396484,
-0.05410633236169815,
0.6507049798965454,
0.22742250561714172,
-0.142199233174324... | |
self._seniors = 1
self._seniorW = w
def test():
#test code
iterations = 200000
size = 2500
nextkey = size
pd = ProbDict(dict([(i,[0,i]) for i in xrange(size)]))
start = time.clock()
for i in xrange(iterations):
key=pd._key()
w=pd[key][0] | [
0.1432260125875473,
0.016777634620666504,
0.2844027280807495,
-0.34889793395996094,
0.10888466238975525,
0.30816328525543213,
0.5156148076057434,
-0.5634489059448242,
-0.04743342101573944,
-0.5494022965431213,
0.12402414530515671,
0.47749006748199463,
0.16793827712535858,
0.055226732045412... | |
if random.randint(0,1+pd._seniorW-w):
#the heavier the object, the more unlikely it will be removed
pd.pop(key)
probAppend = float(500+(size-len(pd)))/1000
if random.uniform(0,1) < probAppend:
nextkey+=1
pd.append(nextkey)
print (time.clock()-start)*10... | [
-0.01329446118324995,
-0.5863069295883179,
0.32060831785202026,
-0.13282567262649536,
0.2737444043159485,
0.3704286515712738,
0.02539241500198841,
-0.5501365065574646,
-0.39629825949668884,
-0.6094638705253601,
0.01376943290233612,
0.44691020250320435,
0.03213873505592346,
0.29891857504844... | |
pd.weights()
weights.sort()
print "avg weight:", float(sum(weights))/pd._len, max(weights), pd._seniorW, pd._seniors, len(pd), len(weights)
print weights
test()
```
Any comments are still welcome. @Darius: your binary trees are too complex and complicated for me; and I do not think its leafs can be remove... | [
0.14460495114326477,
0.02128162421286106,
0.14267516136169434,
-0.05240682139992714,
-0.3153059482574463,
0.05139309540390968,
0.24876166880130768,
-0.36984679102897644,
-0.2502669394016266,
-0.5534992814064026,
-0.12981314957141876,
0.28312572836875916,
-0.3311215043067932,
-0.10250949114... | |
= random.uniform(0, weight_total)
for item, weight in items:
if n < weight:
return item
n = n - weight
return item
```
This will be slow if you have a large list of items. A binary search would probably be better in that case... but would also be more complicated to write, for litt... | [
-0.1211443617939949,
-0.21979747712612152,
0.03661595657467842,
-0.023266375064849854,
-0.18199074268341064,
0.0908656120300293,
0.02358897030353546,
-0.3770460784435272,
-0.34327203035354614,
-0.4756569564342499,
-0.11084692925214767,
0.3195747435092926,
-0.3071862459182739,
0.13725180923... | |
python](http://code.activestate.com/recipes/498229/) if you want to follow that route.
(I'd recommend doing some quick performance testing of both methods on your dataset. The performance of different approaches to this sort of algorithm is often a bit unintuitive.)
---
**Edit:** I took my own advice, since I was cu... | [
0.11381727457046509,
0.11448460072278976,
-0.22131919860839844,
-0.40473321080207825,
-0.21477985382080078,
0.2561945915222168,
0.19730909168720245,
-0.37487897276878357,
-0.574045717716217,
-0.09982619434595108,
0.05681504309177399,
0.5547436475753784,
-0.64853835105896,
-0.36488586664199... | |
return items[bisect.bisect(added_weights, random.random() * last_sum)][0]
```
*A compiling version of 1:*
```
def weighted_choice_compile(items):
"""returns a function that fetches a random item from items
items is a list of tuples in the form (item, weight)"""
weight_total = sum((item[1] for item in it... | [
-0.3307083547115326,
-0.4268830120563507,
0.1517619490623474,
-0.034827444702386856,
-0.2481900155544281,
0.354289174079895,
0.041563935577869415,
-0.458202064037323,
-0.4132896959781647,
-0.38201820850372314,
-0.423696368932724,
0.21561883389949799,
-0.31195124983787537,
-0.02172257006168... | |
return item
n = n - weight
return item
return choice
```
*A compiling version of 2:*
```
def weighted_choice_bisect_compile(items):
"""Returns a function that makes a weighted random choice from items."""
added_weights = []
last_sum = 0
for item, weight in items:
last... | [
-0.148119255900383,
-0.26951149106025696,
0.09785129129886627,
-0.16216108202934265,
-0.1806340366601944,
0.3708147704601288,
-0.19480253756046295,
-0.650157630443573,
-0.2086346596479416,
-0.3544677793979645,
-0.14429596066474915,
0.2235526740550995,
-0.3816445469856262,
-0.20344761013984... | |
def choice(rnd=random.random, bis=bisect.bisect):
return items[bis(added_weights, rnd() * last_sum)][0]
return choice
```
I then built a big list of choices like so:
```
choices = [(random.choice("abcdefg"), random.uniform(0,50)) for i in xrange(2500)]
```
And an excessively simple profiling function:
... | [
-0.06572624295949936,
-0.2627764344215393,
0.10276320576667786,
-0.18922631442546844,
-0.15791623294353485,
0.36509057879447937,
0.3073170781135559,
-0.6628190875053406,
-0.23514661192893982,
-0.7118769288063049,
0.010485799051821232,
0.8767879009246826,
-0.22455240786075592,
-0.2339272201... | |
time taken to compile the choice function once. (I timed 1,000 compiles, then divided that time by 1,000, and added the result to the choice function time.)
So: if you have a list of items+weights which change very rarely, the binary compiled method is *by far* the fastest. | [
0.20201079547405243,
-0.23152504861354828,
-0.09552499651908875,
0.07944194972515106,
-0.07807020097970963,
0.33558619022369385,
0.16496406495571136,
-0.4325631558895111,
-0.2910935878753662,
-0.7751965522766113,
0.06302593648433685,
0.39781615138053894,
0.02009308896958828,
-0.21988852322... | |
I have been getting the error "The required version of the .NET Framework is not installed on this computer." (Event Id 4096 in Event log) when trying to install a VSTO application from both a ClickOnce deployment and a local copy. This is interesting as the .NET framework is installed (on my 32bit Windows 7 PC) and th... | [
0.17673930525779724,
-0.036110926419496536,
0.3459738790988922,
-0.07264101505279541,
0.04136909171938896,
-0.2807495892047882,
0.414817750453949,
0.10297317057847977,
-0.26026982069015503,
-0.7340714931488037,
-0.11844798922538757,
0.7895144820213318,
-0.33844977617263794,
0.1729466170072... | |
on this
> computer."
>
>
> \*\*\*\*\*\*\*\*\*\*\*\*\*\* Exception Text \*\*\*\*\*\*\*\*\*\*\*\*\*\* Microsoft.VisualStudio.Tools.Applications.Deployment.InstallAddInFailedException:
> "The required version of the .NET
> Framework is not installed on this
> computer." at
> Microsoft.VisualStudio.Tools.Application... | [
0.21617059409618378,
-0.43645304441452026,
0.8092228770256042,
-0.07850934565067291,
-0.16967810690402985,
-0.15147249400615692,
0.41093501448631287,
0.5026546120643616,
-0.2881208658218384,
-0.8061919212341309,
0.05395464971661568,
0.3268932104110718,
-0.3690599501132965,
0.45662650465965... | |
If you have a property:
```
public class Fred
{
public string UserName
{
set
{
userName=value;
}
}
}
```
how do you use Rhino Mocks to check that
```
fred= new Fred();
fred.UserName="Jim";
```
is called.
```
Expect.Call(mockFred.UserName).SetPropertyWithArgument("Jim");
```
does... | [
0.6004788875579834,
0.2644502520561218,
0.19449086487293243,
0.047121889889240265,
-0.05887740105390549,
-0.05539917200803757,
0.5507206320762634,
-0.5189831256866455,
-0.0798063725233078,
-0.4805699288845062,
-0.00002836526073224377,
0.7598890662193298,
-0.19357073307037354,
0.14770449697... | |
var fredMock = mocker.DynamicMock<IFred>();
fredMock.UserName = "Name";
// the last call is actually to the set method of username
LastCall.IgnoreArguments();
mocker.ReplayAll();
fredMock.UserName = "Some Test that does this.";
mocker.VerifyAll();
}
}
public inte... | [
0.09738273173570633,
-0.1433575451374054,
0.5453051328659058,
-0.29393264651298523,
0.18479149043560028,
0.02365799993276596,
0.5194326639175415,
-0.27542510628700256,
-0.16690796613693237,
-0.2078523486852646,
-0.2703610360622406,
0.7603413462638855,
-0.30966946482658386,
0.20290353894233... | |
Is there any particular reason I should declare a class or a method final in day-to-day programming (web or otherwise)? Please provide a real-world example where it should be used.
BTW, I'm asking because I'm trying to [pick an 'obscure' keyword and master it](http://www.secretgeek.net/6min_program.asp "8 ways to be a... | [
0.5390785336494446,
-0.07796640694141388,
-0.11135976016521454,
0.14548739790916443,
-0.050916917622089386,
-0.2544665038585663,
0.4455533027648926,
0.20189446210861206,
-0.2668364644050598,
-0.4016686975955963,
-0.07388877123594284,
0.12293320149183273,
0.03795216605067253,
0.261401146650... | |
and abuse it in that manner.
**Edit**: Since an example is requested, I'll describe a case where you might find this keyword handy... say you have a class which defines how two objects may communicate with each other, say, a listener and notifier. The listener class must obviously allow inheritance, but you might want... | [
0.48287272453308105,
0.17367683351039886,
-0.05788193270564079,
0.10348564386367798,
-0.26186129450798035,
-0.2516111731529236,
0.4252251088619232,
0.013627756386995316,
-0.20006471872329712,
-0.6197974681854248,
-0.06878802925348282,
0.4348055422306061,
-0.30086034536361694,
0.07388859242... | |
sorts of crazy stuff like extend the messages and so on. If you don't want other programmers to do that, then you could make the class final. Also, this might make a lot more sense in a widely-used public API, as it also allows other programmers to readily understand which classes are ok to subclass.
Another example -... | [
0.37203720211982727,
-0.034532614052295685,
-0.25032293796539307,
0.25638967752456665,
-0.1274133324623108,
-0.38784581422805786,
0.45158448815345764,
0.11562811583280563,
-0.3452616333961487,
-0.42976731061935425,
0.009729363955557346,
0.3354838788509369,
-0.30845701694488525,
0.287896662... | |
the super's methods during processing -- and since such a class likely only contains a few methods, it's better to just make the whole thing final instead of each method. This again forces people using the class to "has-a", not "is-a", and thus, can control how you expect the code will be executed.
I would agree with ... | [
0.1800147145986557,
-0.3375839293003082,
0.27587375044822693,
0.4030326306819916,
-0.6139137148857117,
-0.20936357975006104,
0.532588005065918,
-0.03890408203005791,
-0.4480452239513397,
-0.3713907301425934,
0.02848115935921669,
0.2641662359237671,
0.0042690676636993885,
0.0427623838186264... | |
On any if you ask a question about licenses, patents or copyright everybody will refer you to the lawyer (see SO’s “ask-a-lawyer” tag). I’m trying to setup a software development process where there will be place for a lawyer. But I cannot find any well known process that includes a lawyer, what activities a he or she ... | [
0.5845212340354919,
0.28249111771583557,
0.28563299775123596,
0.4317914843559265,
0.05448637902736664,
-0.18373915553092957,
-0.08652365952730179,
-0.18919463455677032,
-0.23761866986751556,
-0.412929892539978,
-0.052525561302900314,
0.7832760810852051,
0.0225352942943573,
0.09729100018739... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.