Search Results

Search found 3659 results on 147 pages for 'sorted hash'.

Page 107/147 | < Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >

  • How do I handle a missing mandatory argument in Ruby OptionParser?

    - by Rob Jones
    In OptionParser I can make an option mandatory, but if I leave out that value it will take the name of any following option as the value, screwing up the rest of the command line parsing. Here is a test case that echoes the values of the options: $ ./test_case.rb --input foo --output bar output bar input foo Now leave out the value for the first option: $ ./test_case.rb --input --output bar input --output Is there some way to prevent it taking another option name as a value? Thanks! Here is the test case code: #!/usr/bin/env ruby require 'optparse' files = Hash.new option_parser = OptionParser.new do |opts| opts.on('-i', '--input FILENAME', 'Input filename - required') do |filename| files[:input] = filename end opts.on('-o', '--output FILENAME', 'Output filename - required') do |filename| files[:output] = filename end end begin option_parser.parse!(ARGV) rescue OptionParser::ParseError $stderr.print "Error: " + $! + "\n" exit end files.keys.each do |key| print "#{key} #{files[key]}\n" end

    Read the article

  • Confused by Perl grep function

    - by titaniumdecoy
    I don't understand the last line of this function from Programming Perl 3e. Here's how you might write a function that does a kind of set intersection by returning a list of keys occurring in all the hashes passed to it: @common = inter( \%foo, \%bar, \%joe ); sub inter { my %seen; for my $href (@_) { while (my $k = each %$href) { $seen{$k}++; } } return grep { $seen{$_} == @_ } keys %seen; } I understand that %seen is a hash which maps each key to the number of times it was encountered in any of the hashes provided to the function.

    Read the article

  • How can I make Rails 3 router to localize url's using localization files?

    - by edgerunner
    What I'd like to be able to do is: in config/routes.rb resources :posts in config/locale/en.yml en: resources: posts: "posts" new: "new" edit: "edit" in config/locale/tr.yml tr: resources: posts: "yazilar" new: "yeni" edit: "duzenle" and get I18n.locale = :en edit_post_path(3) #=> /posts/3/edit I18n.locale = :tr edit_post_path(3) #=> /yazilar/3/duzenle I'd also like rails to match any of these routes anytime and pass the associated locale in the params hash such that when I navigate to /yazilar , the request should be routed to the posts#index action. Any simple way of doing that?

    Read the article

  • Is there any simple way to test two PNGs for equality?

    - by Mason Wheeler
    I've got a bunch of PNG images, and I'm looking for a way to identify duplicates. By duplicates I mean, specifically, two PNG files whose uncompressed image data are identical, not necessarily whose files are identical. This means I can't do something simple like compare CRC hash values. I figure this can actually be done reliably since PNGs use lossless compression, but I'm worried about speed. I know I can winnow things down a little by testing for equal dimensions first, but when it comes time to actually compare the images against each other, is there any way to do it reasonably efficiently? (ie. faster than the "double-for-loop checking pixel values against each other" brute-force method?)

    Read the article

  • Does it take time to deallocate memory?

    - by jm1234567890
    I have a C++ program which, during execution, will allocate about 3-8Gb of memory to store a hash table (I use tr1/unordered_map) and various other data structures. However, at the end of execution, there will be a long pause before returning to shell. For example, at the very end of my main function I have std::cout << "End of execution" << endl; But the execution of my program will go something like $ ./program do stuff... End of execution [long pause of maybe 2 min] $ -- returns to shell Is this expected behavior or am I doing something wrong? I'm guessing that the program is deallocating the memory at the end. But, commercial applications which use large amounts of memory (such as photoshop) do not exhibit this pause when you close the application. Please advise :)

    Read the article

  • Filesystem synchronization library?

    - by IsaacB
    Hi, I've got 10 GB of files to back up daily to another site. The client is way out in the country so bandwidth is an issue. Does anyone know of any existing software or libraries out there that help with keeping a folder with its files synchronized across a slow link, that is it only sends files across if they have changed? Some kind of hash checking would be nice, too, to at least confirm the two sides are the same. I don't mind paying some money for it, seeing as how it might take me several weeks to a month to implement something decent on my own. I just don't want to re-invent the wheel, here. BTW it is a windows shop (they have an in house windows IT guy) so windows is preferred. I also have 10 GB of SQL Server 2000 databases to go across. Is the SQL server replication mode reliable? Thanks!

    Read the article

  • Prototype.js: How can i return an array without all the methods Prototypes extends Array with?

    - by Morten
    Hi! Is there a way to return a new version of an array/hash that does not contain all the methods/functions that prototype extends the array object with? Example: var myArray = $A(); myArray['test'] = '1'; myArray['test2'] = '2'; var myVariableToPassToAjax = myArray; If I debug myVariableToPassToAjax it looks like this: Array ( [test] = 1 [test2] = 2 [each] = function each(iterator, context) { .......... .......... } ...and all the other extended array functions ); Is there a way to solve this? :-/ Morten

    Read the article

  • Rails: translations for table's column.

    - by Andrew
    In rails application I have two models: Food and Drink. Both food and drink have a name, which has to be stored in two languages. How do I better realize translations for theese tables? First solution I realized was to replace name column with name_en and name_ru. Another solution is to encode with YAML hash like { :en => 'eng', :ru => 'rus' } and store yaml as a name. What would you recommend, assuming content is not static? Maybe there's good article?

    Read the article

  • Perl XML::Simple XMLout function

    - by Jeremey
    I pass in the following XML to XMLin: <root foo="bar" foo2="bar2"> <pizzas> <pizza>Pepperoni</pizza> </pizzas> </root> I then edit part of the root element via hash array. I don't care about the pizza, but i do need that XML to come back out exactly as it was. However, I get the following from XMLout: <root foo="bar" foo2="bar2"> <pizzas pizza="Pepperoni"</pizzas> </root> Thoughts?

    Read the article

  • Connecting a network printer via a Thecus N2100 - works in Vista, not in Windows 7

    - by Jon Skeet
    I have a Lexmark E250d printer attached to a Thecus N2100 NAS. On Windows Vista I've managed to configure this using an "Internet" printer port with the URL of http://thecus:631/printers/usb-printer. I can add a printer in a similar way in Windows 7, but it never manages to print the test page. If I go to "Configure Port" in Vista, it just has "Security Options" - on Windows 7 it's asking about Raw mode vs LPR mode etc. On Vista I'm using an E250d-specific driver from Lexmark; on Windows 7 there's a Microsoft E250d driver, or a Universal PCL XL driver from Lexmark... I wouldn't expect this different to be related to the problem, but I thought I'd mention it anyway. (Lexmark doesn't have a Windows 7 E250d-specific driver as far as I can see.) Any suggestions? I was thinking of upgrading my main laptop from Vista to Windows 7, but I'd really like to get this sorted first... EDIT: If I connect to http://thecus:631/printers/usb-printer via Chrome while capturing with Wireshark, I get this response: HTTP/1.1 200 OK Date: Wed, 06 Jan 2010 16:47:23 GMT Connection: Keep-Alive Keep-Alive: timeout=60 Content-Language: C Transfer-Encoding: chunked Content-Type: text/html;charset=iso-8859-1 0 No idea what that's meant to be doing... EDIT: On further consultation, this would appear to be the Internet Printing Protocol which is layered on HTTP. Printing a test page successfully from Vista posts to that URL. Will attempt the same on Windows 7...

    Read the article

  • MAD method compression function

    - by Jacques
    I ran across the question below in an old exam. My answers just feels a bit short and inadequate. Any extra ideas I can look into or reasons I have overlooked would be great. Thanx Consider the MAD method compression function, mapping an object with hash code i to element [(3i + 7)mod9027]mod6000 of the 6000-element bucket array. Explain why this is a poor choice of compression function, and how it could be improved. I basically just say that the function could be improved by changing the value for p (or 9027) to an prime number and choosing an other constant for a (or 3) could also help.

    Read the article

  • Server authorization with MD5 and SQL.

    - by Charles
    I currently have a SQL database of passwords stored in MD5. The server needs to generate a unique key, then sends to the client. In the client, it will use the key as a salt then hash together with the password and send back to the server. The only problem is that the the SQL DB has the passwords in MD5 already. Therefore for this to work, I would have to MD5 the password client side, then MD5 it again with the salt. Am I doing this wrong, because it doesn't seem like a proper solution. Any information is appreciated.

    Read the article

  • What is the most efficient Java Collections library?

    - by dehmann
    What is the most efficient Java Collections library? A few years ago, I did a lot of Java and had the impression back then that trove is the best (most efficient) Java Collections implementation. But when I read the answers to the question "Most useful free Java libraries?" I noticed that trove is hardly mentioned. So which Java Collections library is best now? UPDATE: To clarify, I mostly want to know what library to use when I have to store millions of entries in a hash table etc. (need a small runtime and memory footprint).

    Read the article

  • Cherrypicking versus Rebasing

    - by Lakshman Prasad
    The following is a scenario I commonly face: You have a set of commits on master or design, that I want to put on top of production branch. I tend to create a new branch with the base as production cherry-pick these commits on it and merge it to production Then when I merge master to production, I face merge conflicts because even tho the changes are same, but are registered as a different commit because of cherry-pick. I have found some workarounds to deal with this, all of which are laborious and can be termed "hacks". Altho' I haven't done too much rebasing, I believe that too creates a new commit hash. Should I be using rebasing where I am cherrypicking. What other advantages does that have over this.

    Read the article

  • How to call a Thor task multiple times?

    - by deepak
    Thor like Rake (and Make) has task management. If I call a task multiple times, it will effectively call the task only once. How can I call a task multiple times? I tried modifying the @_invocations hash, but that did not work: require 'csv' require './config/environment' class MisReport < Thor desc "all", "generate mysql and postgres mis" def all generate("pg_mis_report", "pg") generate("mysql_mis_report", "mysql") end desc "generate", "generate mis report" def generate(file_name = "mis_report_#{Time.now.to_s(:number)}", connection = "postgres") if connection == "pg" puts "== postgres database" ActiveRecord::Base.establish_connection :development_mysql else puts "== mysql database" ActiveRecord::Base.establish_connection :development end # generate MIS puts puts "mis file is at: #{file_path}" end end

    Read the article

  • What applications do people use for windows folder management? How do you switch between folders in

    - by 118184489189799176898
    I'm always switching between client's folders in different applications like photoshop, sql manager, explorer etc. It's so slow to go between them, navigate to the folder and it's still too slow to copy and paste the directory etc. It's so annoying to do. Someone must have a good solution. I was thinking if there was a "recently accessed" folders list available within every folder explorer window... so in any application, if i go "file open" it will have something, somewhere that lists the recently accessed folders - that would be really helpful. I am aware of the recent places folder in win7, but this sucks because it is not sorted by date accessed. Perhaps if there was a way to change this then this would become a decent feature? Is there some application that already does this? i'm sure someone has already solved this issue in a more elegant solution than I can think off. I'm keen to know what programs people use or how people addresss this issue? Thanks...

    Read the article

  • jQuery .animate chains, callbacks, and .stop(true, true)

    - by JKS
    So I have a animation chain (.animate().animate().animate()), and on the last .animate(), there is a callback to do some clean-up. The animation is triggered by the hash in the address changing (#page1, #page2, etc.) -- so when the user changes the history state rapidly, if there is a currently executing animation, it needs to stop so they don't queue up. The problem is, if I add a .stop(true, true), it appears only to jump to end of the currently running animation -- and executes only its callback, if there is one. What I need is for it to jump to the end of all of the chained animations, and fire all of the callbacks (well, really just the last one). Is this possible somehow? Huge thanks.

    Read the article

  • OpenID and Authlogic - login and password?

    - by skrat
    How can I get rid of validation messages telling me that: Login is too short (minimum is 3 characters) Login should use only letters, numbers, spaces, and .-_@ please. Password is too short (minimum is 4 characters) Password confirmation is too short (minimum is 4 characters) this happens even before map_openid_registration is called, thus not giving me any chance to fill login with something from returned registration Hash. I would like to have OpenID auto-registration (on login) without requiring user to supply login/password. I also won't make this fields "not required" or "not validated", since I still need them with old school login/password registration. Thank you

    Read the article

  • What's the best general programming book to review basic development concepts?

    - by Charles S.
    I'm looking for for a programming book that reviews basic concepts like implementing linked lists, stacks, queues, hash tables, tree traversals, search algorithms, etc. etc. Basically, I'm looking for a review of everything I learned in college but have forgotten. I prefer something written in the last few years that includes at least a decent amount of code in object-oriented languages. This is to study for job interview questions but I already have the "solving interview questions" books. I'm looking for something with a little more depth and explanation. Any good recommendations?

    Read the article

  • Hardware issue: computer plays beep sounds at startup, and then turns off

    - by Darkkurama
    Turns out that after moving, my computer got damaged somehow. I installed my computer 2 days ago. I didn't check the state of the hardware parts and turned the pc on recklessly, not realizing that the cpu fan was dettached from the cpu. After this I reattached the fan. The computer worked kind of faulty after that, because at the time of startup, it would play a long beep (different from the normal beep) and won't display anything. I tried restarting after this incident and it got fixed (don't know how, but it did), and I was even able to play some videogames for some hours (more than 5). This morning I tried to get this issue sorted out by checking again the cpu and in general, the connections, and for my surprise, at the time of turning it on again, the computer wouldn't boot at all. I reapplied some thermal paste to the cpu and fan, but got no results (I did this because the old paste was very badly distributted along the surface of both cpu and fan). Now every time I turn it on, the computer acts randomly: sometimes at startup, it plays a long continous beep and then turns off. one time it played a long continous beep and got to the windows password input screen, but then it turned off More frequently, I turn it on and after some seconds, it turns off without any sound. You can check this video I recorded, which features how the computer behaves most of the time Another one I tried troubleshoting it myself by disconnecting my graphic card, rams, HDD and even the cpu and its fan with no result. Computer specs: Intel Core 2 Quad Q6600 processor, Nvidia xfx gtx 260 black edition, 4 GB ram, 500 GB hard drive, Windows 7 64 bit

    Read the article

  • Complex queries using Rails query language

    - by Daniel Johnson
    I have a query used for statistical purposes. It breaks down the number of users that have logged-in a given number of times. User has_many installations and installation has a login_count. select total_login as 'logins', count(*) as `users` from (select u.user_id, sum(login_count) as total_login from user u inner join installation i on u.user_id = i.user_id group by u.user_id) g group by total_login; +--------+-------+ | logins | users | +--------+-------+ | 2 | 3 | | 6 | 7 | | 10 | 2 | | 19 | 1 | +--------+-------+ Is there some elegant ActiveRecord style find to obtain this same information? Ideally as a hash collection of logins and users: { 2=>3, 6=>7, ... I know I can use sql directly but wanted to know how this could be solved in rails 3.

    Read the article

  • Monotone-increasing Version Number based on Mercurial Commits

    - by Isaac
    When I was using subversion for the code for an application, I could append a period and the result of svnversion to the version number to create a unique and monotone-increasing version number and also be guaranteed that any check-out of the same revision of the code would generate the same version number. In Mercurial, because revision numbers are not necessarily consistent across clones, the local revision number is not suitable. The hash is appropriately unique and consistent, but does not create a number that is monotone-increasing. How can I generate a suitable number to append to the version number based on the Mercurial repository commits?

    Read the article

  • Aging Data Structure in C#

    - by thelsdj
    I want a data structure that will allow querying how many items in last X minutes. An item may just be a simple identifier or a more complex data structure, preferably the timestamp of the item will be in the item, rather than stored outside (as a hash or similar, wouldn't want to have problems with multiple items having same timestamp). So far it seems that with LINQ I could easily filter items with timestamp greater than a given time and aggregate a count. Though I'm hesitant to try to work .NET 3.5 specific stuff into my production environment yet. Are there any other suggestions for a similar data structure? The other part that I'm interested in is aging old data out, If I'm only going to be asking for counts of items less than 6 hours ago I would like anything older than that to be removed from my data structure because this may be a long-running program.

    Read the article

  • Ways to have audio output without wires

    - by viraptor
    I'm trying to find a way of using my home speakers/amp without actually having to connect them. There are two laptops that use them normally (so I don't like changing the connection all the time) and I'd rather move the speakers to a place that's away from the couch. I'm not sure how to do this though... The options I can think of are: some kind of wireless jack-jack connection finally getting a media server Unfortunately I can't find any good product for the first solution. I've seen some headphones which have the receiver integrated and a separate transmitted, so in general the idea is already out there, just not the way I need ;) I've seen also http://www.miccus.com/products/blubridge-mini-jack, but I'd have to have a compatible receiver which I can't find on its own (maybe there's some application that the media server could use?). As far as media server goes... many of the plug servers look really interesting, but I'm not sure how to create an audio output and how to redirect the input really. None of the plug servers I've seen so far advertises the option of audio output jack port. I think this part could be fixed by getting one with an usb port and a separate cheap usb soundcard. I hope that input can be sorted out in some rather simple way. I've got Linux running on both laptops so I hope that would be possible to configure jack/pulse/whatever to use the remote endpoint, or even write a simple local-/dev/dsp:network:media-server-/dev/dsp forwarder. So the main question is... are there better ways? Are there any out of the box solutions? Or maybe this was already done by someone and described somewhere?

    Read the article

  • What CPAN module can summarize error logs?

    - by mithaldu
    I'm maintaining some website code that will soon dump all its errors and warnings into a log file. In order to make this a bit more pro-active i plan to parse this log file daily, summarize the warnings and errors (i.e. count the occurrence of each specific one and group by either warning/error) and then email this to the devs on the project. This would likely admittedly be rather trivial with a hash and some further fiddling, I wondered if there is a suitable module on CPAN that i could use to do this task. It would either be one that summarizes specifically perl error/warnings logs or one that summarizes arbitrary text files. Any suggestions?

    Read the article

< Previous Page | 103 104 105 106 107 108 109 110 111 112 113 114  | Next Page >