text
stringlengths
0
30.5k
title
stringclasses
1 value
embeddings
listlengths
768
768
cluster for custom software I would be writing. I can not use something like Folding@home because I need constant contact with every part of the application. For example if I was running a simulation and one computer was controlling where rain was falling, and another controlling what my herbivores are doing in the simulation. I recently set up an OpenMPI cluster using Ubuntu. Some existing write up is at <https://wiki.ubuntu.com/MpichCluster> .
[ 0.0768163874745369, -0.29999902844429016, 0.056178610771894455, 0.109134741127491, -0.3127428889274597, 0.03131839632987976, -0.20404566824436188, 0.10093148052692413, -0.5151447057723999, -0.7618938088417053, 0.13169114291667938, -0.05502475053071976, -0.32916709780693054, 0.2524555921554...
I am working on Linux with the GCC compiler. When my C++ program crashes I would like it to automatically generate a stacktrace. My program is being run by many different users and it also runs on Linux, Windows and Macintosh (all versions are compiled using `gcc`). I would like my program to be able to generate a stack trace when it crashes and the next time the user runs it, it will ask them if it is ok to send the stack trace to me so I can track down the problem. I can handle the sending the info to me
[ 0.44981372356414795, 0.3855283260345459, 0.16102735698223114, 0.013806418515741825, 0.07898978143930435, -0.2865130305290222, -0.07293988764286041, 0.037425290793180466, -0.4191725552082062, -0.5736814141273499, 0.24531063437461853, 0.499519407749176, -0.3287982642650604, 0.273014456033706...
but I don't know how to generate the trace string. Any ideas? For Linux and I believe Mac OS X, if you're using gcc, or any compiler that uses glibc, you can use the backtrace() functions in `execinfo.h` to print a stacktrace and exit gracefully when you get a segmentation fault. Documentation can be found [in the libc manual](http://www.gnu.org/software/libc/manual/html_node/Backtraces.html). Here's an example program that installs a `SIGSEGV` handler and prints a stacktrace to `stderr` when it segfaults. The `baz()` function here causes the segfault that triggers the handler: ``` #include <stdio.h> #include <execinfo.h> #include <signal.h> #include <stdlib.h> #include <unistd.h> void handler(int sig) { void *array[10]; size_t size;
[ 0.12517252564430237, -0.39116016030311584, 0.37413349747657776, -0.1775551438331604, -0.0102503951638937, -0.2743641138076782, 0.20162689685821533, -0.4397871792316437, -0.1956418752670288, -0.8543834090232849, -0.11114183813333511, 0.5785526037216187, -0.410914808511734, -0.01375506725162...
// get void*'s for all entries on the stack size = backtrace(array, 10); // print out all the frames to stderr fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(array, size, STDERR_FILENO); exit(1); } void baz() { int *foo = (int*)-1; // make a bad pointer printf("%d\n", *foo); // causes segfault } void bar() { baz(); } void foo() { bar(); } int main(int argc, char **argv) { signal(SIGSEGV, handler); // install our handler foo(); // this will call foo, bar, and baz. baz segfaults. } ``` Compiling with `-g -rdynamic` gets you symbol
[ 0.2802104651927948, 0.08658155053853989, 0.5951806902885437, -0.364430695772171, 0.20587050914764404, 0.29667913913726807, 0.49089211225509644, -0.6106777191162109, -0.23050987720489502, -0.6942342519760132, -0.23823630809783936, 0.578347384929657, -0.5789548754692078, 0.024202553555369377...
info in your output, which glibc can use to make a nice stacktrace: ``` $ gcc -g -rdynamic ./test.c -o test ``` Executing this gets you this output: ``` $ ./test Error: signal 11: ./test(handler+0x19)[0x400911] /lib64/tls/libc.so.6[0x3a9b92e380] ./test(baz+0x14)[0x400962] ./test(bar+0xe)[0x400983] ./test(foo+0xe)[0x400993] ./test(main+0x28)[0x4009bd] /lib64/tls/libc.so.6(__libc_start_main+0xdb)[0x3a9b91c4bb] ./test[0x40086a] ``` This shows the load module, offset, and function that each frame in the stack came from. Here you can see the signal handler on top of the stack, and the libc functions before `main` in addition to `main`, `foo`, `bar`, and `baz`.
[ 0.013714471831917763, 0.014128848910331726, 0.23242603242397308, -0.02921714447438717, 0.21670381724834442, 0.08067748695611954, 0.18639548122882843, -0.19192485511302948, -0.053554438054561615, -0.6211938858032227, 0.03959041088819504, 0.4445832073688507, -0.5448482036590576, -0.111326463...
I am looking for an open-source project involving c++ GUI(s) working with a database. I have not done it before, and am looking for a way to get my feet wet. Which can I work on? How about this one <http://sourceforge.net/projects/sqlitebrowser/>: > SQLite Database browser is a light GUI editor for SQLite databases, built on top of QT. The main goal of the project is to allow non-technical users to create, modify and edit SQLite databases using a set of wizards and a spreadsheet-like interface.
[ 0.5402013659477234, 0.07045532017946243, -0.05303322523832321, 0.31290143728256226, -0.22079744935035706, -0.059411417692899704, 0.3286914527416229, 0.20904606580734253, -0.11195827275514603, -0.6604102253913879, 0.22345253825187683, 0.3527733087539673, -0.26599299907684326, -0.19638453423...
I want to set a breakpoint on the `__DoPostBack` method, but it's a pain to find the correct file to set the breakpoint in. The method `__DoPostBack` is contained in an auto-generated js file called something like: ``` ScriptResource.axd?d=P_lo2... ``` After a few post-backs visual studio gets littered with many of these files, and it's a bit of a bear to check which one the current page is referencing. Any thoughts? How about this one <http://sourceforge.net/projects/sqlitebrowser/>: > SQLite Database browser is a light GUI editor for SQLite databases, built on top of QT. The main goal of the project is to allow non-technical users to create,
[ 0.2492961287498474, 0.3466711938381195, -0.04103006795048714, 0.027363071218132973, -0.14425228536128998, -0.03849193453788757, 0.11305846273899078, 0.17388471961021423, 0.16915704309940338, -0.7715996503829956, 0.25056397914886475, 0.36194586753845215, -0.2960481643676758, 0.0699832513928...
modify and edit SQLite databases using a set of wizards and a spreadsheet-like interface.
[ 0.23909656703472137, 0.3396570384502411, -0.22182206809520721, 0.4845077097415924, -0.18451544642448425, 0.006354078650474548, -0.22917234897613525, -0.07215124368667603, 0.3858811557292938, -0.4907301068305969, -0.42582419514656067, 0.5452250242233276, -0.31999680399894714, -0.20372873544...
I would like to display multiple colors (and potentially shapes and sizes) of data points in a Google Chart scatter chart. Does anyone have an example of how to do so? I answered my own question after waiting SECONDS for an answer here :-) You can indeed have different colors for different data elements. For example: <http://chart.apis.google.com/chart?chs=300x200&cht=s&chd=t:1,2,3|6,5,4&chds=1,3,0,10&chxt=x,y&chxl=0:|0|1|2|1:|0|10&chm=d,ff0000,0,0,8,0|a,ff8080,0,1,42,0|c,ffff00,0,2,16,0> It's the chm= that does the magic. I was trying to have multiple chm= statements. You need to have just one, but with multiple descriptions separated by vertical bars.
[ 0.3942732810974121, -0.13897927105426788, 0.67738276720047, 0.21464605629444122, -0.12007570266723633, 0.2592054307460785, -0.010199503973126411, -0.11855039745569229, -0.341594934463501, -0.7010862231254578, 0.23754969239234924, 0.1837676614522934, -0.03296168893575668, 0.0952786430716514...
What are some suggestions for easy to use C++ compilers for a beginner? Free or open-source ones would be preferred. GCC is a good choice for simple things. Visual Studio Express edition is the free version of the major windows C++ compiler. If you are on Windows I would use VS. If you are on linux you should use GCC. \*I say GCC for simple things because for a more complicated project the build process isn't so easy
[ 0.2537315785884857, -0.06278761476278305, 0.014786305837333202, 0.14924663305282593, -0.6177241802215576, -0.3269968628883362, -0.008134178817272186, 0.12460362911224365, -0.22560355067253113, -0.6385695338249207, -0.08096563816070557, 0.6800240874290466, -0.5944046378135681, -0.2158907353...
Do you guys keep track of stored procedures and database schema in your source control system of choice? When you make a change (add a table, update an stored proc, how do you get the changes into source control? We use SQL Server at work, and I've begun using darcs for versioning, but I'd be curious about general strategies as well as any handy tools. *Edit:* Wow, thanks for all the great suggestions, guys! I wish I could select more than one "Accepted Answer"! We choose to script everything, and that includes all stored procedures and schema changes. No wysiwyg tools, and no
[ 0.47301551699638367, 0.009567000903189182, 0.06608680635690689, 0.25096988677978516, 0.144183948636055, -0.20339204370975494, 0.25722238421440125, 0.30135685205459595, -0.3089963495731354, -0.6287187933921814, -0.14914877712726593, 0.7226476073265076, -0.09848599880933762, -0.0695320293307...
fancy 'sync' programs are necessary. Schema changes are easy, all you need to do is create and maintain a single file for that version, including all schema and data changes. This becomes your conversion script from version x to x+1. You can then run it against a production backup and integrate that into your 'daily build' to verify that it works without errors. Note it's important not to change or delete already written schema / data loading sql as you can end up breaking any sql written later. ``` -- change #1234 ALTER TABLE asdf ADD COLUMN MyNewID INT GO -- change #5678 ALTER TABLE asdf DROP
[ 0.38633012771606445, 0.07304079830646515, 0.7054360508918762, 0.08285357058048248, -0.0216758344322443, 0.18942861258983612, 0.2136196494102478, -0.35024940967559814, 0.010252740234136581, -0.6742013692855835, -0.22442568838596344, 0.4884367883205414, -0.684699535369873, 0.0110833328217267...
COLUMN SomeOtherID GO ``` For stored procedures, we elect for a single file per sproc, and it uses the drop/create form. All stored procedures are recreated at deployment. The downside is that if a change was done outside source control, the change is lost. At the same time, that's true for any code, but your DBA'a need to be aware of this. This really stops people outside the team mucking with your stored procedures, as their changes are lost in an upgrade. Using Sql Server, the syntax looks like this: ``` if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_MyProc]') and OBJECTPROPERTY(id, N'IsProcedure') =
[ -0.09971406310796738, -0.022971853613853455, 0.44206076860427856, -0.05066715553402901, 0.022217638790607452, 0.03020661137998104, 0.036368876695632935, 0.025044726207852364, -0.11517968773841858, -0.3626306653022766, -0.17481239140033722, 0.3734442889690399, -0.24945349991321564, 0.068281...
1) drop procedure [usp_MyProc] GO CREATE PROCEDURE [usp_MyProc] ( @UserID INT ) AS SET NOCOUNT ON -- stored procedure logic. SET NOCOUNT OFF GO ``` The only thing left to do is write a utility program that collates all the individual files and creates a new file with the entire set of updates (as a single script). Do this by first adding the schema changes then recursing the directory structure and including all the stored procedure files. As an upside to scripting everything, you'll become much better at reading and writing SQL. You can also make this entire process more elaborate, but this is the basic format of
[ 0.3152381181716919, -0.007845327258110046, 0.4708837866783142, 0.006293770857155323, 0.131083682179451, -0.14808394014835358, -0.05821732059121132, -0.037539128214120865, -0.1550430953502655, -0.4839392900466919, -0.19180598855018616, 0.5965995192527771, -0.5742830634117126, -0.11034929007...
how to source-control all sql without any special software. addendum: Rick is correct that you will lose permissions on stored procedures with DROP/CREATE, so you may need to write another script will re-enable specific permissions. This permission script would be the last to run. Our experience found more issues with ALTER verses DROP/CREATE semantics. YMMV
[ 0.6955897808074951, 0.1959933340549469, 0.1764337420463562, 0.3241121172904968, 0.15156133472919464, -0.4449595510959625, 0.4063171446323395, -0.16214415431022644, 0.11848044395446777, -0.12429821491241455, 0.12310586869716644, 0.5906344056129456, -0.14316223561763763, 0.02822374366223812,...
You've just written a pile of code to deliver some important feature under pressure. You've cut a few corners, you've mashed some code into some over-bloated classes with names like SerialIndirectionShutoffManager.. You tell your boss you're going to need a week to clean this stuff up. "Clean what up?" "My code - its a pigsty!" "You mean there's some more bug fixing?" "Not really, its more like.." "You're gonna make it run faster?" "Perhaps, buts thats not.." "Then you should have written it properly when you had the chance. Now I'm glad you're here, yeah, I'm gonna have to go ahead and ask you to come in this
[ 0.9338162541389465, 0.17700661718845367, -0.11639436334371567, 0.34950387477874756, 0.34721478819847107, -0.12758325040340424, 0.334933340549469, 0.10598180443048477, -0.47541213035583496, -0.30649077892303467, 0.30089494585990906, 0.5747483372688293, -0.16129140555858612, -0.0006753097986...
weekend.. " I've read Matin Fowler's book, but I'm not sure I agree with his advice on this matter: * Encourage regular code reviews, so refactoring work is encouraged as a natural part of the development process. * Just don't tell, you're the developer and its part of your duty. Both these methods squirm out of the need to communicate with your manager. What do you tell your boss? It's important to include refactoring time in your original estimates. Going to your boss after you've delivered the product and then telling him that you're not actually done is lying about being done. You didn't actually make
[ 1.0267223119735718, -0.19401176273822784, -0.10130106657743454, 0.1034417673945427, 0.3609248995780945, -0.32027295231819153, -0.026591584086418152, 0.1260613650083542, -0.18500082194805145, -0.22694560885429382, -0.08229057490825653, 0.769925057888031, 0.46902990341186523, -0.315268456935...
the deliverable deadline. It's like a surgeon doing surgery and then not making sure he put everything back the way it was supposed to be. It is important to include all the parts of development (e.g. refactoring, usability research, testing, QA, revisions) in your original schedules. Ultimately this isn't so much a management problem as a programmer problem. If, however, you've inherited a mess then you will have to explain to the boss that the last set of programmers in a rush to get the project out the door cut corners and that it's been limping along. You can band-aid the problem
[ 0.5700294375419617, -0.15656057000160217, -0.08374782651662827, 0.1384994238615036, 0.17287610471248627, 0.3270038664340973, 0.08183776587247849, 0.05297107622027397, -0.17068533599376678, -0.6782467365264893, -0.15253975987434387, 0.6837460994720459, 0.08069875836372375, 0.049045305699110...
for awhile (as they likely did), but each band-aid just delays the problem and ultimately makes the problem that much more expensive to fix. Be honest with your boss and understand that a project isn't done until it's done.
[ 0.814421534538269, -0.058281417936086655, -0.052139852195978165, 0.15899387001991272, 0.19401858747005463, -0.2358996719121933, 0.589015543460846, 0.2874302864074707, -0.2552911937236786, -0.18696528673171997, 0.34303295612335205, 0.5016049742698669, 0.01858038268983364, -0.295112937688827...
People also often ask "How can I compile Perl?" while what they really want is to create an executable that can run on machines even if they don't have Perl installed. There are several solutions, I know of: 1. [perl2exe](http://www.indigostar.com/perl2exe.htm) of IndigoStar It is commercial. I never tried. Its web site says it can cross compile Win32, Linux, and Solaris. 2. [Perl Dev Kit](http://www.activestate.com/Products/perl_dev_kit/) from ActiveState. It is commercial. I used it several years ago on Windows and it worked well for my needs. According to its web site it works on Windows, Mac OS X, Linux, Solaris, AIX and HP-UX. 3. [PAR](http://search.cpan.org/dist/PAR/) or rather
[ 0.7110056281089783, -0.4070538878440857, 0.22560404241085052, -0.03185924515128136, -0.49222156405448914, 0.15735919773578644, -0.18550710380077362, -0.010155785828828812, -0.21817298233509064, -0.5652750730514526, 0.24207153916358948, 0.16561423242092133, -0.42551949620246887, 0.075293950...
[PAR::Packer](http://search.cpan.org/dist/PAR-Packer/) that is free and open source. Based on the test reports it works on the Windows, Mac OS X, Linux, NetBSD and Solaris but theoretically it should work on other UNIX systems as well. Recently I have started to use PAR for packaging on Linux and will use it on Windows as well. Other recommended solutions? In addition to the three tools listed in the question, there's another one called [Cava Packager](http://www.cavapackager.com/) written by Mark Dootson, who has also contributed to [PAR](http://par.perl.org) in the past. It only runs under Windows, has a nice Wx GUI and works differently from the typical three
[ 0.4187540113925934, 0.2749195098876953, -0.04550938308238983, -0.16181142628192902, -0.1050482839345932, 0.13840259611606598, -0.21020035445690155, -0.23771807551383972, -0.3078024685382843, -0.5398187637329102, 0.4002344310283661, 0.4207463562488556, -0.4323534667491913, -0.05893707275390...
contenders in that it assembles all Perl dependencies in a source / lib directory instead of creating a single archive containing everything. There's a free version, but it's not Open Source. I haven't used this except for testing. As for PAR, it's really a toolkit. It comes with a packaging tool which does the dependency scanning and assembly of stand-alone executables, but it can also be used to generate and use so-called .par files, in analogy to Java's JARs. It also comes with [client](http://search.cpan.org/dist/PAR-Repository-Client) and [server](http://search.cpan.org/dist/PAR-Repository) for automatically loading missing packages over the network, etc. The [slides of my PAR talk](http://steffen-mueller.net/talks/appdeployment/)
[ -0.3299812078475952, 0.33915042877197266, 0.1265948861837387, 0.20890654623508453, -0.47685912251472473, 0.14118695259094238, -0.0010683342115953565, -0.35261020064353943, -0.13595186173915863, -0.4042416512966156, 0.445098876953125, 0.09963949769735336, 0.1152070090174675, 0.1658714711666...
at [YAPC::EU](http://yapceurope.org/) 2008 go into more details on this. There's also an active mailing list: par at perl dot org.
[ 0.6588567495346069, 0.1651477962732315, 0.18117593228816986, -0.14401550590991974, -0.49178531765937805, 0.05353616550564766, 0.22088536620140076, 0.45131438970565796, -0.37810343503952026, -0.276007741689682, 0.017821963876485825, 0.10935449600219727, -0.10828950256109238, 0.0943097323179...
I make a lot of web applications and from time to time I need a color picker. What's one that I can use like an API and doesn't require a lot of code to plug in? I also need it to work in all browsers. [Farbtastic](http://acko.net/dev/farbtastic) is a nice jQuery color picker But apparently doesn't work in IE6 [Here](http://www.eyecon.ro/colorpicker/#about) is another jQuery color picker that looks nice, not sure about it compatibility though.
[ 0.45422521233558655, -0.4497203528881073, 0.20767587423324585, 0.07047068327665329, -0.004109987989068031, -0.16067953407764435, -0.31427615880966187, 0.2956778407096863, -0.09730662405490875, -0.6262086629867554, 0.22970177233219147, 0.6155750751495361, 0.012884380295872688, -0.0231049377...
I'm currently running Vista and I would like to manually complete the same operations as my Windows Service. Since the Windows Service is running under the Local System Account, I would like to emulate this same behavior. Basically, I would like to run CMD.EXE under the Local System Account. I found information online which suggests lauching the CMD.exe using the DOS Task Scheduler AT command, but I received a Vista warning that "due to security enhancements, this task will run at the time excepted but not interactively." Here's a sample command: ``` AT 12:00 /interactive cmd.exe ``` Another solution suggested creating a secondary Windows Service
[ 0.18685117363929749, 0.15536513924598694, 0.548213005065918, -0.1943589448928833, 0.2684016823768616, -0.38216936588287354, 0.5328986644744873, 0.21365654468536377, -0.29191070795059204, -0.881997287273407, -0.11670484393835068, 0.882853090763092, -0.0013528703711926937, 0.3540329337120056...
via the Service Control (sc.exe) which merely launches CMD.exe. ``` C:\sc create RunCMDAsLSA binpath= "cmd" type=own type=interact C:\sc start RunCMDAsLSA ``` In this case the service fails to start and results it the following error message: ``` FAILED 1053: The service did not respond to the start or control request in a timely fashion. ``` The third suggestion was to launch CMD.exe via a Scheduled Task. Though you may run scheduled tasks under various accounts, I don't believe the Local System Account is one of them. I've tried using the Runas as well, but think I'm running into the same restriction as found when running a scheduled task. Thus far,
[ -0.0098408879712224, -0.15087297558784485, 0.4952743649482727, 0.09280943125486374, -0.20502527058124542, -0.1569506973028183, 0.2499707192182541, -0.03793567791581154, -0.4369276762008667, -0.5872204303741455, -0.11966754496097565, 0.2855597734451294, -0.555274486541748, 0.253970175981521...
each of my attempts have ended in failure. Any suggestions? Though I haven't personally tested, I have good reason to believe that the above stated AT COMMAND solution will work for XP, 2000 and Server 2003. Per my and Bryant's testing, we've identified that the same approach does not work with Vista or Windows Server 2008 -- most probably due to added security and the /interactive switch being deprecated. However, I came across this [article](http://verbalprocessor.com/2007/12/05/running-a-cmd-prompt-as-local-system) which demonstrates the use of [PSTools](http://download.sysinternals.com/files/PSTools.zip) from [SysInternals](http://sysinternals.com/) (which was acquired by Microsoft in July, 2006.) I launched the command line via the following and suddenly
[ -0.0920814648270607, -0.2952006757259369, 0.5470746159553528, -0.037193965166807175, -0.25525960326194763, 0.09588021785020828, 0.528072714805603, 0.28126105666160583, 0.007806424051523209, -0.7203977108001709, -0.15912118554115295, 0.886038064956665, -0.10538891702890396, 0.20565509796142...
I was running under the Local Admin Account like magic: ``` psexec -i -s cmd.exe ``` PSTools works well. It's a lightweight, well-documented set of tools which provides an appropriate solution to my problem. Many thanks to those who offered help.
[ 0.32718074321746826, 0.23503057658672333, 0.3184933066368103, -0.020024815574288368, -0.1695667952299118, -0.09800207614898682, 0.12568888068199158, 0.4985380470752716, -0.01513324398547411, -0.8487725853919983, 0.012569863349199295, 0.40929222106933594, 0.13864022493362427, -0.07559156417...
Has anyone found a way to get gcc to build/install on SCO6? With 2.95 and 4.3 I get to the point where it needs to use (2.95) or find (4.3) the assembler and that's where it fails. If anyone has figured this out I would appreciate the info! Thanks I have came across to the same error message. After digging for a while, found out that one can supply xsd files in addition to wsdl file. So included/imported .xsd files in addition to .wsdl at the end of the wsdl command as follows: > wsdl.exe myWebService.wsdl myXsd1.xsd myType1.xsd myXsd2.xsd ... Wsdl gave some warnings but
[ 0.4427574872970581, 0.09221824258565903, 0.335720032453537, 0.03488003462553024, -0.19482269883155823, -0.2798384130001068, 0.23382890224456787, 0.11693240702152252, -0.4505890905857086, -0.8903257846832275, 0.034769207239151, 0.4449775815010071, -0.46479883790016174, 0.20280985534191132, ...
it did create an ok service interface.
[ 0.030676238238811493, 0.004066862165927887, 0.2700190544128418, 0.10707980394363403, -0.15655343234539032, -0.14833560585975647, 0.35669878125190735, 0.36740386486053467, 0.04078703373670578, -0.28490278124809265, 0.17903681099414825, 0.16806817054748535, 0.03139353543519974, -0.0527930632...
We are developing automated regression tests using VMWare and NUnit. We have divided tests into steps and now I would like to see each step be examined for performance regression. Simply timing the tests, as NUnit does, does not seem reliable. I have figured in a acceptance factor of about 15% but our steps can differ sometimes to over 35%. In such a resource dependent test environment is there any consistent way of testing performance? Is a "smart" timing system my only option? For this sort of performance testing, there's no such thing as a system that will give you a
[ 0.378135085105896, -0.041445937007665634, -0.06983232498168945, 0.4277796447277069, -0.02479480765759945, -0.08152821660041809, 0.31253287196159363, -0.22444447875022888, 0.059485189616680145, -0.3578439950942993, 0.4335050880908966, 0.591823935508728, 0.10393860936164856, -0.1354529559612...
simple pass/fail result. In real life, changing your system is likely to make some things faster and some other things slower, so it's usually not a choice between "better" and "not better", it's a choice between different kinds of better. (Of course, you want to avoid cases where it's strictly worse.) What I've done for this in the past is to just keep statistics over time. Every time you run your tests, drop the results in a SQL database with the revision number and the test timings. Then you can graph them whenever and however you want (ideally in a little
[ 0.3838593065738678, -0.1339586079120636, -0.05420387536287308, 0.42619824409484863, -0.0182026419788599, 0.06428629904985428, 0.5195152759552002, -0.044991206377744675, -0.2875193655490875, -0.7017309665679932, 0.39701151847839355, 0.31277188658714294, 0.0063960314728319645, -0.17535410821...
web applet so everyone on the team can review them) and see if your performance is trending up or down, or if performance has been sucking ever since a particular revision. The key thing here, though, is that it needs to be a *graph*. That way human eyes can look at it and find the trends. You could spend all week trying to come up with an AI algorithm to analyse the data numerically, but it would never beat a human's pattern-recognition ability.
[ 0.4773293137550354, -0.1461636871099472, 0.2958393692970276, 0.49523603916168213, -0.1858786940574646, -0.22904571890830994, 0.39687296748161316, 0.36547672748565674, -0.5414906740188599, -0.939443826675415, 0.17591913044452667, 0.33300670981407166, -0.039148714393377304, -0.11922513693571...
I thought I'd offer this softball to whomever would like to hit it out of the park. What are generics, what are the advantages of generics, why, where, how should I use them? Please keep it fairly basic. Thanks. * Allows you to write code/use library methods which are type-safe, i.e. a List<string> is guaranteed to be a list of strings. * As a result of generics being used the compiler can perform compile-time checks on code for type safety, i.e. are you trying to put an int into that list of strings? Using an ArrayList would cause that to be a
[ 0.44965025782585144, -0.12261427193880081, -0.10657591372728348, 0.3410564064979553, -0.4229709208011627, -0.19959434866905212, 0.4824284613132477, 0.1985395848751068, -0.1737162470817566, -0.5774385333061218, 0.31595462560653687, 0.5853890180587769, -0.2774530351161957, -0.016558652743697...
less transparent runtime error. * Faster than using objects as it either avoids boxing/unboxing (where .net has to convert [value types to reference types or vice-versa](https://stackoverflow.com/questions/5057267/what-is-the-difference-between-a-reference-type-and-value-type-in-c)) or casting from objects to the required reference type. * Allows you to write code which is applicable to many types with the same underlying behaviour, i.e. a Dictionary<string, int> uses the same underlying code as a Dictionary<DateTime, double>; using generics, the framework team only had to write one piece of code to achieve both results with the aforementioned advantages too.
[ 0.17153675854206085, -0.19840727746486664, 0.05721600353717804, 0.1303318738937378, -0.5587989687919617, -0.0039163436740636826, 0.4872293472290039, -0.3938124477863312, -0.1262943297624588, -0.7757731676101685, -0.04773009195923805, 0.5679198503494263, -0.2770232856273651, -0.126797527074...
I really like Xml for saving data, but when does sqlite/database become the better option? eg, when the xml has more than *x* items or is greater than *y* MB? I am coding an rss reader and I believe I made the wrong choice in using xml over a sqlite database to store a cache of *all* the feeds items. There are some feeds which have an xml file of ~1mb after a month, another has over 700 items, while most only have ~30 items and are ~50kb in size after a *several* months. I currently have no plans to implement
[ 0.770309329032898, 0.027900397777557373, 0.30204668641090393, 0.11835004389286041, -0.19936367869377136, -0.18609493970870972, 0.127341628074646, 0.0635223239660263, -0.24707113206386566, -0.7102347016334534, 0.14040516316890717, 0.3514569401741028, -0.23628339171409607, 0.0740627944469451...
a cap because I like to be able to search through everything. So, my questions are: 1. When is the overhead of sqlite/databases justified over using xml? 2. Are the **few large xml files** justification enough for the database when there are **a lot of small** ones, though even the small ones will grow over time? (a long *long* time) **updated** (more info) Every time a feed is selected in the GUI I reload all the items from that feeds xml file. I also need to modify the read/unread status which seems really hacky when I loop through all nodes in the xml to find the
[ 0.6775518655776978, -0.13456688821315765, 0.4979148209095001, 0.31273123621940613, -0.012879017740488052, -0.39591848850250244, -0.36529475450515747, -0.3033216595649719, -0.4693388342857361, -0.7364345192909241, 0.4723879396915436, 0.7892271876335144, -0.35781896114349365, 0.0774014443159...
item and then set it to read/unread. I basically agree with [Mitchel](https://stackoverflow.com/questions/77726/xml-or-sqlite-when-to-drop-xml-for-a-database#77750), that this can be highly specific depending on what are you going to do with XML and SQLite. For your case (cache), it seems to me that using SQLite (or other embedded databases) makes more sense. First I don't really think that SQLite will need more overhead than XML. And I mean both development time overhead and runtime overhead. Only problem is that you have a dependence on SQLite library. But since you would need some library for XML anyway it doesn't matter (I assume project is in C/C++). **Advantages of
[ 0.3152131736278534, -0.04155492037534714, 0.336978018283844, 0.20912091434001923, -0.06459866464138031, -0.18848159909248352, 0.018299154937267303, -0.2885092794895172, -0.33229729533195496, -0.5909878611564636, -0.15930013358592987, 0.6113763451576233, -0.05474056303501129, 0.002040705177...
SQLite over XML:** * everything in one file, * performance loss is lower than XML as cache gets bigger, * you can keep feed metadata separate from cache itself (other table), but accessible in the same way, * SQL is probably easier to work with than XPath for most people. **Disadvantages of SQLite:** * can be problematic with multiple processes accessing same database (probably not your case), * you should know at least basic SQL. Unless there will be hundreds of thousands of items in cache, I don't think you will need to optimize it much, * maybe in some way it can be more dangerous from security
[ 0.39902418851852417, 0.18211670219898224, 0.24037843942642212, 0.2688772678375244, -0.3616176247596741, -0.446135550737381, 0.15335024893283844, -0.035145100206136703, -0.19838477671146393, -0.6756036281585693, 0.14696566760540009, 0.5817521214485168, -0.3640294075012207, 0.107045061886310...
standpoint (SQL injection). On the other hand, you are not coding web app, so this should not happen. Other things are on par for both solutions probably. To sum it up, answers to your questions respectively: 1. You will not know, unless you test your specific application with both back ends. Otherwise it's always just a guess. Basic support for both caches should not be a problem to code. Then benchmark and compare. 2. Because of the way XML files are organized, SQLite searches should always be faster (barring some corner cases where it doesn't matter anyway because it's blazingly fast). Speeding up searches
[ 0.44210147857666016, 0.0075072324834764, -0.016374768689274788, 0.4663325846195221, -0.14188773930072784, -0.4219105541706085, 0.00627003563567996, -0.35512393712997437, -0.010140429250895977, -0.5025994777679443, 0.08106956630945206, 0.5741042494773865, -0.18601259589195251, -0.2017004489...
in XML would require index database anyway, in your case that would mean having cache for cache, not a particularly good idea. But with SQLite you can have indexing as part of database.
[ 0.07382936775684357, 0.21240603923797607, 0.3228050172328949, 0.35437896847724915, -0.3105234205722809, -0.4319468140602112, -0.24307042360305786, -0.02889431267976761, -0.1975604146718979, -0.6371349692344666, 0.09814636409282684, 0.21265509724617004, -0.3671950399875641, 0.05278765782713...
At my current gig, we use iBATIS through Java to CRUD our databases. I like the abstract qualities of the tool, especially when working with legacy databases, as it doesn't impose its own syntax on you. **I'm looking for a Python analogue to this library**, since the website only has Java/.NET/Ruby versions available. I don't want to have to switch to Jython if I don't need to. Are there any other projects similar to iBATIS functionality out there for Python? iBatis sequesters the SQL DML (or the definitions of the SQL) in an XML file. It specifically focuses on the mapping between the
[ 0.3669084310531616, 0.07591068744659424, 0.16356973350048065, -0.05702647939324379, -0.23956479132175446, 0.05562626197934151, -0.11778199672698975, 0.09246986359357834, -0.04068858548998833, -0.6169896125793457, 0.10271275043487549, 0.40613749623298645, -0.08927972614765167, 0.00907555874...
SQL and some object model defined elsewhere. SQL Alchemy can do this -- but it isn't really a very complete solution. Like iBatis, you can merely have SQL table definitions and a mapping between the tables and Python class definitions. What's more complete is to have a class definition that is *also* the SQL database definition. If the class definition generates the SQL Table DDL as well as the query and processing DML, that's much more complete. I flip-flop between SQLAlchemy and the Django ORM. SQLAlchemy can be used in an iBatis like manner. But I prefer to make the object
[ 0.12502050399780273, 0.09906521439552307, 0.16756673157215118, 0.3441236615180969, -0.2883746027946472, -0.1992821991443634, -0.23532405495643616, -0.04869486019015312, 0.10033165663480759, -0.5276790857315063, 0.07809728384017944, 0.530852198600769, -0.421850323677063, 0.1788836419582367,...
design central and leave the SQL implementation be derived from the objects by the toolset. I use SQLAlchemy for large, batch, stand-alone projects. DB Loads, schema conversions, DW reporting and the like work out well. In these projects, the focus is on the relational view of the data, not the object model. The SQL that's generated may be moved into PL/SQL stored procedures, for example. I use Django for web applications, exploiting its built-in ORM capabilities. You can, with a little work, segregate the Django ORM from the rest of the Django environment. You can [provide global settings](http://docs.djangoproject.com/en/dev/topics/settings/#using-settings-without-setting-django-settings-module) to bind your app
[ 0.46261247992515564, 0.4965146780014038, 0.1354367434978485, -0.07478416711091995, -0.37536537647247314, -0.13407759368419647, -0.07244820147752762, 0.020920369774103165, 0.004610143601894379, -0.6714170575141907, 0.022838616743683815, 0.5336335301399231, -0.24113145470619202, 0.2840315401...
to a specific database without using a separate settings module. Django includes a number of common relationships (Foreign Key, Many-to-Many, One-to-One) for which it can manage the SQL implementation. It generates key and index definitions for the attached database. If your problem is largely object-oriented, with the database being used for persistence, then the nearly transparent ORM layer of Django has advantages. If your problem is largely relational, with the SQL processing central, then the capability of seeing the generated SQL in SQLAlchemy has advantages.
[ 0.035522978752851486, 0.27563098073005676, 0.17934352159500122, 0.1758735328912735, -0.3203440010547638, -0.3126524090766907, -0.0858415737748146, -0.05191568657755852, -0.15698471665382385, -0.4737713634967804, -0.019053896889090538, 0.6569843292236328, -0.2130088061094284, -0.22025306522...
How do you get Perl to stop and give a stack trace when you reference an undef value, rather than merely warning? It seems that `use strict;` isn't sufficient for this purpose. ``` use warnings FATAL => 'uninitialized'; use Carp (); $SIG{__DIE__} = \&Carp::confess; ``` The first line makes the warning fatal. The next two cause a stack trace when your program dies. See also `man 3pm warnings` for more details.
[ 0.24915067851543427, 0.10354816913604736, 0.24987487494945526, -0.03995262831449509, 0.12021996825933456, -0.2992115318775177, 0.6950753927230835, -0.03453021124005318, -0.31309589743614197, -0.2822643220424652, -0.17850303649902344, 0.47825708985328674, -0.4856123626232147, 0.166607439517...
The Matrix in SSRS (SQL Server Reporting Services 2005) seems to have issues with certain the border styles when exporting to XLS (but not PDF or web view; maybe other formats, not sure?). For example: Create a matrix and set the Matrix border style to Black Solid 1px, but all 4 of the cells to have a border style of Black None 1px. When viewed via the ASP.NET control, it looks correct. But after export to XLS, it creates borders around all of the header cells (column and row headers, and the top left cell), and even the right most data
[ -0.010433411225676537, -0.16216757893562317, 0.5688969492912292, 0.008363397791981697, -0.20012874901294708, -0.06011150777339935, 0.1475924402475357, -0.38194724917411804, -0.6081017255783081, -0.35507550835609436, -0.015868034213781357, 0.262681782245636, -0.5493060946464539, -0.05904339...
column. But all the cells in the middle of the report correctly have no border set. Update: If the Matrix borders are set to None, then the borders on the cells don't show up in XLS. So, how do you set an outer border around the Matrix, but not have it apply the 'all sides' border to every cell that touches the edge of the Matrix when exported to Excel? This seems to be a bug in SSRS 2005 Excel rendering. I've been able to fix this by explicitly setting all sides of the matrix BorderStyle property (Left, Right, Top, Bottom) to Solid. Also,
[ 0.0614323690533638, -0.028928261250257492, 0.6372082233428955, -0.056153636425733566, -0.18631620705127716, 0.017917994409799576, -0.06793984025716782, -0.41068002581596375, -0.32394883036613464, -0.602350652217865, 0.204118549823761, 0.4097118079662323, -0.25821200013160706, -0.0226865354...
when you do this, it seems like setting the BorderStyle.Default property to Solid or None doesn't matter. The value explicitly set for the other sides overrides that Default value.
[ 0.4574401378631592, -0.2726895809173584, 0.35754910111427307, 0.17009460926055908, 0.3228275179862976, -0.4550776481628418, 0.25807464122772217, -0.3832511305809021, -0.1901804655790329, -0.47550392150878906, 0.06749771535396576, 0.7371183037757874, -0.10994336754083633, -0.090442128479480...
I'm working on an embedded Linux project that interfaces an ARM9 to a hardware video encoder chip, and writes the video out to SD card or USB stick. The software architecture involves a kernel driver that reads data into a pool of buffers, and a userland app that writes the data to a file on the mounted removable device. I am finding that above a certain data rate (around 750kbyte/sec) I start to see the userland video-writing app stalling for maybe half a second, about every 5 seconds. This is enough to cause the kernel driver to run out of buffers
[ 0.23694564402103424, 0.06581039726734161, 0.5704873204231262, 0.38222816586494446, 0.15489038825035095, -0.009318952448666096, -0.18646878004074097, 0.048117585480213165, -0.06257450580596924, -0.6274766325950623, 0.014919640496373177, 0.7195717096328735, 0.08067420870065689, 0.10462969541...
- and even if I could increase the number of buffers, the video data has to be synchronised (ideally within 40ms) with other things that are going on in real time. Between these 5 second "lag spikes", the writes complete well within 40ms (as far as the app is concerned - I appreciate they're buffered by the OS) I think this lag spike is to do with the way Linux is flushing data out to disk - I note that pdflush is designed to wake up every 5s, my understanding is that this would be what does the writing. As soon
[ 0.017043521627783775, -0.06749657541513443, 1.0955101251602173, 0.2595932185649872, 0.07854980230331421, -0.3486986756324768, 0.49992427229881287, -0.02841504104435444, -0.055054157972335815, -0.7448933124542236, -0.20608478784561157, 0.6437863707542419, 0.050821755081415176, -0.0421953126...
as the stall is over the userland app is able to quickly service and write the backlog of buffers (that didn't overflow). I think the device I'm writing to has reasonable ultimate throughput: copying a 15MB file from a memory fs and waiting for sync to complete (and the usb stick's light to stop flashing) gave me a write speed of around 2.7MBytes/sec. I'm looking for two kinds of clues: 1. How can I stop the bursty writing from stalling my app - perhaps process priorities, realtime patches, or tuning the filesystem code to write continuously rather than burstily? 2. How can I make
[ 0.1967313140630722, -0.02230122685432434, 0.6374180316925049, 0.28475427627563477, 0.05489866062998772, 0.18266649544239044, 0.44560736417770386, -0.022965168580412865, -0.13491378724575043, -0.7206116914749146, 0.23387344181537628, 0.6830559968948364, 0.17741747200489044, -0.0945405438542...
my app(s) aware of what is going on with the filesystem in terms of write backlog and throughput to the card/stick? I have the ability to change the video bitrate in the hardware codec on the fly which would be much better than dropping frames, or imposing an artificial cap on maximum allowed bitrate. Some more info: this is a 200MHz ARM9 currently running a Montavista 2.6.10-based kernel. Updates:* Mounting the filesystem SYNC causes throughput to be much too poor. * The removable media is FAT/FAT32 formatted and must be as the purpose of the design is that the media can be plugged
[ 0.29130440950393677, 0.06812325865030289, 0.8838914036750793, 0.35023805499076843, 0.09771481156349182, -0.09068011492490768, 0.18267278373241425, -0.08180572837591171, -0.28850501775741577, -0.6622319221496582, -0.06266986578702927, 1.0273219347000122, -0.23704257607460022, -0.00947866588...
into any Windows PC and read. * Regularly calling sync() or fsync() say, every second causes regular stalls and unacceptably poor throughput * I am using write() and open(O\_WRONLY | O\_CREAT | O\_TRUNC) rather than fopen() etc. * I can't immediately find anything online about the mentioned "Linux realtime filesystems". Links? I hope this makes sense. First embedded Linux question on stackoverflow? :) For the record, there turned out to be two main aspects that seem to have eliminated the problem in all but the most extreme cases. This system is still in development and hasn't been thoroughly torture-tested yet but is working fairly well
[ 0.19996950030326843, -0.05496453866362572, 0.31511178612709045, -0.11145211011171341, 0.1561264842748642, -0.3204037845134735, 0.45011505484580994, 0.2973628342151642, -0.15825682878494263, -0.7577387094497681, -0.34620732069015503, 0.7213967442512512, -0.14884960651397705, 0.1768020391464...
(touch wood). The big win came from making the userland writer app multi-threaded. It is the calls to write() that block sometimes: other processes and threads still run. So long as I have a thread servicing the device driver and updating frame counts and other data to sychronise with other apps that are running, the data can be buffered and written out a few seconds later without breaking any deadlines. I tried a simple ping-pong double buffer first but that wasn't enough; small buffers would be overwhelmed and big ones just caused bigger pauses while the filesystem digested the writes. A
[ -0.08062267303466797, 0.22246329486370087, 0.46061670780181885, -0.08500780165195465, 0.0665803849697113, 0.040714770555496216, 0.2928236424922943, -0.27415037155151367, -0.41380420327186584, -0.40560027956962585, 0.29080668091773987, 0.602631688117981, -0.19625328481197357, -0.08628921210...
pool of 10 1MB buffers queued between threads is working well now. The other aspect is keeping an eye on ultimate write throughput to physical media. For this I am keeping an eye on the stat Dirty: reported by /proc/meminfo. I have some rough and ready code to throttle the encoder if Dirty: climbs above a certain threshold, seems to vaguely work. More testing and tuning needed later. Fortunately I have lots of RAM (128M) to play with giving me a few seconds to see my backlog building up and throttle down smoothly. I'll try to remember to pop back and update
[ 0.3039957582950592, 0.1341419219970703, 0.49645304679870605, 0.10909082740545273, 0.06538854539394379, 0.18142364919185638, 0.3539208471775055, -0.004325029440224171, -0.5678907036781311, -0.8290014863014221, 0.2404927760362625, 0.6116393804550171, 0.147725909948349, -0.202890083193779, ...
this answer if I find I need to do anything else to deal with this issue. Thanks to the other answerers.
[ 0.2778675854206085, 0.19603528082370758, 0.3167208433151245, 0.4641939401626587, -0.29105478525161743, 0.020085914060473442, 0.39542272686958313, 0.28166723251342773, -0.12857994437217712, -0.6684800386428833, -0.12148987501859665, 0.4263607859611511, 0.010063781403005123, 0.10729826986789...
In a C++ app, I have an hWnd pointing to a window running in a third party process. This window contains controls which extend the COM TreeView control. I am interested in obtaining the CheckState of this control. I use the hWnd to get an HTREEITEM using TreeView\_GetRoot(hwnd) from commctrl.h hwnd points to the window and hItem is return value from TreeView\_GetRoot(hwnd). They are used as follows: ``` int iCheckState = TreeView_GetCheckState(hwnd, hItem); switch (iCheckState) { case 0: // (unchecked) case 1: // checked ... } ``` I'm looking to
[ 0.01290684100240469, 0.1515744924545288, 0.4964701533317566, -0.13536058366298676, 0.16216984391212463, 0.06050752475857735, 0.17015232145786285, -0.28233999013900757, 0.13091784715652466, -0.7879257798194885, -0.35413289070129395, 0.6741420030593872, -0.40755680203437805, -0.1652874499559...
port this code into a C# app which does the same thing (switches off the CheckState of the TreeView control). I have never used COM and am quite unfamiliar. I have tried using the .NET mscomctl but can't find equivalent methods to TreeView\_GetRoot or TreeView\_GetCheckState. I'm totally stuck and don't know how to recreate this code in C# :( Suggestions? We have these definitions from CommCtrl.h: ``` #define TreeView_SetItemState(hwndTV, hti, data, _mask) \ { TVITEM _ms_TVi;\ _ms_TVi.mask = TVIF_STATE; \ _ms_TVi.hItem = (hti); \ _ms_TVi.stateMask = (_mask);\ _ms_TVi.state = (data);\ SNDMSG((hwndTV), TVM_SETITEM, 0, (LPARAM)(TV_ITEM *)&_ms_TVi);\ } #define TreeView_SetCheckState(hwndTV, hti, fCheck) \ TreeView_SetItemState(hwndTV,
[ 0.1533401906490326, -0.1952485293149948, 0.8040089011192322, -0.03147565573453903, 0.0700104832649231, -0.11541319638490677, 0.6086498498916626, -0.22677917778491974, -0.11354333907365799, -1.0198322534561157, -0.17357318103313446, 0.7104241847991943, -0.44008952379226685, 0.19054971635341...
hti, INDEXTOSTATEIMAGEMASK((fCheck)?2:1), TVIS_STATEIMAGEMASK) ``` We can translate this to C# using PInvoke. First, we implement these macros as functions, and then add whatever other support is needed to make those functions work. Here is my first shot at it. You should double check my code especially when it comes to the marshalling of the struct. Further, you may want to Post the message cross-thread instead of calling SendMessage. Lastly, I am not sure if this will work at all since I believe that the common controls use WM\_USER+ messages. When these messages are sent cross-process, the data parameter's addresses are unmodified and the resulting process may cause an
[ 0.22278578579425812, -0.16990698873996735, 0.544979989528656, -0.049390073865652084, -0.08595163375139236, -0.1269959956407547, 0.09066257625818253, -0.3629176914691925, 0.016972217708826065, -0.7776177525520325, -0.0825725570321083, 0.6721616983413696, -0.6283409595489502, 0.0833383798599...
Access Violation. This would be a problem in whatever language you use (C++ or C#), so perhaps I am wrong here (you say you have a working C++ program). ``` static class Interop { public static IntPtr TreeView_SetCheckState(HandleRef hwndTV, IntPtr hti, bool fCheck) { return TreeView_SetItemState(hwndTV, hti, INDEXTOSTATEIMAGEMASK((fCheck) ? 2 : 1), (uint)TVIS.TVIS_STATEIMAGEMASK); } public static IntPtr TreeView_SetItemState(HandleRef hwndTV, IntPtr hti, uint data, uint _mask) { TVITEM _ms_TVi = new TVITEM(); _ms_TVi.mask = (uint)TVIF.TVIF_STATE; _ms_TVi.hItem = (hti); _ms_TVi.stateMask = (_mask); _ms_TVi.state = (data); IntPtr p
[ -0.05391157791018486, -0.03775344789028168, 0.6012770533561707, 0.10818003863096237, 0.2028583437204361, -0.10857583582401276, 0.5119307637214661, -0.2915073037147522, -0.3816753327846527, -0.49051228165626526, -0.5505300164222717, 0.6834498643875122, -0.4620334804058075, 0.312509775161743...
= Marshal.AllocCoTaskMem(Marshal.SizeOf(_ms_TVi)); Marshal.StructureToPtr(_ms_TVi, p, false); IntPtr r = SendMessage(hwndTV, (int)TVM.TVM_SETITEMW, IntPtr.Zero, p); Marshal.FreeCoTaskMem(p); return r; } private static uint INDEXTOSTATEIMAGEMASK(int i) { return ((uint)(i) << 12); } [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam); private enum TVIF : uint { TVIF_STATE = 0x0008 } private enum TVIS : uint { TVIS_STATEIMAGEMASK = 0xF000 } private enum TVM : int { TV_FIRST = 0x1100, TVM_SETITEMA = (TV_FIRST + 13), TVM_SETITEMW = (TV_FIRST + 63) } private
[ 0.05667198449373245, -0.28173932433128357, 0.6532567143440247, 0.10085776448249817, 0.09741147607564926, -0.012573609128594398, 0.43404078483581543, -0.988090991973877, -0.36314213275909424, -0.3923485279083252, -0.38706114888191223, 0.6095210909843445, -0.24788935482501984, 0.203440248966...
struct TVITEM { public uint mask; public IntPtr hItem; public uint state; public uint stateMask; public IntPtr pszText; public int cchTextMax; public int iImage; public int iSelectedImage; public int cChildren; public IntPtr lParam; } } ```
[ 0.17484687268733978, -0.3633618652820587, 0.6923686265945435, 0.035273585468530655, -0.139346182346344, 0.15942569077014923, 0.4934934973716736, -0.21558508276939392, -0.00842189509421587, -0.831725537776947, -0.7074007987976074, 0.5502575635910034, -0.569326639175415, -0.08171182870864868...
In the C programming language and Pthreads as the threading library; do variables/structures that are shared between threads need to be declared as volatile? Assuming that they might be protected by a lock or not (barriers perhaps). Does the pthread POSIX standard have any say about this, is this compiler-dependent or neither? Edit to add: Thanks for the great answers. But what if you're *not* using locks; what if you're using [barriers](http://en.wikipedia.org/wiki/Barrier_(computer_science)) for example? Or code that uses primitives such as [compare-and-swap](http://en.wikipedia.org/wiki/Compare_and_swap) to directly and atomically modify a shared variable... I think one very important property of volatile is that it makes the
[ 0.15416687726974487, 0.2093295305967331, -0.10743702203035355, 0.2756524384021759, 0.11590280383825302, -0.40021803975105286, -0.17385774850845337, -0.16545464098453522, -0.33852723240852356, -0.28710997104644775, -0.15870004892349243, 0.5889378190040588, -0.30315282940864563, 0.1519879698...
variable be written to memory when modified, and reread from memory each time it accessed. The other answers here mix volatile and synchronization, and it is clear from some other answers than this that volatile is NOT a sync primitive (credit where credit is due). But unless you use volatile, the compiler is free to cache the shared data in a register for any length of time... if you want your data to be written to be predictably written to actual memory and not just cached in a register by the compiler at its discretion, you will need to mark
[ 0.1677100658416748, -0.015983212739229202, 0.04219996556639671, 0.2632160186767578, -0.09699676930904388, 0.012173977680504322, 0.08072857558727264, 0.05461841821670532, -0.0714552029967308, -0.011550426483154297, 0.11241047829389572, 0.6817059516906738, -0.2460482120513916, 0.214274719357...
it as volatile. Alternatively, if you only access the shared data after you have left a function modifying it, you might be fine. But I would suggest not relying on blind luck to make sure that values are written back from registers to memory. Especially on register-rich machines (i.e., not x86), variables can live for quite long periods in registers, and a good compiler can cache even parts of structures or entire structures in registers. So you should use volatile, but for performance, also copy values to local variables for computation and then do an explicit write-back. Essentially, using volatile
[ -0.09390760958194733, 0.08760984241962433, 0.1194685772061348, 0.2950115203857422, -0.08742640167474747, -0.40186402201652527, 0.21904514729976654, 0.1587686389684677, -0.2558539807796478, -0.2878165543079376, -0.2109861522912979, 0.6812952160835266, -0.15884505212306976, 0.114258021116256...
efficiently means doing a bit of load-store thinking in your C code. In any case, you positively have to use some kind of OS-level provided sync mechanism to create a correct program. For an example of the weakness of volatile, see my Decker's algorithm example at <http://jakob.engbloms.se/archives/65>, which proves pretty well that volatile does not work to synchronize.
[ -0.2287628948688507, 0.22942909598350525, 0.05271263048052788, 0.28331801295280457, -0.0005614506080746651, -0.42956194281578064, 0.3129235804080963, -0.18649087846279144, -0.3019788861274719, -0.7332212328910828, -0.20377902686595917, 0.4954277276992798, -0.44803041219711304, -0.241684436...
If I am given a `MemoryStream` that I know has been populated with a `String`, how do I get a `String` back out? This sample shows how to read and write a string to a MemoryStream. --- ``` Imports System.IO Module Module1 Sub Main() ' We don't need to dispose any of the MemoryStream ' because it is a managed object. However, just for ' good practice, we'll close the MemoryStream. Using ms As New MemoryStream Dim sw As New StreamWriter(ms)
[ 0.07205299288034439, -0.1415233314037323, 0.7621781229972839, 0.005115889012813568, 0.1456720232963562, -0.2246960699558258, 0.16154025495052338, -0.061691801995038986, -0.12278217822313309, -0.5959758162498474, -0.07048039138317108, 0.7442046999931335, -0.20448032021522522, 0.351054728031...
sw.WriteLine("Hello World") ' The string is currently stored in the ' StreamWriters buffer. Flushing the stream will ' force the string into the MemoryStream. sw.Flush() ' If we dispose the StreamWriter now, it will close ' the BaseStream (which is our MemoryStream) which ' will prevent us from reading from our MemoryStream 'sw.Dispose()
[ -0.049736201763153076, -0.1981571763753891, 0.8054068088531494, -0.2683583199977875, 0.422254741191864, -0.22047752141952515, 0.47882771492004395, -0.005838490556925535, 0.10792997479438782, -0.6875043511390686, -0.17325997352600098, 0.3115541934967041, -0.26637592911720276, 0.369819432497...
' The StreamReader will read from the current ' position of the MemoryStream which is currently ' set at the end of the string we just wrote to it. ' We need to set the position to 0 in order to read ' from the beginning. ms.Position = 0 Dim sr As New StreamReader(ms) Dim myStr =
[ -0.05663815513253212, -0.46474170684814453, 1.0235658884048462, -0.047176115214824677, 0.11476819962263107, 0.09316373616456985, 0.30660098791122437, 0.03711681813001633, -0.07467560470104218, -0.5339763760566711, -0.29632702469825745, 0.5250805020332336, -0.08686189353466034, 0.4487369954...
sr.ReadToEnd() Console.WriteLine(myStr) ' We can dispose our StreamWriter and StreamReader ' now, though this isn't necessary (they don't hold ' any resources open on their own). sw.Dispose() sr.Dispose() End Using Console.WriteLine("Press any key to continue.") Console.ReadKey() End Sub End Module ```
[ -0.0812954530119896, 0.011427240446209908, 0.7223039865493774, -0.23418711125850677, 0.32627665996551514, -0.3528948724269867, 0.31158316135406494, -0.2709476947784424, 0.023403409868478775, -0.6744876503944397, -0.4192827641963959, 0.45245853066444397, -0.01872968301177025, 0.285177469253...
How would you implement a system with the following objectives: * Manage authentication, authorization for **hundreds of thousands** of *existing users* currently tightly integrated with a 3rd party vendor's application (We want to bust these users out into something we manage and make our apps work against it, plus our 3rd party vendors work against it). * Manage profile information linked to those users * Must be able to be accessed from any number of web applications on just about any platform (Windows, \*nix, PHP, ASP/C#, Python/Django, et cetera). Here some sample implementations: * LDAP/AD Server to manage everything. Use custom schema for all profile data. Everything
[ 0.48612117767333984, -0.09177685528993607, 0.10593977570533752, 0.37287524342536926, -0.007412956096231937, -0.29903918504714966, 0.1500624269247055, -0.1580188274383545, -0.2678602933883667, -0.6613234281539917, -0.10854946821928024, 0.4098888039588928, -0.3938933312892914, -0.15037640929...
can authenticate against LDAP/AD and we can store all sorts of ACLs and profile data in a custom schema. * Use LDAP/AD for authentication only, tie LDAP users to a most robust profile/authorization server using some sort of traditional database (MSSQL/PostgreSQL/MySQL) or document based DB (CouchDB, SimpleDB, et cetera). Use LDAP for authorization, then hit the DB for more advanced stuff. * Use a traditional database (Relational or Document) for everything. Are any of these three the best? Are there other solutions which fit the objectives above and are easier to implement? \*\* I should add that almost all applications that will be authenticating
[ 0.2559308409690857, -0.04549649357795715, 0.49850961565971375, 0.29681628942489624, -0.1717054843902588, -0.5208410024642944, 0.23996268212795258, -0.4150162935256958, 0.31676608324050903, -0.5281485915184021, -0.04265240952372551, 0.6622817516326904, -0.4010814428329468, -0.23194520175457...
against the user database will be under our control. The lone few outsiders will be the applications we're removing the current user database from and perhaps 1 or 2 others. Nothing so broad as to need an openID server. Its also important to know that a lot of these users have had these accounts for 5-8 years and know their logins and passwords, et cetera. There is a difference between authentication and authorization/profiling so don't force both necessarily into a single tool. Your second solution of using LDAP for authentication and a DB for authorization seems more robust as the LDAP data
[ 0.18860386312007904, 0.0007394655258394778, 0.06171467900276184, 0.179623544216156, -0.23610761761665344, -0.34560927748680115, 0.20065410435199738, -0.2633609473705292, 0.015652893111109734, -0.3343568444252014, 0.14772209525108337, 0.6943657994270325, -0.2642635107040405, 0.1812088787555...
is controlled by the user and the DB would be controlled by an admin. The latter would likely morph in structure and complexity over time, but authentication is just that authentication. Separation of these functions will prove more manageable.
[ 0.1871313601732254, 0.19636690616607666, 0.17664770781993866, 0.1883573830127716, -0.22628657519817352, -0.1345396786928177, 0.41433829069137573, -0.511278510093689, 0.3942062258720398, -0.2878130376338959, -0.5966225862503052, 0.5058799982070923, -0.2306298315525055, 0.07600193470716476, ...
Lot of googling did not help me! Are there any good dictionary web based available? I am looking for a site which can send me the meaning of words if we pass the word through query string! I found you a [Big Huge Thesaurus](http://words.bighugelabs.com/) with a web API, and a dictionary at [Aonaware](http://services.aonaware.com/DictService/) that looks like it uses SOAP
[ 0.45766016840934753, 0.14852303266525269, 0.2996772825717926, 0.09192607551813126, -0.20819224417209625, 0.018291085958480835, 0.6919330358505249, -0.0195893794298172, 0.08180668205022812, -0.44806650280952454, 0.30357131361961365, 0.3552573323249817, 0.014998074620962143, 0.02940690144896...
How do I write a clean implementation of the strategy pattern in Perl? I want to do it in a way that leverages Perl's features. It really depends on what you mean by "clean implementation". As in any other language, you can use Perl's object system with polymorphism to do this for you. However, since Perl has first class functions, this pattern isn't normally coded explicitly. Leon Timmermans' example of ``` sort { lc($a) cmp lc($b) } @items ``` demonstrates this quite elegantly. However, if you're looking for a "formal" implementation as you would do in C++, here's what it may look like using Perl+[Moose](http://search.cpan.org/dist/Moose). This
[ 0.19773496687412262, -0.09834978729486465, -0.08311988413333893, -0.058990418910980225, -0.13072273135185242, -0.0807529017329216, 0.41829678416252136, -0.35127103328704834, -0.34253060817718506, -0.5978882312774658, 0.047359563410282135, 0.5112910866737366, -0.6314981579780579, -0.2933649...
is just a translation of the C++ code from [Wikipedia -- Strategy pattern](http://en.wikipedia.org/wiki/Strategy_pattern), except I'm using Moose's support for delegation. ``` package StrategyInterface; use Moose::Role; requires 'run'; package Context; use Moose; has 'strategy' => ( is => 'rw', isa => 'StrategyInterface', handles => [ 'run' ], ); package SomeStrategy; use Moose; with 'StrategyInterface'; sub run { warn "applying SomeStrategy!\n"; } package AnotherStrategy; use Moose; with 'StrategyInterface'; sub run { warn "applying AnotherStrategy!\n"; } ############### package main; my $contextOne = Context->new( strategy => SomeStrategy->new() ); my $contextTwo = Context->new( strategy => AnotherStrategy->new() ); $contextOne->run(); $contextTwo->run(); ```
[ 0.07995978742837906, -0.12971815466880798, 0.39262819290161133, -0.28691545128822327, -0.40514442324638367, -0.09032577276229858, 0.8029547929763794, -0.5795778036117554, -0.18551911413669586, -0.7424371838569641, -0.1701790690422058, 0.6175962686538696, -0.3177134692668915, -0.25131845474...
I need to figure out the hard drive name for a solaris box and it is not clear to me what the device name is. On linux, it would be something like `/dev/hda` or `/dev/sda`, but on solaris I am getting a bit lost in the partitions and what the device is called. I think that entries like `/dev/rdsk/c0t0d0s0` are the partitions, how is the whole hard drive referenced? /dev/rdsk/c0t0d0s0 means Controller 0, SCSI target (ID) 0, and s means Slice (partition) 0. Typically, by convention, s2 is the entire disk. This partition overlaps with the other partitions. prtvtoc /dev/rdsk/c0t0d0s0 will show you
[ 0.3923123776912689, -0.15437088906764984, 0.4465482532978058, 0.20205402374267578, -0.18733996152877808, -0.1134444922208786, -0.3835110664367676, 0.07105174660682678, -0.17222371697425842, -0.8224425315856934, -0.2786793112754822, 0.41452252864837646, -0.09696164727210999, 0.3245268762111...
the partition table for the disk, to make sure.
[ -0.18294963240623474, 0.2415168285369873, -0.11187851428985596, 0.4255792796611786, 0.13889989256858826, 0.21081942319869995, -0.4648783504962921, 0.11366795748472214, -0.3413615822792053, -0.2988254427909851, 0.12053773552179337, 0.5532602667808533, 0.10636883974075317, -0.077271603047847...
I'm new to RhinoMocks, and trying to get a grasp on the syntax in addition to what is happening under the hood. I have a user object, we'll call it User, which has a property called IsAdministrator. The value for IsAdministrator is evaluated via another class that checks the User's security permissions, and returns either true or false based on those permissions. I'm trying to mock this User class, and fake the return value for IsAdministrator in order to isolate some Unit Tests. This is what I'm doing so far: ``` public void CreateSomethingIfUserHasAdminPermissions() { User user = _mocks.StrictMock<User>();
[ 0.38529133796691895, 0.3047347664833069, 0.4320894181728363, -0.22181369364261627, -0.08462203294038773, 0.09975907951593399, 0.5888693332672119, -0.3097960352897644, -0.006303954869508743, -0.5656245350837708, 0.2620241641998291, 0.6450008749961853, -0.2993417978286743, 0.2802855372428894...
SetupResult.For(user.IsAdministrator).Return(true); // do something with my User object } ``` Now, I'm expecting that Rhino is going to 'fake' the call to the property getter, and just return true to me. Is this incorrect? Currently I'm getting an exception because of dependencies in the IsAdministrator property. Can someone explain how I can achieve my goal here? One quick note before I jump into this. Typically you want to avoid the use of a "Strict" mock because it makes for a brittle test. A strict mock will throw an exception if anything occurs that you do not explicitly tell Rhino will happen.
[ 0.5719350576400757, 0.07436317205429077, 0.21018952131271362, 0.22636933624744415, 0.15211808681488037, -0.4897283613681793, 0.5790435075759888, -0.10265430063009262, -0.1990213543176651, -0.38976284861564636, 0.1589995175600052, 1.105592966079712, -0.24936851859092712, 0.1559676080942154,...
Also I think you may be misunderstanding exactly what Rhino is doing when you make a call to create a mock. Think of it as a custom Object that has either been derived from, or implements the System.Type you defined. If you did it yourself it would look like this: ``` public class FakeUserType: User { //overriding code here } ``` Since IsAdministrator is probably just a public property on the User type you can't override it in the inheriting type. As far as your question is concerned there are multiple ways you could handle this. You could implement IsAdministrator as a virtual property
[ 0.5077473521232605, 0.07940434664487839, 0.11561419814825058, 0.12916526198387146, 0.006214515771716833, 0.14649698138237, 0.11370599269866943, -0.30484962463378906, -0.38153111934661865, -0.2529968321323395, 0.4950805604457855, 0.5657684206962585, -0.46026289463043213, 0.41951602697372437...
on your user class as [aaronjensen](https://stackoverflow.com/questions/78389/rhinomocks-correct-way-to-mock-property-getter#78428) mentioned as follows: ``` public class User { public virtual Boolean IsAdministrator { get; set; } } ``` This is an ok approach, but only if you plan on inheriting from your User class. Also if you wan't to fake other members on this class they would also have to be virtual, which is probably not the desired behavior. Another way to accomplish this is through the use of interfaces. If it is truly the User class you are wanting to Mock then I would extract an interface from it. Your above example would look something like this: ``` public
[ 0.09874466806650162, 0.10613126307725906, 0.009980487637221813, 0.1539534032344818, -0.13885243237018585, -0.023024573922157288, 0.5453886389732361, -0.27711746096611023, -0.5518532395362854, -0.37217989563941956, 0.12486764788627625, 0.5593530535697937, -0.3324659764766693, 0.122516475617...
interface IUser { Boolean IsAdministrator { get; } } public class User : IUser { private UserSecurity _userSecurity = new UserSecurity(); public Boolean IsAdministrator { get { return _userSecurity.HasAccess("AdminPermissions"); } } } public void CreateSomethingIfUserHasAdminPermissions() { IUser user = _mocks.StrictMock<IUser>(); SetupResult.For(user.IsAdministrator).Return(true); // do something with my User object } ``` You can get fancier if you want by using [dependency injection and IOC](http://martinfowler.com/articles/injection.html) but the basic principle is the same across the board. Typically you want your classes to
[ 0.10024315118789673, -0.2027636468410492, 0.8098734617233276, -0.017908817157149315, -0.11119509488344193, 0.04238816350698471, 0.44058048725128174, -0.27405282855033875, -0.14080609381198883, -0.9597002267837524, 0.14586053788661957, 0.5225362181663513, -0.5395937561988831, 0.086294047534...
depend on interfaces rather than concrete implementations anyway. I hope this helps. I have been using RhinoMocks for a long time on a major project now so don't hesitate to ask me questions about TDD and mocking.
[ 0.5169990658760071, 0.36138999462127686, -0.0049152798019349575, 0.3298449218273163, -0.27137070894241333, -0.1373317837715149, 0.31430959701538086, 0.44123369455337524, -0.08655580878257751, -0.6922156810760498, 0.5527682900428772, 0.8734663128852844, 0.12031880021095276, -0.1682648658752...
I have an application that works pretty well in Ubuntu, Windows and the Xandros that come with the Asus EeePC. Now we are moving to the [Acer Aspire One](http://en.wikipedia.org/wiki/Aspire_One) but I'm having a lot of trouble making php-gtk to compile under the Fedora-like (Linpus Linux Lite) Linux that come with it. Hi Guys well I finally got this thing to work the basic workflow was this: ``` #!/bin/bash sudo yum install yum-utils #We don't want to update the main gtk2 by mistake so we download them #manually and install with no-deps[1](and forced because gtk version #version of AA1 and the gtk2-devel aren't compatible). sudo yumdownloader --disablerepo=updates gtk2-devel glib2-devel sudo rpm
[ 0.2969284951686859, 0.15645956993103027, 0.5130366683006287, 0.16855093836784363, -0.3652099370956421, -0.348586767911911, 0.15286730229854584, -0.17124368250370026, -0.09375772625207901, -0.5667365193367004, 0.0010408363305032253, 0.9140507578849792, 0.07553702592849731, -0.04167369753122...
--force --nodeps -i gtk2*rpm glib2*rpm #We install the rest of the libraries needed. sudo yum --disablerepo=updates install atk-devel pango-devel libglade2-devel sudo yum install php-cli php-devel make gcc #We Download and compile php-gtk wget http://gtk.php.net/do_download.php?download_file=php-gtk-2.0.1.tar.gz tar -xvzf php-gtk-2.0.1.tar.gz cd php-gtk-2.0.1 ./buildconf ./configure make sudo make install ``` If you want to add more libraries like gtk-extra please type `./configure -help` before making it to see the different options available. After installing you'll need to add `php_gtk2.so` to the *Dynamic Extensions* of `/etc/php.ini` ``` extension=php_gtk2.so ``` Sources: [1]: [Dependency problems on Acer Aspire One Linux](http://macles.blogspot.com/2008/08/dependency-problems-on-acer-aspire-one.html)
[ -0.18406130373477936, -0.08359495550394058, 0.6606186628341675, 0.21946807205677032, -0.3324001431465149, 0.009151182137429714, 0.21129661798477173, -0.3547777831554413, -0.031637128442525864, -0.369343101978302, -0.4038658142089844, 0.8349173665046692, -0.33932405710220337, -0.15483261644...
When writing a custom server, what are the best practices or techniques to determine maximum number of users that can connect to the server at any given time? I would assume that the capabilities of the computer hardware, network capacity, and server protocol would all be important factors. Also, do you think it is a good practice to limit the number of network connections to a certain maximum number of users? Or should the server not limit the number of network connections and let performance degrade until the response time is extremely high? Dan Kegel put together a summary of techniques for
[ 0.3691161274909973, 0.009971135295927525, -0.0019092384027317166, 0.20157450437545776, 0.045984555035829544, 0.28563353419303894, 0.15826956927776337, -0.36257657408714294, -0.37024497985839844, -0.5104163289070129, 0.18437503278255463, 0.4180145561695099, -0.21914148330688477, -0.28126281...
handling large amounts of network connections from a single server, here: <http://www.kegel.com/c10k.html>
[ -0.36440980434417725, 0.11315526813268661, -0.2287922203540802, 0.09659845381975174, -0.192609965801239, 0.10998646914958954, -0.18567439913749695, -0.23874908685684204, -0.7951136827468872, -0.2648645341396332, -0.20257334411144257, -0.2353399097919464, 0.22088946402072906, 0.221197769045...
How can I find out the date a MS SQL Server 2000 object was last modified? I need to get a list of all the views, procs, functions etc that were modified since Aug 15th. In sysObjects I can see the date objects were created but I need to know when they were last altered. NB: this is an SQL 2000 database. Note that SQL Server actually does **not** record the last modification date. It does not exist in any system tables. The Schema Changes History report is actually constructed from the [Default Trace](http://msdn.microsoft.com/en-us/library/ms191006.aspx). Since many admins (and web hosts) turn that off,
[ 0.28588414192199707, 0.15111993253231049, 0.3981509506702423, 0.14936226606369019, 0.13846062123775482, -0.22108638286590576, 0.16550464928150177, 0.25138965249061584, -0.4042426347732544, -0.7222257256507874, 0.22207202017307281, 0.24029165506362915, -0.04479621350765228, 0.65697085857391...
it may not work for you. Buck Woody had a good explanation of how this report works [here](http://blogs.msdn.com/buckwoody/archive/2007/10/12/sql-server-management-studio-standard-reports-schema-changes-history.aspx). The data is also temporary. For this reason, you should never RELY on the Schema Changes History report. Alternatives: * Use [DDL Triggers](http://msdn.microsoft.com/en-us/library/ms186406.aspx) to log all schema modification to a table of your choosing. * Enforce a protocol where views and procs are never altered, they are only dropped and recreated. This means the created date will also be the last updated date (this does not work with tables obviously). * Vigilantly version your SQL objects and schema in source control. -- Edit: saw that this is SQL 2000.
[ 0.3202444016933441, -0.00012217272887937725, 0.5062742829322815, 0.02866436168551445, 0.1857021003961563, -0.49534788727760315, 0.4310295581817627, 0.060371749103069305, -0.45034876465797424, -0.5789030194282532, 0.05391249433159828, 0.5219503045082092, -0.2023439258337021, 0.3216197192668...
That rules out Default Trace and DDL Triggers. You're left with one of the more tedious options I listed above.
[ 0.36847442388534546, -0.09505454450845718, 0.08572172373533249, 0.17721636593341827, 0.32683613896369934, -0.268710196018219, 0.17418384552001953, 0.03425198048353195, -0.23054584860801697, -0.34552979469299316, 0.0735354796051979, 0.5482771992683411, -0.041612397879362106, 0.0628703236579...
Using only ANSI C, what is the best way to, with fair certainty, determine if a C style string is either a integer or a real number (i.e float/double)? Don't use atoi and atof as these functions return 0 on failure. Last time I checked 0 is a valid integer and float, therefore no use for determining type. use the strto{l,ul,ull,ll,d} functions, as these set errno on failure, and also report where the converted data ended. strtoul: <http://www.opengroup.org/onlinepubs/007908799/xsh/strtoul.html> this example assumes that the string contains a single value to be converted. ``` #include <errno.h> char* to_convert = "some string"; char* p = to_convert; errno = 0; unsigned long val =
[ -0.027158202603459358, -0.0587933212518692, 0.3466328978538513, -0.18397365510463715, -0.060922570526599884, 0.12234201282262802, 0.24812015891075134, -0.5369266271591187, -0.149720698595047, -0.297470360994339, -0.1098618432879448, 0.7823490500450134, -0.35068708658218384, -0.162585705518...
strtoul(to_convert, &p, 10); if (errno != 0) // conversion failed (EINVAL, ERANGE) if (to_convert == p) // conversion failed (no characters consumed) if (*p != 0) // conversion failed (trailing data) ``` Thanks to Jonathan Leffler for pointing out that I forgot to set errno to 0 first.
[ -0.25491613149642944, 0.20778851211071014, 0.060878343880176544, -0.2909929156303406, -0.15251414477825165, 0.3254498839378357, 0.6941958069801331, -0.46370819211006165, 0.002974998438730836, -0.5364289283752441, -0.3950921297073364, 0.8108952045440674, -0.2525082528591156, -0.236129730939...
Does anyone know of any resources that talk about best practices or design patterns for shell scripts (sh, bash etc.)? I wrote quite complex shell scripts and my first suggestion is "don't". The reason is that is fairly easy to make a small mistake that hinders your script, or even make it dangerous. That said, I don't have other resources to pass you but my personal experience. Here is what I normally do, which is overkill, but tends to be solid, although *very* verbose. **Invocation** make your script accept long and short options. be careful because there are two commands to parse options, getopt
[ 0.5989628434181213, 0.07964465022087097, -0.24625858664512634, -0.10758678615093231, 0.004297905135899782, -0.3128564655780792, 0.6584393382072449, 0.06916896253824234, 0.02407415397465229, -0.5425026416778564, -0.12523742020130157, 1.0424892902374268, -0.10146797448396683, -0.308985441923...
and getopts. Use getopt as you face less trouble. ``` CommandLineOptions__config_file="" CommandLineOptions__debug_level="" getopt_results=`getopt -s bash -o c:d:: --long config_file:,debug_level:: -- "$@"` if test $? != 0 then echo "unrecognized option" exit 1 fi eval set -- "$getopt_results" while true do case "$1" in --config_file) CommandLineOptions__config_file="$2"; shift 2; ;; --debug_level)
[ 0.06814287602901459, -0.16823342442512512, 0.4204072058200836, -0.10611863434314728, 0.24799565970897675, 0.1322866678237915, 0.5128085613250732, -0.4912605285644531, -0.43749088048934937, -0.604189932346344, -0.7353231310844421, 0.8925688862800598, -0.31703299283981323, -0.521942138671875...
CommandLineOptions__debug_level="$2"; shift 2; ;; --) shift break ;; *) echo "$0: unparseable option $1"
[ -0.2265380471944809, -0.4458540678024292, 0.48807039856910706, -0.40952304005622864, 0.5112066864967346, -0.11717928200960159, 0.306922972202301, -0.15195442736148834, 0.025012323632836342, -0.18585725128650665, -0.5962072610855103, 0.7464460730552673, -0.435192346572876, -0.03867381811141...
EXCEPTION=$Main__ParameterException EXCEPTION_MSG="unparseable option $1" exit 1 ;; esac done if test "x$CommandLineOptions__config_file" == "x" then echo "$0: missing config_file parameter" EXCEPTION=$Main__ParameterException EXCEPTION_MSG="missing config_file parameter" exit 1 fi ``` Another important point is that a program should always return zero if completes successfully, non-zero if something went wrong. **Function
[ -0.22196218371391296, -0.0739394947886467, 0.20381110906600952, -0.29904478788375854, 0.19018085300922394, -0.09850547462701797, 0.5932515859603882, -0.20053626596927643, -0.4041757583618164, -0.16509570181369781, -0.38186946511268616, 0.606207013130188, -0.23063679039478302, 0.07106393575...
calls** You can call functions in bash, just remember to define them before the call. Functions are like scripts, they can only return numeric values. This means that you have to invent a different strategy to return string values. My strategy is to use a variable called RESULT to store the result, and returning 0 if the function completed cleanly. Also, you can raise exceptions if you are returning a value different from zero, and then set two "exception variables" (mine: EXCEPTION and EXCEPTION\_MSG), the first containing the exception type and the second a human readable message. When you call a function,
[ 0.0011633522808551788, 0.10159017890691757, 0.08536924421787262, -0.040092241019010544, -0.1465095728635788, 0.12876363098621368, 0.31588372588157654, -0.38082727789878845, -0.09160244464874268, -0.3834603726863861, -0.031104346737265587, 0.6923080086708069, -0.368660032749176, 0.079191945...