Search Results

Search found 5915 results on 237 pages for 'practices'.

Page 61/237 | < Previous Page | 57 58 59 60 61 62 63 64 65 66 67 68  | Next Page >

  • Best Practise for Writing a POS System

    - by Gary
    Hi, I'm putting together a basic POS system in C# that needs to print to a receipt printer and open a cash drawer. Do I have to use the Microsoft Point of Service SDK? I've been playing around with printing to my Samsung printer using the Windows driver that came with it, and it seems to work great. I assume though that other printers may not come with Windows drivers and then I would be stuck? Or would I be able to simply use the Generic/Text Driver to print to any printer that supports it? For the cash drawer I would need to send codes directly to the COM port which is fine with me, if it saves me the hassle of helping clients setup OPOS drivers on there systems. Am I going down the wrong path here? Thanks, Gary

    Read the article

  • When to use custom exceptions vs. existing exceptions vs. generic exceptions

    - by Ryan Elkins
    I'm trying to figure out what the correct form of exceptions to throw would be for a library I am writing. One example of what I need to handle is logging a user in to a station. They do this by scanning a badge. Possible things that could go wrong include: Their badge is deactivated They don't have permission to work at this station The badge scanned does not exist in the system They are already logged in to another station elsewhere The database is down Internal DB error (happens sometimes if the badge didn't get set up correctly) An application using this library will have to handle these exceptions one way or another. It's possible they may decide to just say "Error" or they may want to give the user more useful information. What's the best practice in this situation? Create a custom exception for each possibility? Use existing exceptions? Use Exception and pass in the reason (throw new Exception("Badge is deactivated.");)? I'm thinking it's some sort of mix of the first two, using existing exceptions where applicable, and creating new ones where needed (and grouping exceptions where it makes sense).

    Read the article

  • Migrating from CPython to Jython

    - by itsadok
    I'm considering moving my code (around 30K LOC) from CPython to Jython, so that I could have better integration with my java code. Is there a checklist or a guide I should look at, to help my with the migration? Does anyone have experience with doing something similar? From reading the Jython site, most of the problems seem too obscure to bother me. I did notice that: thread safety is an issue Unicode support seems to be quite different, which may be a problem for me mysqldb doesn't work and needs to be replaced with zxJDBC Anything else? Related question: What are some strategies to write python code that works in CPython, Jython and IronPython

    Read the article

  • Do MSDTC and disaster recovery go together?

    - by DevDelivery
    Our application writes to multiple Sql Server databases within a distributed transaction. The Ops guys are saying that this messes up their disaster recovery plan because while the transactions on the live tables may commit at the same time, the log shipping on the separate databases happen at slightly different times. So in in a disaster recovery situation, there will be a few partial transactions. Is there a method for maintaining separate but synced databases in DR? Or do we have to re-design to relatively independent databases (or a single database)?

    Read the article

  • Perl unpack in list context

    - by drewk
    A common 'Perlism' is generating a list as something to loop over in this form: for($str=~/./g) { print "the next character from \"$str\"=$_\n"; } In this case the global match regex returns a list that is one character in turn from the string $str, and assigns that value to $_ Instead of a regex, split can be used in the same way or 'a'..'z', map, etc. I am investigating unpack to generate a field by field interpretation of a string. I have always found unpack to be less straightforward to the way my brain works, and I have never really dug that deeply into it. As a simple case, I want to generate a list that is one character in each element from a string using unpack (yes -- I know I can do it with split(//,$str) and /./g but I really want to see if unpack can be used this way...) Obviously, I can use a field list for unpack that is unpack("A1" x length($str), $str) but is there some other way that kinda looks like globbing? ie, can I call unpack(some_format,$str) either in list context or in a loop such that unpack will return the next group of character in the format group until $str is exausted? I have read The Perl 5.12 Pack pod and the Perl 5.12 pack tutorial and the Perkmonks tutorial Here is the sample code: #!/usr/bin/perl use warnings; use strict; my $str=join('',('a'..'z', 'A'..'Z')); #the alphabet... $str=~s/(.{1,3})/$1 /g; #...in groups of three print "str=$str\n\n"; for ($str=~/./g) { print "regex: = $_\n"; } for(split(//,$str)) { print "split: \$_=$_\n"; } for(unpack("A1" x length($str), $str)) { print "unpack: \$_=$_\n"; }

    Read the article

  • Building a Drupal Newsletter Module for handling Newsletter Articles

    - by Michael T. Smith
    We're building a module for generating HTML for email newsletters. We've looked into using a few other modules (SimpleNews, MailChimp, among others), but due to various requirements, it'll be easier and better for us to build a custom solution. Being a new Drupal developer, I'm a bit worried about handling this in a "non-Drupal" way. That being said, my plan is to setup a vocabulary with Newsletters as a term and the actual Newsletters as sub-terms, like so: Newsletters (term) - Newsletter A (sub-term) - Newsletter B (sub-term) This has the added benefit of being able to organize where articles were published (besides just on the site.) The question, though, is how to handle the different Newsletter issues. I could go another level deeper in the vocabulary, like so: Newsletters (term) - Newsletter A (sub-term) - Issue - 2010-03-01 - Issue - 2010-03-02 - Newsletter B (sub-term) - Issue - 2010-03-01 - Issue - 2010-03-08 But I'm wondering if this is adding a bit too much complexity. Once I have this taxonomy setup, when the user went to add new newsletters it would also create a node (content type: newsletter), and when he/she went to add new issues, it would also create a node (content type: issue.) Those would then be the landing pages for that content. So, the question is is there a better way for handling this structure? Is this a Drupal-like solution?

    Read the article

  • Simple ASP.Net MVC 1.0 Validation

    - by Mike
    On the current project we are working on we haven't upgraded to MVC 2.0 yet so I'm working on implementing some simple validation with the tools available in 1.0. I'm looking for feedback on the way I'm doing this. I have a model that represents a user profile. Inside that model I have a method that will validate all the fields and such. What I want to do is pass a controller to the validation method so that the model can set the model validation property in the controller. The goal is to get the validation from the controller into the model. Here is a quick example public FooController : Controller { public ActionResult Edit(User user) { user.ValidateModel(this); if (ModelState.IsValid) ....... ....... } } And my model validation signature is like public void ValidateModel(Controller currentState) What issues can you see with this? Am I way out to lunch on how I want to do this?

    Read the article

  • Lisp Style question label local functions or not?

    - by Andrew Myers
    I was wondering if there is a standard practice regarding the use of labels in Lisp. I've been messing around with a Lisp implementation of the algorithm described in the first answer here http://stackoverflow.com/questions/352203/generating-permutations-lazily My current version uses labels to break out portions of functionality. (defun next-permutation (pmute) (declare (vector pmute)) (let ((len (length pmute))) (if (> len 2) (labels ((get-pivot () (do ((pivot (1- len) (1- pivot))) ((or (= pivot 0) (< (aref pmute (1- pivot)) (aref pmute pivot))) pivot))) (get-swap (pivot) (let ((swp (1- len))) (loop for i from (1- len) downto pivot do (if (or (and (> (aref pmute i) (aref pmute (1- pivot))) (< (aref pmute i) (aref pmute swp))) (< (aref pmute swp) (aref pmute (1- pivot)))) (setf swp i))) swp)) (next (swp pivot) (rotatef (aref pmute (1- pivot)) (aref pmute swp)) (reverse-vector pmute pivot (1- len)))) (let ((piv (get-pivot))) (if (> piv 0) (next (get-swap piv) piv) nil)))))) Since each label is only called once I was wondering if this is considered bad practice since the only reason to do it in this case is for aesthetic reasons. I would argue that the current version with labels is clearer but that may go against common wisdom that I'm not aware of, being new to Lisp.

    Read the article

  • Java Builder pattern with Generic type bounds

    - by I82Much
    Hi all, I'm attempting to create a class with many parameters, using a Builder pattern rather than telescoping constructors. I'm doing this in the way described by Joshua Bloch's Effective Java, having private constructor on the enclosing class, and a public static Builder class. The Builder class ensures the object is in a consistent state before calling build(), at which point it delegates the construction of the enclosing object to the private constructor. Thus public class Foo { // Many variables private Foo(Builder b) { // Use all of b's variables to initialize self } public static final class Builder { public Builder(/* required variables */) { } public Builder var1(Var var) { // set it return this; } public Foo build() { return new Foo(this); } } } I then want to add type bounds to some of the variables, and thus need to parametrize the class definition. I want the bounds of the Foo class to be the same as that of the Builder class. public class Foo<Q extends Quantity> { private final Unit<Q> units; // Many variables private Foo(Builder<Q> b) { // Use all of b's variables to initialize self } public static final class Builder<Q extends Quantity> { private Unit<Q> units; public Builder(/* required variables */) { } public Builder units(Unit<Q> units) { this.units = units; return this; } public Foo build() { return new Foo<Q>(this); } } } This compiles fine, but the compiler is allowing me to do things I feel should be compiler errors. E.g. public static final Foo.Builder<Acceleration> x_Body_AccelField = new Foo.Builder<Acceleration>() .units(SI.METER) .build(); Here the units argument is not Unit<Acceleration> but Unit<Length>, but it is still accepted by the compiler. What am I doing wrong here? I want to ensure at compile time that the unit types match up correctly.

    Read the article

  • Constructor overloading in Java - best practice

    - by errr
    There are a few topics similar to this, but I couldn't find one with a sufficient answer. I would like to know what is the best practice for constructor overloading in Java. I already have my own thoughts on the subject, but I'd like to hear more advice. I'm referring to both constructor overloading in a simple class and constructor overloading while inheriting an already overloaded class (meaning the base class has overloaded constructors). Thanks :)

    Read the article

  • Why use Python interactive mode?

    - by mvid
    When I first started reading about Python, all of the tutorials have you use Python's Interactive Mode. It is difficult to save, write long programs, or edit your existing lines (for me at least). It seems like a far more difficult way of writing Python code than opening up a code.py file and running the interpreter on that file. python code.py I am coming from a Java background, so I have ingrained expectations of writing and compiling files for programs. I also know that a feature would not be so prominent in Python documentation if it were not somehow useful. So what am I missing?

    Read the article

  • Large svn external

    - by MPelletier
    I have a project which uses a large library residing in its own repository. Using: Tortoise-SVN, the server is running an enterprise edition of VisualSVN The project itself has the "standard" structure: trunk tags branches In each branch, tag, and trunk is the library, set as an external (svn:external property). If I get the entire tree, I get the library several times, which is just getting too ridiculously repetitive. Is there a recommended structure for this? Or perhaps a way not to get all externals (because other externals are much smaller, easier to manipulate)?

    Read the article

  • How can I effectively test a scripting engine?

    - by ChaosPandion
    I have been working on an ECMAScript implementation and I am currently working on polishing up the project. As a part of this, I have been writing tests like the following: [TestMethod] public void ArrayReduceTest() { var engine = new Engine(); var request = new ExecScriptRequest(@" var a = [1, 2, 3, 4, 5]; a.reduce(function(p, c, i, o) { return p + c; }); "); var response = (ExecScriptResponse)engine.PostWithReply(request); Assert.AreEqual((double)response.Data, 15D); } The problem is that there are so many points of failure in this test and similar tests that it almost doesn't seem worth it. It almost seems like my effort would be better spent reducing coupling between modules. To write a true unit test I would have to assume something like this: [TestMethod] public void CommentTest() { const string toParse = "/*First Line\r\nSecond Line*/"; var analyzer = new LexicalAnalyzer(toParse); { Assert.IsInstanceOfType(analyzer.Next(), typeof(MultiLineComment)); Assert.AreEqual(analyzer.Current.Value, "First Line\r\nSecond Line"); } } Doing this would require me to write thousands of tests which once again does not seem worth it.

    Read the article

  • POJO's versus Cursors in Android

    - by Kilnr
    I usually tend to define the model layer of my apps using POJO's, such as Article, Comment, etc. I was about to implement an AlphabetIndexer in the adapter of one of my ListViews. Right now this adapter accepts a Collection of Articles, which I normally get from my wrapper around an SQLiteDatabase. The signature of the AlphabetIndexer constructer is as follows: public AlphabetIndexer (Cursor cursor, int sortedColumnIndex, CharSequence alphabet) Since this doesn't accept a Collection or something similar, just a Cursor, it got me wondering: maybe I shouldn't be creating objects for my model, and just use the Cursors returned from the database? So the question is, I guess: what should I do, represent data with Collections of POJO's, or just work with Cursors throughout my app? Any input?

    Read the article

  • WCF Timeout issue - should there even be a socket connection?

    - by stiank81
    I have a .Net application which is split into a client and server side. The communication between them is handled using WCF. I'm not using the automagic service references, but instead I've built the connection manually like described in the Screencast by Miguel Castro. Summarized this means that I create a console application on the server side that holds ServiceHost objects for the different services: var myServiceHost = new System.ServiceModel.ServiceHost(typeof(MyService), new Uri("net.tcp://localhost:8002")); myServiceHost.Open(); And on the client side I have service proxies creating channels using the ChannelFactory: IMyService proxy = new ChannelFactory<IMyService>("MyServiceEndpoint").CreateChannel(); The client and server side share the service contract defined in the interface IMyService. And another advantage is that I get minimal App.config files - without all the autogenerated stuff created through the Service References. Example from client side: <?xml version="1.0"?> <configuration> <system.serviceModel> <client> <endpoint address="net.tcp://localhost:8002/MyEndpoint" binding="netTcpBinding" contract="IMyService" name="MyServiceEndpoint"/> </client> </system.serviceModel> </configuration> So - to my problem. I create the proxy once, and it holds a channel all the way through the application. However, if I leave the application without use for a few minutes the channel has timed out, and I get the following exception: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9979998'. How do I prevent this? I'm assuming I need to specify a higher timeout in my configuration? But I don't want it to ever time out. But on the other hand - I don't want a socket connection! Do I need one? Thought I could go connection less with WCF... What's the permanent solution and best practice on solving this? Set timeout to "never".. Create a new channel for each request? I'm assuming there is some overhead creating the channel?.. Increase the timeout to e.g. 5minutes and create new channel if the connection did timeout? Make it connection less somehow? (Without the overhead of creating channels..) Something else...

    Read the article

  • Build and render infinite hierarchical category tree from self-referential category table

    - by FreshCode
    I have a Categories table in which each category has a ParentId that can refer to any other category's CategoryId that I want to display as multi-level HTML list, like so: <ul class="tree"> <li>Parent Category <ul> <li>1st Child Category <!-- more sub-categories --> </li> <li>2nd Child Category <!-- more sub-categories --> </li> </ul> </li> </ul> Presently I am recursively rendering a partial view and passing down the next category. It works great, but it's wrong because I'm executing queries in a view. How can I render the list into a tree object and cache it for quick display every time I need a list of all hierarchical categories?

    Read the article

  • StringLengthValidator - localization not working

    - by danysdragons
    I am validating input to my ASP.NET application using StringLengthValidators, and using the ValidationSummary control to display the error messages. To localize the application, the StringLengthValidators have the MessageTemplateResourceName and MessageTemplateResourceType attributes set. The first time the validator runs, it picks up the correct error message based on the current culture setting. If I change the language setting while running the app, the next time the validator runs, the ValidationSummary it still displays the error message for the old culture. The text for all other controls is being updated correctly. Any ideas, folks?

    Read the article

  • trouble accessing non-static functions from static functions in AS3

    - by Dogmatixed
    I have a class containing, among other things, a drop down menu. With the aim of saving space, and since the contents of the menu will never change, I've made a static DataProvider for the whole class that populates each instances menu. I was hoping to populate the list with actual functions like so: tmpArr.push({label:"Details...", funct:openDetailsMenu, args:""}); and then assign tmpArr to the DataProvider. Because the DataProvider is static the function that contains that code also needs to be static, but the functions in the array are non-static. At first it didn't seem like a problem, because when the user clicks on a menu item the drop down menu can call a non-static "executeFunction(funct, args)" on its parent. However, when I try to compile, the static function setting up the DataProvider it can't find the non-static functions being passed. If the compiler would just trust me the code would work fine! The simple solution is to just pass strings and use a switch statement to call functions based on that, but that's big, ugly, inelegant, and difficult to maintain, especially if something inherits from this class. The simpler solution is to just make the DataProvider non-static, but I'm wondering if anyone else has a good way of dealing with this? Making the static function able to see its non-static brethren? Thanks.

    Read the article

  • Dynamic State Machine in Ruby? Do State Machines Have to be Classes?

    - by viatropos
    Question is, are state machines always defined statically (on classes)? Or is there a way for me to have it so each instance of the class with has it's own set of states? I'm checking out Stonepath for implementing a Task Engine. I don't really see the distinction between "states" and "tasks" in there, so I'm thinking I could just map a Task directly to a state. This would allow me to be able to define task-lists (or workflows) dynamically, without having to do things like: aasm_event :evaluate do transitions :to => :in_evaluation, :from => :pending end aasm_event :accept do transitions :to => :accepted, :from => :pending end aasm_event :reject do transitions :to => :rejected, :from => :pending end Instead, a WorkItem (the main workflow/task manager model), would just have many tasks. Then the tasks would work like states, so I could do something like this: aasm_initial_state :initial tasks.each do |task| aasm_state task.name.to_sym end previous_state = nil tasks.each do |tasks| aasm_event task.name.to_sym do transitions :to => "#{task.name}_phase".to_sym, :from => previous_state ? "#{task.name}_phase" : "initial" end previous_state = state end However, I can't do that with the aasm gem because those methods (aasm_state and aasm_event) are class methods, so every instance of the class with that state machine has the same states. I want it so a "WorkItem" or "TaskList" dynmically creates a sequence of states and transitions based on the tasks it has. This would allow me to dynamically define workflows and just have states map to tasks. Are state machines ever used like this?

    Read the article

  • Are endless loops in bad form?

    - by rlbond
    So I have some C++ code for back-tracking nodes in a BFS algorithm. It looks a little like this: typedef std::map<int> MapType; bool IsValuePresent(const MapType& myMap, int beginVal, int searchVal) { int current_val = beginVal; while (true) { if (current_val == searchVal) return true; MapType::iterator it = myMap.find(current_val); assert(current_val != myMap.end()); if (current_val == it->second) // end of the line return false; current_val = it->second; } } However, the while (true) seems... suspicious to me. I know this code works, and logically I know it should work. However, I can't shake the feeling that there should be some condition in the while, but really the only possible one is to use a bool variable just to say if it's done. Should I stop worrying? Or is this really bad form. EDIT: Thanks to all for noticing that there is a way to get around this. However, I would still like to know if there are other valid cases.

    Read the article

  • Invoice Discount: Negative line items vs Internal properties

    - by FreshCode
    Should discount on invoice items and entire invoices be negative line items or separate properties of an invoice? In a similar question, Should I incorporate list of fees/discounts into an order class or have them be itemlines, the asker focuses more on orders than invoices (which is a slightly different business entity). Discount is proposed to be separate from order items since it is not equivalent to a fee or product and may have different reporting requirements. Hence, discount should not simply be a negative line item. Previously I have successfully used negative line items to clearly indicate and calculate discount, but this feels inflexible and inaccurate from a business perspective. Now I am opting to add discount to each line item, along with an invoice-wide discount. Is this the right way to do it? Should each item have its own discount amount and percentage? Domain Model Code Sample This is what my domain model, which maps to an SQL repository, looks like: public class Invoice { public int ID { get; set; } public Guid JobID { get; set; } public string InvoiceNumber { get; set; } public Guid UserId { get; set; } // user who created it public DateTime Date { get; set; } public decimal DiscountPercent { get; set; } // all lines discount %? public decimal DiscountAmount { get; set; } // all lines discount $? public LazyList<InvoiceLine> InvoiceLines { get; set; } public LazyList<Payment> Payments { get; set; } // for payments received public boolean IsVoided { get; set; } // Invoices are immutable. // To change: void -> new invoice. public decimal Total { get { return (1.0M - DiscountPercent) * InvoiceLines.Sum(i => i.LineTotal) - DiscountAmount; } } } public class InvoiceLine { public int ID { get; set; } public int InvoiceID { get; set; } public string Title { get; set; } public decimal Quantity { get; set; } public decimal LineItemPrice { get; set; } public decimal DiscountPercent { get; set; } // line discount %? public decimal DiscountAmount { get; set; } // line discount amount? public decimal LineTotal { get { return (1.0M - DiscountPercent) * (this.Quantity * (this.LineItemPrice)) - DiscountAmount; } } }

    Read the article

  • Enumerations and String values in ASP.NET

    - by Jason
    I'm looking for some best practice advice on enumerations and retrieving an associated string value. Given this: public enum SerialKillers { TedBundy, EdGein, AlbertFish, GeorgeBush } What is the best way to get a related string value of the name? Eg. "Ted Bundy", given that the string value may not match the representation in the enumeration. eg "George W Bush" My current thinking is function accepting an enum and returning a string, but would that not mean hard coding the string values (which I prefer not to do)? Is using a resources file where the string can be retrieved via the enumeration too heavy handed? Should I accept the fact I am going to Hell for victimising Ted Bundy by associating him with George Bush?

    Read the article

  • How to secure Add child record functionality in MVC on Parent's view?

    - by RSolberg
    I'm trying to avoid some potential security issues as I expose some a new set of functionality into the real world. This is basically functionality that will allow for a new comment to be added via a partialview on the "Parent" page. My comment needs to know a couple of things, first what record is the comment for and secondly who is making the comment. I really don't like using a hidden field to store the ID for the Parent record in the add comment form as that can be easily changed with some DOM mods. How should I handle this? PARENT <% Html.RenderPartial("AddComment", Model.Comments); %> CHILD <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CommentsViewModel>" %> <% using (Html.BeginForm("AddComment", "Requests")) {%> <fieldset> <legend>New Comment</legend> <%= Html.HiddenFor(p => p.RequestID) %> <%= Html.TextBoxFor(p => p.Text) %> &nbsp; <input type="submit" value="Add" /> </fieldset> <% } %> CONTROLLER [AcceptVerbs(HttpVerbs.Post)] public void AddComment(CommentsViewModel commentsModel) { var user = GetCurrentUser(); commentsModel.CreatedByID = user.UserID; RequestsService.AddComment(commentsModel); }

    Read the article

  • Deploying software on compromised machines

    - by Martin
    I've been involved in a discussion about how to build internet voting software for a general election. We've reached a general consensus that there exist plenty of secure methods for two way authentication and communication. However, someone came along and pointed out that in a general election some of the machines being used are almost certainly going to be compromised. To quote: Let me be an evil electoral fraudster. I want to sample peoples votes as they vote and hope I get something scandalous. I hire a bot-net from some really shady dudes who control 1000 compromised machines in the UK just for election day. I capture the voting habits of 1000 voters on election day. I notice 5 of them have voted BNP. I look these users up and check out their machines, I look through their documents on their machine and find out their names and addresses. I find out one of them is the wife of a tory MP. I leak 'wife of tory mp is a fascist!' to some blogger I know. It hits the internet and goes viral, swings an election. That's a serious problem! So, what are the best techniques for running software where user interactions with the software must be kept secret, on a machine which is possibly compromised?

    Read the article

< Previous Page | 57 58 59 60 61 62 63 64 65 66 67 68  | Next Page >