instruction
stringlengths 0
30k
⌀ |
---|
I wrote a python tsr that polled the server every so often (it pulled its polling frequency from the server) and would print out to label printer. Was relatively nice.
Once written in python, I used py2exe on it, then inno setup compiler, then put on intranet and had user install it.
It was not great, but it worked. Users would launch it in the morning, and the program would receive the kill switch from the server at night.
|
This post claims to have a link to a video that shows how to use VB9's XML Literals in C#. I didn't follow the link however. http://blogs.msdn.com/bethmassi/archive/2008/07/03/teched-panel-vb-xml-literals-for-c-developers.aspx
|
This post claims to have a link to a video that shows how to use VB9's XML Literals in C#. However, it only really discusses them and from what I can gather, you cannot use them in C#. http://blogs.msdn.com/bethmassi/archive/2008/07/03/teched-panel-vb-xml-literals-for-c-developers.aspx
|
There's two questions here: Silverlight vs. Flash as platform and Silverlight vs. Flex as RIA framework.
The first question depends on your timeframe. Flash Player has over 95% reach, Silverlight has no way near that. However, Silverlight may get there, it is after all backed by Microsoft. If you aim to launch a site next week and want a huge audience, Silverlight is not an option. If you aim to launch a really cool application that everyone would want to use it's a bit different, if your app is good enough your target audience may install Silverlight just to be able to run it.
As for the second question its a matter of how easy it is to develop <em>applications</em> in Silverlight. Flex isn't just a set of widgets, it's a very big framework that does a lot of thing that ease the work of the developer. You could write the same applications using only the core Flash API, but it would be very much more work. Depending on what's available in Silverlight, this should be an important factor when deciding. If you can cut development time, is having two platforms worth it?
|
Before burning the house down to catch a fly with NOLOCK all over, you may want to take a look at that deadlock graph you should've captured with Profiler.
Remember that a deadlock requires (at least) 2 locks. Connection 1 has Lock A, wants Lock B - and vice-versa for Connection 2. This is an unsolvable situation, and someone has to give.
What you've shown so far is solved by simple locking, which Sql Server is happy to do all day long.
I suspect you (or LINQ) are starting a transaction with that UPDATE statement in it, and SELECTing some other piece of info before hand. But, you really need to backtrack through the deadlock graph to find the locks *held* by each thread, and then backtrack through Profiler to find the statements that caused those locks to be granted.
I expect that there's at least 4 statements to complete this puzzle (or a statement that takes multiple locks - perhaps there's a trigger on the Posts table?).
|
I thought you meant [pagination of the printed page][1] - that's where I cut my teeth. I was going to enter a great monologue about collecting all the content for the page, positioning (a vast number of rules here, constrait engines are quite helpful) and justification... but apparently you were talking about the process of organizing information on webpages.
For that, I'd guess database hits. Disk access is slow. Once you've got it in memory, sorting is cheap.
[1]: http://en.wikipedia.org/wiki/Pagination
|
Unfortunately, git provides no way to do this. Instead, the 'git way' is to have two repositories -- client and server, and clone the one(s) you need.
|
Are you running your application locally inside of IIS or inside of the development web server? If it's the latter, then that's probably why: Cassini (the development web server) doesn't do ISAPI, so this value will be empty.
|
IDEA 8 Milestone 1 is a beta(ish) "based on a new platform". This may have changed the way that swing is handled. Also you are running a beta JDK.
You will probably get more help/submit a bug at the Jetbrain forums unless they are on SO also. [Here is the bug tracker link][1]
[1]: http://www.jetbrains.net/jira/browse/IDEA/ "Jetbrains jira tracker"
|
You sure the timer isn't outliving the 'dbiSchedule' somehow and firing after the 'dbiSchedule' has been been disposed of?
If that is the case you might be able to recreate it more consistently if the timer fires more quickly thus increasing the chances of you closing the Form just as the timer is firing.
|
Is it possible to cancel the timer upon closing the form (*i.e.* in the form's OnClose() method)? This looks like the cleanest solution.
|
Looks like a threading issue.
**Hypothesis**: Maybe you have a main thread and a timer thread accessing this control. The main thread shuts down - calling Control.Dispose() to indicate that I'm done with this Control and I shall make no more calls to this. However the timer thread is still active - a context switch to that thread, where it may call methods on the same control. Now the control says I'm Disposed (already given up my resources) and I shall not work anymore. ObjectDisposed exception.
**How to solve this**: In the timer thread, before calling methods/properties on the control, do a check with
if ControlObject.IsDisposed then return; // or do whatever - but don't call control methods
OR stop the timer thread BEFORE disposing the object.
|
The following regex should do the job (Perl regex syntax):
/(10\.\d+\/\d+)/
You could do some additional sanity checking by opening the urls
http://hdl.handle.net/<doi>
and
http://dx.doi.org/<doi>
where <doi> is the candidate doi,
and testing that you a) get a 200 OK http status, and b) the returned page is not the "DOI not found" page for the service.
|
Another good GUI designer for Eclipse is [Window Builder Pro][1]. Like Jigloo, it's not free for commercial use.
It allows you to design user interfaces for Swing, SWT and even the Google Web Toolkit (GWT).
[1]: http://www.windowbuilderpro.com/
|
Have you looked at [WIFE][1]? We use that in our application which translates SWIFT messages to an internal XML format and back again. We haven't had any problems with it. Also, it's licensed under the LGPL, so you can hack it up if you need to. Check it out.
[1]: http://wife.sourceforge.net/
|
Yes, a svn copy (whether you are thinking of it as a tag, a branch, or copying a file in trunk) is all the same. SVN will internally create a pointer to the source location at that revision. If you then make changes to the copy (which you are likely to do if it is a branch or a copied file in trunk, but shouldn't do for tags), SVN will only store what was changed, rather than creating a whole new copy.
|
One of the best comprehensive discussions of software design concepts related to OO (including these ones) is Bertrand Meyer's [Object Oriented Software Construction][1].
Regarding 'coupling', he gives his Weak Coupling / Small Interfaces rule as follows:
>>**If two modules communicate, they should exchange as little information as possible.**
Meyer's material related to cohesion isn't ever boiled down to a single pithy statement, but I think this sentence from Steve McConnell's [Code Complete][2] sums it up pretty well:
>>**Cohesion refers to how closely all the routines in a class or all the code in a routine support a central purpose**
[1]: http://www.amazon.com/Object-Oriented-Software-Construction-Prentice-Hall-International/dp/0136291554/ref=sr_1_1?ie=UTF8&s=books&qid=1220373153&sr=8-1
[2]: http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670/ref=sr_1_1?ie=UTF8&s=books&qid=1220373885&sr=1-1
|
@[bpapa](#39813)
> It's just another web browser that
> very few people are going to use
> because there are already 4 major
> browsers out there that work just fine
> for most people. It doesn't have the
> extensions like Firefox,
Actually, it is pretty clear that it has a plugin architecture
> it doesn't
> have browser sync with an iPhone like
> Safari, it doesn't come with your
> computer like IE, and it doesn't...
> well I don't know what Opera does that
> makes it stand out but I don't think
> Chrome has it.
"I don't know what Opera has, but this piece of software that I've never touched clearly doesn't have it"... what??
> Another reason why I don't see it
> taking off - since it's not on OS X a
> lot of tech people aren't going to be
> using it.
Did you miss the part where the Linux and OS X distros are coming right behind Windows?
|
The other answers cover how to do this well, but I thought I'd also point out that it's not really odd that this isn't in the vector API: it's inefficient, linear search through the vector for the value, followed by a bunch of copying to remove it.
If you're doing this operation intensively, it can be worth considering std::set instead for this reason.
|
Modifying the bootloader is bad, bad idea. Here are just a few of the possible gotcha's:
- it will potentially kill full disk encryption products (Truecrypt, PGP, Vista's BitLocker, etc)
- it will potentially trip up AV products (scaring users)
- it will potentially kill complicated booting scenarios (chained boot loaders, etc)
- it will kill off the chain of trust when using the TPM module (because it checks the MBR for change before executing it)
- direct disk access is not allowed starting from Vista (only using drivers)
Alternatives (like modifying the hardware register during the Windows bootup via a driver which is set to load at boot time or after Windows has booted) should really be considered. If the modification is as simple as writing to a port, ie:
OUT AX, BL
then drivers exists for all versions of Window which can do this (reading/writing a value from/to a certain port) which can be called from user mode.
|
I liked the mouseover/out best since I actually already needed to swap the image anyhow. I really should have thought of doing this with javascript to begin with.
Thanks for the quick answers.
|
I liked the mouseover/out best since I actually already needed to swap the image anyhow. I really should have thought of doing this with javascript to begin with.
Thanks for the quick answers.
@Joseph
Thanks for that link. I had never heard of this technique before and really like the idea.
I will definitely try that out and see how I fare with it.
|
Python doesn't have an equivalent but you can implement your own.
Myself, I like keeping it simple (I've seen some horribly complex examples on the net), something like this ...
class Animal:
DOG=1
CAT=2
x = Animal.DOG
|
How to Turn Off Sounds in Turtoise SVN
|
|tortoisesvn|
|
I do not want SVN to alert me with sounds, when it fails to update for e.g. How do I turn off sounds in SVN?
|
|tortoisesvn|system-sounds|
|
Hmmm... I suppose the closest thing to an enum would be a dictionary, defined either like this:
months = {
'January': 1,
'February': 2,
...
}
or
months = dict(
January=1,
February=2,
...
)
Then, you can use the symbolic name for the constants like this:
mymonth = months['January']
There are other options, like a list of tuples, or a tuple of tuples, but the dictionary is the only one that provides you with a "symbolic" (constant string) way to access the
value.
Edit: I like Alexandru's answer too!
|
The XOR method fails if a and b point to the same address. The first XOR will clear all of the bits at the memory address pointed to by both variables, so once the function returns (*a == *b == 0), regardless of the initial value.
More info on the Wiki page:
[XOR swap algorithm][1]
Although it's not likely that this issue would come up, I'd always prefer to use the method that's guaranteed to work, not the clever method that fails at unexpected moments.
[1]: http://en.wikipedia.org/wiki/XOR_swap_algorithm
|
Thanks for the answers. This is what I'm going to try for dynamically choosing the right method:
I'll collect all of the first *N* hits in a conventional bit array, and choose one of three methods, based on the symmetry of this sample.
- If the sample is highly asymmetric,
I'll simply store the indexes to the
set bits (or maybe the distance to
the next bit) in a list.
- If the sample is highly symmetric,
I'll keep using a conventional bit
array.
- If the sample is moderately
symmetric, I'll use a lossless
compression method like Huffman
coding [suggested by
InSciTekJeff][1].
The boundaries between the asymmetric, moderate, and symmetric regions will depend on the time required by the various algorithms balanced against the space they need, where the relative value of time versus space would be an adjustable parameter. The space needed for Huffman coding is a function of the symmetry, and I'll profile that with testing. Also, I'll test all three methods to determine the time requirements of my implementation.
It's possible (and actually I'm hoping) that the middle compression method will always be better than the list or the bit array or both. Maybe I can encourage this by choosing a set of Huffman codes adapted for higher or lower symmetry. Then I can simplify the system and just use two methods.
[1]: http://stackoverflow.com/questions/36106/what-are-some-alternatives-to-a-bit-array#36311
|
@Martin
That works for local forms that open in InfoPath. Nathan was asking about web-enabled forms. ActiveX controls are disabled for web forms, as evidenced by the informational label at the bottom of the design controls when the form compatability has been set to the web.
Now, I will admit that I know nothing about the HTML tags to play audio in a browser, but I have something else that might work. I had an InfoPath form that I needed to dynamically load an image into for a web-enabled form. Similar to the ActiveX issue, the Picture control was also disabled. What I did was put some managed code behind the form and execute the following when the form loaded.
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
string imgPath = "http://yoursite/yourimage.jpeg";
XPathNodeIterator xpni = MainDataSource.CreateNavigator().SelectSingleNode("/my:FormName/my:RichTextControlName", NamespaceManager).SelectChildren(XPathNodeType.All);
xpni.Current.InnerXml = "<img xmlns=\"http://www.w3.org/1999/xhtml\" src=\"" + filePath + "\" width=\"200px\" height=\"55px\" />";
}
I don't see why you couldn't take the same approach and load audio rather than an image.
|
Here's a good example using Regular Expressions: <https://web.archive.org/web/20210619174622/https://www.4guysfromrolla.com/webtech/042501-1.shtml>
|
You could load your list of words as chakrit suggested into a data table or xml file with a unique sequential key. When getting your random word, use a random number generator to determine what words to fetch by their key. If you concatenate 2 of them, I don't think you need to include the numbers in the string unless "true randomness" is part of the goal.
|
if statement condition optimisation
|
|php|language-agnostic|conditional-statements|
|
I have an if statment with two conditions (seperated by an OR operator), one of the conditions covers +70% of situations and takes far less time to process/execute than the second condition, so in the interests of speed i only want the second condition to be processed if the first condition evaluates to false.
if i order the conditions so that the first condition (the quicker one) appears in the if statment first - on the occasions where this condition is met and evaluates true is the second condition even processed ?
if ( (condition1) | (condition2) ){
// do this
}
or would i need to nest two if statements to only check the second condition if the first evaluates to false ?
if (condition1){
// do this
}else if (condition2){
// do this
}
I am working in php, however i assume that this may be language-agnostic.
Thanks
|
Since this is tagged language agnostic I'll chime in. For Perl at least, the first option is sufficient, I'm not familiar with PHP. It evaluates left to right and drops out as soon as the condition is met.
|
If you know the HTML is well-formed enough, you could, if you make sure it has a root node, convert the data in that field into a System.Xml.XmlDocument and then get the InnerText value from it.
Again, you will have to make sure the text has a root node, which you can add yourself if needs be, since it will not matter, and make sure the HTML is well formed.
|
How do you set up an OpenID server in Ubuntu?
|
|ubuntu|openid|linux|
|
I want to log onto Stack Overflow using OpenID, but I thought I'd set up my own server, just because it's harder :) How do you do this in Ubuntu?
|
How do you set up an OpenID provider (server) in Ubuntu?
|
|linux|ubuntu|openid|
|
I want to log onto Stack Overflow using OpenID, but I thought I'd set up my own OpenID provider, just because it's harder :) How do you do this in Ubuntu?
Edit: Replacing 'server' with the correct term OpenID provider (Identity provider would also be correct according to [wikipedia](http://en.wikipedia.org/wiki/Openid#Using_OpenID)).
|
Redirect the data to disk and use a [Hex Editor][1]. Most text editors / viewers do their own conversions behind the scenes, so it is difficult to be sure you are seeing the data in it's true form.
[1]: http://www.ex-cinder.com/hexeditor/index.html
|
Which is a better approach in logging - files or DB?
|
|multithreading|logging|
|
Okay, here's the scenario. I have a utility that processes tons of records, and enters information to the Database accordingly.
It works on these records in multi-threaded batches. Each such batch writes to the same log file for creating a workflow trace for each record. Potentially, we could be making close to a million log writes in a day.
Should this log be made into a database residing on another server? Considerations:
1. The obvious disadvantage of multiple threads writing to the same log file is that the log messages are shuffled amongst each other. In the database, they can be grouped by batch id.
2. Performance - which would slow down the batch processing more? writing to a local file or sending log data to a database on another server on the same network. Theoretically, the log file is faster, but is there a gotcha here?
Are there any optimizations that can be done on either approach?
Thanks.
|
Another place you could stop the timer is the [FormClosing](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx) event - this happens before the form is actually closed, so is a good place to stop things before they might access unavailable resources.
|
I think it depends greatly on what you are doing with the log files afterwards.
Of the two operations writing to the log file will be faster - especially as you are suggesting writing to a database on another server.
However if you are then trying to process and search the log files on a regular basis then the best place to do this would be a database.
If you use a logging framework like log4net they often provide simple config file based ways of redirecting input to file or database.
|
Set up Powershell Script for Automatic Execution
|
|powershell|scripting|command-line|
|
Just a side note, this statement has no effect:
XML.ignoreWhitespace;
because <code>ignoreWhitespace</code> is a property. You have to set it to <code>true</code> like this:
XML.ingoreWhitespace = true;
|
Here are two code samples you can try:
**1**:
<script>
function Print() {
alert ("THUD.. another tree bites the dust!")
if (document.layers)
{
window.print();
}
else if (document.all)
{
WebBrowser1.ExecWB(6, 1)//use 6, 1 to prompt the print dialog or 6, 6 to omit it
;
WebBrowser1.outerHTML = "";
}
}
</script>
<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
**2**:
if (navigator.appName == "Microsoft Internet Explorer")
{
var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
PrintCommandObject.ExecWB(6, -1); PrintCommandObject.outerHTML = "";
}
else {
window.print();
}
You may need to add the site/page you are testing on to you local intranet zone.
|
Here are two code samples you can try:
**1**:
<script>
function Print() {
alert ("THUD.. another tree bites the dust!")
if (document.layers)
{
window.print();
}
else if (document.all)
{
WebBrowser1.ExecWB(6, 1);
//use 6, 1 to prompt the print dialog or 6, 6 to omit it
//some websites also indicate that 6,2 should be used to omit the box
WebBrowser1.outerHTML = "";
}
}
</script>
<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>
**2**:
if (navigator.appName == "Microsoft Internet Explorer")
{
var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
document.body.insertAdjacentHTML('beforeEnd', PrintCommand);
PrintCommandObject.ExecWB(6, -1); PrintCommandObject.outerHTML = "";
}
else {
window.print();
}
You may need to add the site/page you are testing on to you local intranet zone.
|
The <code>Event.COMPLETE</code> handler really shouldn't be called unless the loader was fully loaded, it makes no sense. Have you confirmed that it is in fact not fully loaded (by looking at the <code>bytesLoaded</code> vs. <code>bytesTotal</code> values that you trace)? If the <code>Event.COMPLETE</code> event is dispatched before <code>bytesLoaded == bytesTotal</code> that is a bug.
Good that you've got it working with the timer, but it is very odd that you need it.
|
In addition to the other comments, you may find the -m (move) switch to git-branch helpful. You could rename your old master to something else, then rename your new branch to master:
git branch -m master crap_work
git branch -m previous_master master
|
I think the article "[Java theory and practice: A brief history of garbage collection][1]" from IBM should help explain some of the questions you have.
[1]: http://www.ibm.com/developerworks/java/library/j-jtp10283/
|
I would suggest mocking out your calls to the database. Mocks are basically objects that look like the object you are trying to call a method on, in the sense that they have the same properties, methods, etc. available to caller. But instead of performing whatever action they are programmed to do when a particular method is called, it skips that altogether, and just returns a result. That result is typically defined by you ahead of time.
In order to set up your objects for mocking, you probably need to use some sort of inversion of control/ dependency injection pattern, as in the following pseudo-code:
class Bar {
private FooDataProvider _dataProvider;
public instantiate(FooDataProvider dataProvider) {
_dataProvider = dataProvider;
}
public getAllFoos() {
##instead of calling Foo.GetAll() here, we are introducing an extra layer of abstraction
return _dataProvider.GetAllFoos();
}
}
class FooDataProvider {
public Foo[] GetAllFoos() {
return Foo.GetAll();
}
}
Now in your unit test, you create a mock of FooDataProvider, which allows you to call the method GetAllFoos without having to actually hit the database.
class BarTests {
public TestGetAllFoos() {
#here we set up our mock FooDataProvider
mockRepository = MockingFramework.new()
mockFooDataProvider = mockRepository.CreateMockOfType(FooDataProvider);
#create a new array of Foo objects
testFooArray = new Foo[] {Foo.new(), Foo.new(), Foo.new()}
#the next statement will cause testFooArray to be returned every time we call FooDAtaProvider.GetAllFoos, instead of calling to the database and returning whatever is in there
#ExpectCallTo and Returns are methods provided by our imaginary mocking framework
ExpectCallTo(mockFooDataProvider.GetAllFoos).Returns(testFooArray)
#now begins our actual unit test
testBar = new Bar(mockFooDataProvider)
baz = testBar.GetAllFoos()
#baz should now equal the testFooArray object we created earlier
Assert.AreEqual(3, baz.length)
}
}
A common mocking scenario, in a nutshell. Of course you will still probably want to unit test your actual database calls too, for which you will need to hit the database.
|
Simple password encryption
|
|database|language-agnostic|passwords|
|
What is a good, simple encryption scheme for protecting passwords in a database? I don't necessarily need anything that's hyper-secure nor do I need anything that's lightning fast, but those things would be nice. Primarily, I just want something that's easy to implement without being terribly slow or insecure.
|
[MD5](http://en.wikipedia.org/wiki/MD5) or [SHA1](http://en.wikipedia.org/wiki/SHA-1) + salt.
|
Use the [SHA][1] one way hashing algorithm along with a unique salt. It is the main algorithm I use for storing my passwords in the database.
[1]: http://en.wikipedia.org/wiki/SHA-1
|
If you use MD5 or SHA1 use a salt to avoid rainbow table hacks.
In C# this is easy:
MD5CryptoServiceProvider hasher = new MD5CryptoServiceProvider();
string addSalt = string.Concat( "ummm salty ", password );
byte[] hash = hasher.ComputeHash( Encoding.Unicode.GetBytes( addSalt ) );
|
Well I think that the only major example of multi-threaded javascript is Google's chrome (WOULD THEY RELEASE IT ALREADY JEEZ) and if I understand it the javascript will only one process per tab, so unless it started spawning tabs (popups) I would assume this would be a null issue, but I think that Google has that under wraps anyway, the are running all the javascript in a sandbox.
|
I seem to remember Brendan Eich commented on this in a recent podcast; if i recall correctly, it's not being considered, as it adds unreasonable restrictions to optimization. He compared it to the `arguments` local in that, while useful for varargs, its very existence removes the ability to guess at what a function will touch just by looking at its definition.
BTW: i believe JS *did* have support for accessing locals through the arguments local at one time - [a quick search][1] shows this has been deprecated though.
[1]: http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Functions/arguments
|
Again, we need to make a distinction between 1) multithreaded support in the language (which I don't think is seriously being discussed as something that will happen) and 2) usage of multiple threads in the JavaScript engine/interpreter in the browser.
For #2, I can't see how this can really add any possible security concerns to the engine/interpreter, unless there are flaws in the implementation.
|
To answer part of your question, here's how you'd run a rake task from inside Rails code:
require 'rake'
load 'path/to/task.rake'
Rake::Task['foo:bar:baz'].invoke
Mind you, I have no idea how (or why) you could have one database per user.
|
Be careful with generic foreign keys that don't point to exactly one table. Query performance suffers dramatically if you have to split the where condition on a type and point to several different tables. If you only have a few types, and the number of types will not grow, it's Ok to have separate nullable foreign keys to the different tables, but if you will have more types, it's better to come up with a different data model (like @palmsey's suggestion).
|
I'm with ScottKoon here, Adobe AIR is great. I've really only made one really nice (imho) widget thus far, but I did so using jQuery and Prototype.js, which floored in such wonderful ways because I didn't have to learn a whole new event model. Adobe AIR is really sweet, the memory foot print isn't too bad, upgrading to a new version is built into AIR so it's almost automatic, and best of all it's cross-platform...they even have an alpha-version for Linux, but it works pretty well already on my Eee.
|
Create new page in Webtop
|
|documentum|webtop|
|
How do I create a new webpage in the Documentum front end Webtop?
|
Best way to update LINQ to SQL classes after database schema change
|
|c#|.net|linq-to-sql|
|
I'm using LINQ to SQL classes in a project where the database design is still in a bit of flux.
Is there an easy way of synchronising the classes with the schema, or do I need to manually update the classes if a table design changes?
|
|f#|functional-programming|lambda|
|
|functional-programming|f#|lambda|
|
Is it possible to pass a reference to a function to another function in F#? Specifically, I'd like to pass lambda functions like
foo(fun x -> x ** 3)
More specifically, I need to know how I would refer to the passed function in a function that I wrote myself.
|
How To Extract SFTP SSH Key From Key Cache in FileZilla FTP Client
|
|ftp|sftp|filezilla|
|
I have connected to a server via SFTP using FileZilla and accepted adding the server's SSH key to the key cache in FileZilla.
How can I extract this cached key to a keyfile so that may use it through other SFTP applications that require a keyfile be made available?
I have not been able to find anything in the FileZilla documentation related to this.
|
The **highly regarded [Joda Time library][1]** is also worth a look. This is basis for the new [date and time api][2] that is pencilled in for Java 7. The design is neat, intuitive, [well documented][3] and avoids a lot of the clumsiness of the original Date / Calendar classes. [`DateFormatter`][4] can parse a String to a Joda `DateTime`.
[1]: http://joda-time.sourceforge.net/index.html
[2]: http://jcp.org/en/jsr/detail?id=310
[3]: http://joda-time.sourceforge.net/userguide.html
[4]: http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormatter.html
|
The **highly regarded [Joda Time library][1]** is also worth a look. This is basis for the new [date and time api][2] that is pencilled in for Java 7. The design is neat, intuitive, [well documented][3] and avoids a lot of the clumsiness of the original `java.util.Date` / `java.util.Calendar` classes.
Joda's [`DateFormatter`][4] can parse a String to a Joda `DateTime`.
[1]: http://joda-time.sourceforge.net/index.html
[2]: http://jcp.org/en/jsr/detail?id=310
[3]: http://joda-time.sourceforge.net/userguide.html
[4]: http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormatter.html
|
If you don't need ASP.NET handled edit cabilities I would **stay away** from the DataGrid and the GridView ... they provide **unnecessary bloat**.
|
ROUND ( 123.456 , 2 , 1 )
When the third parameter **!= 0** it truncates rather than rounds
[http://msdn.microsoft.com/en-us/library/ms175003(SQL.90).aspx][1]
[1]: http://msdn.microsoft.com/en-us/library/ms175003(SQL.90).aspx
|
It's easy, you just add a docstring at the top of the module.
|
For the packages, you can document it in `__init__.py`.
For the modules, you can add a docstring simply in the module file.
All the information is here: http://www.python.org/dev/peps/pep-0257/
|
I'm a big fan of [Cronolog][1]. Just install and pipe your logs through it. For daily log rotation, something like this would work:
ErrorLog "|/usr/bin/cronolog /path/to/logs/%Y-%m-%d/error.log"
CustomLog "|/usr/bin/cronolog /path/to/logs/%Y-%m-%d/access.log" combined
Pretty handy, and once installed, easier (in my experience) than logrotate.
[1]: http://cronolog.org/
|
Pretty much every language does a short circuit evaluation. Meaning the second condition is only evaluated if it's aboslutely necessary to. For this to work, most languages use the double pipe, ||, not the single one, |.
See http://en.wikipedia.org/wiki/Short-circuit_evaluation
|
I think since no communication is possible, the best strategy would involve distributing the probability of each prisoners as evenly as possible?
**My take:**
1. Draw a table of numbers with 2 columns, the first column contains the box number (from box #1 to box#100). Each prisoner then gets to pick 50 boxes and whatever box they pick, they should put 1 mark on the corresponding row in the second column.
2. All prisoners are however required to never pick any box twice. And no box may be marked more than 50. Some prisoners may get less options than others since some box may get filled to 50 marks first.
3. When a prisoner is moved to room B he/she opens whatever boxes he has marked on.
|
I think since no communication is possible, the best strategy would involve
> distributing the probability of each prisoners as evenly as possible
Am I on the right path or not?
**Information available for each prisoner:**
>* The number of survivied prisoners, so if you have an efficient box picking system that utilizes the order any prisoner enters room B, then **a strategy is definitely possible**
* Which boxes the earlier prisoners picked. Of course, no communication is possible _during_ the run and it wouldn't be possible to remember any 100s box picking permutation. **But you could use this information to compute in a system _before_ the run starts.**
**My take:**
> 1. Draw a table of numbers with 2 columns, the first column contains the box number (from box #1 to box#100). Each prisoner then gets to pick 50 boxes and whatever box they pick, they should put 1 mark on the corresponding row in the second column.
2. All prisoners are however required to never pick any box twice. And no box may be marked more than 50. Some prisoners may get less options than others since some box may get filled to 50 marks first.
3. When a prisoner is moved to room B he/she opens whatever boxes he has marked on.
|
A common practice is to move all the code you can out of the codebehind and into an object you can test in isolation. Such code will usually follow the MVP or MVC design patterns. If you search on "Rhino Igloo" you will probably find the link to its Subversion repository. That code is worth a study, as it demonstrate one of the best MVP implementations on Web Forms that I have seen.
Your codebehind will, when following this pattern, do two things:
1. Transit all user actions to the presenter.
2. Render data provided by the presenter.
Unit testing the presenter should be trivial.
|
A common practice is to move all the code you can out of the codebehind and into an object you can test in isolation. Such code will usually follow the MVP or MVC design patterns. If you search on "Rhino Igloo" you will probably find the link to its Subversion repository. That code is worth a study, as it demonstrate one of the best MVP implementations on Web Forms that I have seen.
Your codebehind will, when following this pattern, do two things:
1. Transit all user actions to the presenter.
2. Render data provided by the presenter.
Unit testing the presenter should be trivial.
Update: Rhino Igloo can be found here: https://svn.sourceforge.net/svnroot/rhino-tools/trunk/rhino-igloo/
|
Re: aku, izb, John Topley...
Watch out for mutability issues...
It may seem sensible to omit getters/setters. It actually may be ok in some cases. The real problem with the proposed pattern shown here is mutability.
The problem is once you pass an object reference out containing non-final, public fields. Anything else with that reference is free to modify those fields. You no longer have any control over the state of that object. (Think what would happen if Strings were mutable.)
It gets bad when that object is an important part of the internal state of another, you've just exposed internal implementation. To prevent this, a copy of the object must be returned instead. This works, but can cause massive GC pressure from tons of single-use copies created.
If you have public fields, consider making the class read-only. Add the fields as parameters to the constructor, and mark the fields final. Otherwise make sure you're not exposing internal state, and if you need to construct new instances for a return value, make sure it won't be called excessively.
See: "[Effective Java][1]" by Joshua Bloch -- Item #13: Favor Immutability.
PS: Also keep in mind, all JVMs these days will optimize away the getMethod if possible, resulting in just a single field-read instruction.
[1]: http://java.sun.com/docs/books/effective/
|
The *args and **kwargs ist a common idiom to allow arbitrary number of arguments to functions as described in [the python docs][1]
The *args will give you all funtion parameters a a list:
In [1]: def foo(*args):
...: for a in args:
...: print a
...:
...:
In [2]: foo(1)
1
In [4]: foo(1,2,3)
1
2
3
The **kwargs will give you all named function parameters as a dictionary:
In [5]: def bar(**kwargs):
...: for a in kwargs:
...: print a, kwargs[a]
...:
...:
In [6]: bar(name="one", age=27)
age 27
name one
An other usage of the *l is to "flattern" a list:
In [9]: def foo(bar, lee):
...: print bar, lee
...:
...:
In [10]: l = [1,2]
In [11]: foo(*l)
1 2
[1]: http://docs.python.org/tut/node6.html#SECTION006700000000000000000
|
The *args and **kwargs ist a common idiom to allow arbitrary number of arguments to functions as described in [the python docs][1]
The *args will give you all funtion parameters a a list:
In [1]: def foo(*args):
...: for a in args:
...: print a
...:
...:
In [2]: foo(1)
1
In [4]: foo(1,2,3)
1
2
3
The \**kwargs will give you all
**keyword arguments** except for those corresponding to a formal parameter as a dictionary
In [5]: def bar(**kwargs):
...: for a in kwargs:
...: print a, kwargs[a]
...:
...:
In [6]: bar(name="one", age=27)
age 27
name one
An other usage of the *l the reversed usage when calling a function is to **unpack argument lists**
In [9]: def foo(bar, lee):
...: print bar, lee
...:
...:
In [10]: l = [1,2]
In [11]: foo(*l)
1 2
[1]: http://docs.python.org/tut/node6.html#SECTION006700000000000000000
|
> @Mickey: No, it is turned off. Do I need to turn it on to find out?
The trace log will show you how long each action takes. It could help you find what is taking so long.
[Here][1] is a link that might help you get it setup.
[1]: http://davidhayden.com/blog/dave/archive/2005/07/17/2396.aspx
|
You can use [MySQL Query Browser][1] to run the query and then just go to File -> Export Resultset and choose the output format. The options are CSV, HTML, XML, Excel and PLIST.
[1]: http://www.mysql.com/products/tools/query-browser/
|