Search Results

Search found 27766 results on 1111 pages for 'bad idea jeans'.

Page 100/1111 | < Previous Page | 96 97 98 99 100 101 102 103 104 105 106 107  | Next Page >

  • Python to Java translation

    - by obelix1337
    Hello, i get quite short code of algorithm in python, but i need to translate it to Java. I didnt find any program to do that, so i will really appreciate to help translating it. I learned python a very little to know the idea how algorithm work. The biggest problem is because in python all is object and some things are made really very confuzing like sum(self.flow[(source, vertex)] for vertex, capacity in self.get_edges(source)) and "self.adj" is like hashmap with multiple values which i have no idea how to put all together. Is any better collection for this code in java? code is: [CODE] class FlowNetwork(object): def __init__(self): self.adj, self.flow, = {},{} def add_vertex(self, vertex): self.adj[vertex] = [] def get_edges(self, v): return self.adj[v] def add_edge(self, u,v,w=0): self.adj[u].append((v,w)) self.adj[v].append((u,0)) self.flow[(u,v)] = self.flow[(v,u)] = 0 def find_path(self, source, sink, path): if source == sink: return path for vertex, capacity in self.get_edges(source): residual = capacity - self.flow[(source,vertex)] edge = (source,vertex,residual) if residual > 0 and not edge in path: result = self.find_path(vertex, sink, path + [edge]) if result != None: return result def max_flow(self, source, sink): path = self.find_path(source, sink, []) while path != None: flow = min(r for u,v,r in path) for u,v,_ in path: self.flow[(u,v)] += flow self.flow[(v,u)] -= flow path = self.find_path(source, sink, []) return sum(self.flow[(source, vertex)] for vertex, capacity in self.get_edges(source)) g = FlowNetwork() map(g.add_vertex, ['s','o','p','q','r','t']) g.add_edge('s','o',3) g.add_edge('s','p',3) g.add_edge('o','p',2) g.add_edge('o','q',3) g.add_edge('p','r',2) g.add_edge('r','t',3) g.add_edge('q','r',4) g.add_edge('q','t',2) print g.max_flow('s','t') [/CODE] result of this example is "5". algorithm find max flow in graph(linked list or whatever) from source vertex "s" to destination "t". Many thanx for any idea

    Read the article

  • GoTo statements and alternatives in VB.NET

    - by qais
    I've posted a code snippet on another forum asking for help and people pointed out to me that using GoTo statements is very bad programming practice. I'm wondering: why is it bad? What alternatives to GoTo are there to use in VB.NET that would be considered generally more of a better practice? Consider this snippet below where the user has to input their date of birth. If the month/date/year are invalid or unrealistic(using if statements checking the integer inputs size, if there's a better way to do this, I'd appreciate if you could tell me that also :D) How would I be able to loop back to ask the user again? retryday: Console.WriteLine("Please enter the day you were born : ") day = Console.ReadLine If day > 31 Or day < 1 Then Console.WriteLine("Please enter a valid day") GoTo retryday End If

    Read the article

  • MySQL query optimization.

    - by PiKey
    I'm so bad in making good MySQL queries. I've created this one: http://pastebin.com/GtDfgky8 products Table have about 17k rows, allegro Table have about 3k of rows. The query Idea is select all products, where stock_quanity 3, where is photo, and where is no product id in allegro table. Now query takes about 10 seconds... I have no idea how I can optimize this query. Please help my, I'll be thankfully! :) & Sorry for my bad English also

    Read the article

  • Getting TexBox's ID's .... to Calculate

    - by jjj
    i have : vb code: Private Sub Calculation() Dim txt1 As Decimal txt1 = (CS_Incoms_done.Text / CS_Incoms_target.Text) * 100 CS_Incom_Result.Text = "%" + FormatNumber(txt, 2, TriState.False) Dim txt2 As Decimal txt2 = (CS_GovernmentService_done.Text / CS_GovernmentService_target.Text) * 100 CS_GovernmentService_Result.Text = "%" + FormatNumber(txt2, 2, TriState.False) Dim txt3 As Decimal txt3 = (CS_RentBox_done.Text / CS_RentBox_target.Text) * 100 CS_RentBox_Result.Text = "%" + FormatNumber(txt3, 2, TriState.False) Dim txt4 As Decimal txt4 = (CS_ServiceAdvertising_done.Text / CS_ServiceAdvertising_target.Text) * 100 CS_ServiceAdvertising_Result.Text = "%" + FormatNumber(txt4, 2, TriState.False) Dim txt5 As Decimal txt5 = (CS_ServiceCatogray_done.Text / CS_ServiceCatogray_target.Text) * 100 CS_ServiceCatogray_Result.Text = "%" + FormatNumber(txt5, 2, TriState.False) End Sub i just show you 5 textbox's of 100 textbox's .... and don't want to complete all the textbox's like this ... i want a simple code to do it.. ... as you notice , every three textbox's are look a like on the first two parts of their id's..~ for example -- CS_ServiceCatogray _Result.Text, CS_ServiceCatogray _done.Text and CS_ServiceCatogray _target.Text... ~..and the last part is the same in all textbox's for geving the Result .. _Result.Text , _done.Text and _target.Text So... i had an idea to take the id and put the Similar two parts in an array... and use For Each something like: Dim allItems As Array For Each item As Control In panel4.Controls Select Case item.[GetType]().Name Case "TextBox" 'here just be sure that this item is not saved in the allItems array ,if it is not do >>' allItems[Last_Item_Saved_Index+1] = DirectCast(item, TextBox).ID ', but i want to save just the two Similar parts of the textboxs ids' 'i am not sure if this completely correct, but i wanted to do something like it[' Dim partOFtxt As String = allItems[Last_Item_Saved_Index] Dim txt As Decimal = (partOFtxt + "_done.Text") / (partOFtxt + "_target.Text") (partOFtxt + "_Result.Text") = "%" + FormatNumber(txt, 2, TriState.False) ']' 'end condition' Exit Select Case Else Exit Select End Select Next i hope that you get the idea.. if you have a better idea ... it would be nice.. Thanks in advance..

    Read the article

  • Can't insert a number into a C++ custom streambuf/ostream

    - by 0xbe5077ed
    I have written a custom std::basic_streambuf and std::basic_ostream because I want an output stream that I can get a JNI string from in a manner similar to how you can call std::ostringstream::str(). These classes are quite simple. namespace myns { class jni_utf16_streambuf : public std::basic_streambuf<char16_t> { JNIEnv * d_env; std::vector<char16_t> d_buf; virtual int_type overflow(int_type); public: jni_utf16_streambuf(JNIEnv *); jstring jstr() const; }; typedef std::basic_ostream<char16_t, std::char_traits<char16_t>> utf16_ostream; class jni_utf16_ostream : public utf16_ostream { jni_utf16_streambuf d_buf; public: jni_utf16_ostream(JNIEnv *); jstring jstr() const; }; // ... } // namespace myns In addition, I have made four overloads of operator<<, all in the same namespace: namespace myns { // ... utf16_ostream& operator<<(utf16_ostream&, jstring) throw(std::bad_cast); utf16_ostream& operator<<(utf16_ostream&, const char *); utf16_ostream& operator<<(utf16_ostream&, const jni_utf16_string_region&); jni_utf16_ostream& operator<<(jni_utf16_ostream&, jstring); // ... } // namespace myns The implementation of jni_utf16_streambuf::overflow(int_type) is trivial. It just doubles the buffer width, puts the requested character, and sets the base, put, and end pointers correctly. It is tested and I am quite sure it works. The jni_utf16_ostream works fine inserting unicode characters. For example, this works fine and results in the stream containing "hello, world": myns::jni_utf16_ostream o(env); o << u"hello, wor" << u'l' << u'd'; My problem is as soon as I try to insert an integer value, the stream's bad bit gets set, for example: myns::jni_utf16_ostream o(env); if (o.badbit()) throw "bad bit before"; // does not throw int32_t x(5); o << x; if (o.badbit()) throw "bad bit after"; // throws :( I don't understand why this is happening! Is there some other method on std::basic_streambuf I need to be implementing????

    Read the article

  • How to change PHP's eregi to preg_match

    - by jasondavis
    I need help, below is a small VERY basic regex to somewhat validate an email, I do realize it does not work the greatest but for my needs it is ok for now. It currently uses PHP's eregi function which php.net says is now a depreciated function and I should use preg_match instead, simply replacing erei with preg_match does not work, can someone show me how to make it work? function validate_email($email) { if (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $email)) { echo 'bad email'; } else { echo 'good email'; } } function validate_email($email) { if (!preg_match("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $email)) { echo 'bad email'; } else { echo 'good email'; } }

    Read the article

  • How to mock/stub a directory of files and their contents using RSpec?

    - by John Topley
    A while ago I asked "How to test obtaining a list of files within a directory using RSpec?" and although I got a couple of useful answers, I'm still stuck, hence a new question with some more detail about what I'm trying to do. I'm writing my first RubyGem. It has a module that contains a class method that returns an array containing a list of non-hidden files within a specified directory. Like this: files = Foo.bar :directory => './public' The array also contains an element that represents metadata about the files. This is actually a hash of hashes generated from the contents of the files, the idea being that changing even a single file changes the hash. I've written my pending RSpec examples, but I really have no idea how to implement them: it "should compute a hash of the files within the specified directory" it "shouldn't include hidden files or directories within the specified directory" it "should compute a different hash if the content of a file changes" I really don't want to have the tests dependent on real files acting as fixtures. How can I mock or stub the files and their contents? The gem implementation will use Find.find, but as one of the answers to my other question said, I don't need to test the library. I really have no idea how to write these specs, so any help much appreciated!

    Read the article

  • Ignoring (serious) errors to keep the program alive?

    - by SQuirreL bites
    One of the main things I wanted to achieve in my experimental programming language was: When errors occur (Syntax, Name, Type, etc.) keep the program running, no matter how serious or devastating it is. I know that this is probably very bad, but I just wanted something that doesn't kill itself on every error - I find it interesting what happens when a serious error occurs but the program continues. Does this "paradigm" have a name? I mean expect for How bad is it to do the above? Are there programs in use out there that just follow: "Hey, this is a fatal, unexpected error - but you know what? I don't care!"?

    Read the article

  • Improve SQL strategy - denormalize in object-children-images case

    - by fesja
    Hi, I have a Tour object which has many Place objects. For the list of tours, I want to show some info of the tour, the number of places of the tour, and three Place's images. Right one my SQL queries are (i'm using Doctrine with Symfony on MySQL) get Tour get Tour 1 places get Tour 2 places get Tour 3 places ... get Tour n places If I have a three Tour list, it's not so bad; but I'm sure it can get bad if I do a 10-20 tour-list. So, thinking on how to improve the queries I've thought of several measures: Having a place count cache Storing the urls of three images on a new tour field. The problem with 2. is that if I change the image, I have to check all the tours to update that image for another one. What solution do you think is best to scale the system in a near future? Any other suggestion. thanks!

    Read the article

  • Links in rounded boxes? In ALL browsers (yep included IE8)

    - by raffaello123
    I tried maaaany script but every time I get stuck in something bad. My goal is to create rounded boxes for links. You can see an example of I'm talking about here in the read more link (effects not necessary). Very common I know, but I want to make it work in eeeevery browsers at least safari, FF, chrome and most important IE7+ (IE6 not necessary...). The script that took me closest to the solution is Cornerz but I can't fix a very bad issue on IE8. Does anybody knows a way to get rid of this or to achieve my goal? Thank you I appreciate every support. Cheers

    Read the article

  • Double use of variables?

    - by Vaccano
    I have read that a variable should never do more than one thing. Overloading a variable to do more than one thing is bad. Because of that I end up writing code like this: (With the customerFound variable) bool customerFound = false; Customer foundCustomer = null; if (currentCustomer.IsLoaded) { if (customerIDToFind = currentCustomer.ID) { foundCustomer = currentCustomer; customerFound = true; } } else { foreach (Customer customer in allCustomers) { if (customerIDToFind = customer.ID) { foundCustomer = customer; customerFound = true; } } } if (customerFound) { // Do something } But deep down inside, I sometimes want to write my code like this: (Without the foundCustomer variable) Customer foundCustomer = null; if (currentCustomer.IsLoaded) { if (customerIDToFind = currentCustomer.ID) { foundCustomer = currentCustomer; } } else { foreach (Customer customer in allCustomers) { if (customerIDToFind = customer.ID) { foundCustomer = customer; } } } if (foundCustomer != null) { // Do something } Does this secret desires make me an evil programmer? (i.e. is the second case really bad coding practice?)

    Read the article

  • Serializing an extended form object

    - by andyperfect
    I've been reading up on this whole subject, but I never came across this specific problem. I already understand that the whole idea of serializing an entire form is a horrible idea and just doesn't work. But, I am encountering a bit of a different problem. I have a class that inherits the "button" form object, that I call DataButton. Now for my problem. I want to be able to serialize this class, but I don't need any of the information from the actual button class. Is there any way to bypass the fact that I can't set the button form object to Serializable() and notify VB that when serialization is to occur, it should simply skip over that information? Theoretically, if such a procedure were possible, I'd be able to do the entire serialization without a hitch. I came up with the idea earlier of removing the "inherits" feature from the class, and having simply a button within the class, but that makes my program really difficult to work with as I am constantly changing the location, size, backgroundImage, text, and whatnot. Thus, immediate updates would be much tougher to work with. Any help would be greatly appreciated.

    Read the article

  • Function to identify problematic datatypes

    - by Zach
    I just spent several hours debugging some R code, only to discover that the error was due to an Inf that had sneaked in during my calculations. I had checked for NA, but hadn't thought to check for Inf. I wrote the following function to help prevent this situation in the future: is.bad <- function(x){ is.na(x) | is.nan(x) | is.infinite(x) } > is.bad(c(NA, NaN, Inf, -Inf, 0, 1, 1000, 1e6)) [1] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE Are there any other special data types in R I should be aware of?

    Read the article

  • Identity alternative for SQL Azure Federation : are Azure Queues or Service Bus Queues a good choice?

    - by JYL
    As many of developers, I'm looking for a way to integrate my existing app to SQL Azure Federations, and replacing the Identity columns (the primary keys of my tables) is a big problem. For many reasons, I do NOT want use GUID for my primary keys (please don't open the debate about the GUID or not, it's not my question : i just don't want a GUID, period). So I need to build a key provider to replace the "identity" feature of a standard SQL database. I'm using Entity Framework, so i can easily find one place to set the Id value just before the insert (by overriding the SaveChanges method of my ObjectContext class). I just need to find a "not too complicated" implementation for getting the current Id, which is "farm-ready". I've read this SO post : "ID Generation for Sharded Database (Azure Federated Database)" and "Synchronizing Multiple Nodes in Windows Azure from MSDN Magazine", but this solution sounds a bit complicated for me. I'm thinking about creating (automatically) one azure queue for each SQL table, which contain a pre-loaded list of consecutive integer. When I want an Id value, I just have to get a message from the queue (which becomes invisible and is deleted on the way), which give me the current available Id. About the choice between "Windows Azure Queues" and "Windows Azure Service Bus Queues", I prefere "Windows Azure Queues", due to the "high" latency of Service Bus Queues. I don't think that the lack of "ordering garantee" of Azure Queues is a problem. What do you think about that idea of using Azure Queues to provide Id values ? Do you see any argument to give up that idea ? Do you have a better idea, or even a good practice, to provider integer ids in SQL Azure Federation databases ? Thanks.

    Read the article

  • What should I use to replace the WinAPI Beep() function?

    - by Jon Cage
    I've got a Visual C++/CLI app which uses beeps to signify good and bad results (used when the user can't see the screen). Currently I use low pitched beeps for bad results and high pitched beeps for good results: if( goodResult == true ) { Beep(1000, 40); } else { Beep(2000, 20); } This works okay on my Vista laptop, but I've tried it on other laptops and some seem to play the sounds for less time (they sound more like clicks than beeps) or the sound doesn't play at all. So I have two questions here: Is there a more reliable beep function? Is there a (simple) way I can play a short .wav file or something similar instead (preferred solution).

    Read the article

  • Is there anything wrong with taking immediate actions in constructors?

    - by pestaa
    I have classes like this one: class SomeObject { public function __construct($param1, $param2) { $this->process($param1, $param2); } ... } So I can instantly "call" it as some sort of global function just like new SomeObject($arg1, $arg2); which has the benefits of staying concise, being easy to understand, but might break unwritten rules of semantics by not waiting till a method is called. Should I continue to feel bad because of a bad practice, or there's really nothing to worry about? Clarification: I do want an instance of the class. I do use internal methods of the class only. I initialize the object in the constructor, but call the "important" action-taker methods too. I am selfish in the light of these sentences.

    Read the article

  • Read from file into pointer to struct

    - by cla barzu
    I need help with pointers in C. I have to read from a file, and fill an array with pointers to struct rcftp_msg . Since now I did the next things: struct rcftp_msg { uint8_t version; uint8_t flags; uint16_t len; uint8_t buffer[512]; }; struct rcftp_msg *windows [10]; pfile = fopen(file,"r"); // Open the file I have to read from the file into the buffer, but I don't know how to do it. I tried the next: for (i = 0; i <10; i++){ leng=fread (**windows[i]->buffer**,sizeof(uint8_t),512,pfile); } I think windows[i]-buffer is bad, cuz that don't work. Sorry for my bad English :(

    Read the article

  • the use of private keyword

    - by LAT
    Hi everyone I am new to programming. I am learning Java now, there is something I am not really sure, that the use of private. Why programmer set the variable as private then write , getter and setter to access it. Why not put everything in public since we use it anyway. public class BadOO { public int size; public int weight; ... } public class ExploitBadOO { public static void main (String [] args) { BadOO b = new BadOO(); b.size = -5; // Legal but bad!! } } I found some code like this, and i saw the comment legal but bad. I don't understand why, please explain me.

    Read the article

  • Need help in sorting the programming buzz-words

    - by cwap
    How do you sort out the good buzz from the bad buzz? - I really need your help here :) I see a lot of buzz-words nowadays, both here on SO and in school. For example, we had a teacher who everyone respected, who said "be careful about gold-plating and death-by-interfacing". Now, everyone and their mama cries whenever I'm creating an interface.. Another example would be here on SO where lately "premature optimization is the root of all evil", so everytime someone asks a perfomance question, he'll get that sentence thrown in his face. A few months ago I remember it was all about NHibernate in here, etc., etc... These things comes and goes, but only the good buzz stays. Now, how do you seperate the good from the bad? By reading blogs from respected persons? By trying to come to a conclusion on your own, and then try to convince others that you're right? By simply ignoring it?

    Read the article

  • Failing faster when URL content is not found, howto

    - by Jam
    I have a thread pool that loops over a bunch of pages and checks to see if some string is there or not. If String is found, or not found response is near instant, however if server is offline or application is not running getting a rejection seems to take seconds How can I change my code to fail faster? for (Thread thread : pool) { thread.start(); } for (Thread thread : pool) { try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } Here is my run method @Override public void run() { for (Box b : boxes) { try { connection = new URL(b.getUrl()).openConnection(); scanner = new Scanner(connection.getInputStream()); scanner.useDelimiter("\\Z"); content = scanner.next(); if (content.equals("YES")) { } else { System.out.println("\tFAILED ON " + b.getName() + " BAD APPLICATION STATE"); } } catch (Exception ex) { System.out.println("\tFAILED ON " + b.getName() + " BAD APPLICATION STATE"); } } }

    Read the article

  • What makes my code DDD (domain-driven design) qualified?

    - by oykuo
    Hi All, I'm new to DDD and am thinking about using this design technique in my project. However, what strikes me about DDD is that how basic the idea is. Unlike other design techniques such as MVC and TDD, it doesn't seems to contain any ground breaking ideas. For example, I'm sure some of you will have the same feeling that the idea of root aggregates and repositories are nothing new because when you are was writing MVC web applications you have to have one single master object (i.e. the root aggregate) that contain other minor objects (i.e. value objects and entities) in the model layer in order to send data to a strongly typed view. To me, the only new idea in DDD is probably the "Smart" entities (i.e. you are supposed to have business rules on root aggregates) Separation between value object, root aggregate and entities. Can anyone tell me if I have missed out anything here? If that's all there is to DDD, if I update one of my existing MVC application with the above 2 new ideas, can I claim it's an TDD, MVC and DDD applcation?

    Read the article

  • Is there an efficient way to figure out the headers, cookies, and get/post data being passed to a si

    - by kryptobs2000
    More specifically I'm looking for something, perhaps an add-on for firefox, once enabled it logs all of this information as it's passed to and from the server. I'm doing some web scripting and this would be really handy. If anyone is wondering specifically what I'm doing currently I'm trying to make a script to repost my craigslist ad every 2 days since I handle a few things on there. Might even go so far as to make a simple gui to manage the submissions. I do suspect this goes against the ToS, for that reason I don't plan to release the code. Besides cl is already bad enough with spam, I'm not trying to contribute further to it, figured I'd say what I'm doing for the sake of being honest though. I don't have any bad intentions with this, just some things I've been trying to sell an ad for my pc repair business. I've been reposting some things for months now and so often I just forget to do it.

    Read the article

  • How would you structure your workflow for a web application ?

    - by cx42net
    Hi ! When designing a web application (or something else), it's good to have a workflow, and it's better to have a well ordered one. Starting with this idea in mind, I'd like to know what is your process from having an idea to maintain this great working project. For me actually, the process is the following one : Having the idea Checking this project already exists, and how it works Describing on a paper its functionalities finding a good and adequate name for this (and checking the domain availability with WHOISMyProject) Making a quick layout of the project on a paper Designing the project (via TheGimp, Photoshop, etc) Making a complete mockup of each pages Developing a prototype of the client-side application (with false datas) Developing the server side Testing Making the documentation/help/faq Releasing the project Maintaining it. Would you change the order of some points ? add/remove some ? I would please to know how you do that. I'm looking to set up a perfect workflow in order to make my project become real in the best way possible. Thank you for your opinion !

    Read the article

< Previous Page | 96 97 98 99 100 101 102 103 104 105 106 107  | Next Page >