Search Results

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

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

  • perl hashes - comparing keys and values

    - by Aaron Moodie
    I've been reading over the perl doc, but I can't quite get my head around hashes. I'm trying to find if a hash key exists, and if so, compare is't value. The thing that is confusing me is that my searches say that you find if a key exists by if (exists $files{$key}) , but that $files{$key} also gives the value? the code i'm working on is: foreach my $item(@new_contents) { next if !-f "$directory/$item"; my $date_modified = (stat("$directory/$item"))[9]; if (exists $files{$item}) { if ($files{$item} != $date_modified { $files{$item} = $date_modified; print "$item has been modified\n"; } } else { $files{$item} = $date_modified; print "$item has been added\n"; } }

    Read the article

  • javascript to launch only ONE window for a Java applet with a given URL

    - by Jonathan Dugan
    I need a javascript solution to launch only one window, with a Java Applet in it, for a given URL. I found a solution posted here on Stack Overflow - here: http://stackoverflow.com/questions/528671/javascript-window-open-only-if-the-window-does-not-already-exist But it doesn't seem to work .. I get Error: launchApplication.winrefs is undefined Line: 29 I can't seem to post the code in this little box and make it look right below, so the code (my working code, plus the solution from above) is here: http://pastie.org/833879 Where is the error? As I understand it, the hash or array or whatever I use to store the called references to the windows opened this way will be lost if the calling window is closed. Is there a way to make this work even if the calling window is closed and reopened? To basically ask the browser: "Do you have a window open with the following URL?" and if so, "What is the reference to that window?" (so I can raise it).

    Read the article

  • Array sorting efficiency... Beginner need advice

    - by SoleSoft
    I'll start by saying I am very much a beginner programmer, this is essentially my first real project outside of using learning material. I've been making a 'Simon Says' style game (the game where you repeat the pattern generated by the computer) using C# and XNA, the actual game is complete and working fine but while creating it, I wanted to also create a 'top 10' scoreboard. The scoreboard would record player name, level (how many 'rounds' they've completed) and combo (how many buttons presses they got correct), the scoreboard would then be sorted by combo score. This led me to XML, the first time using it, and I eventually got to the point of having an XML file that recorded the top 10 scores. The XML file is managed within a scoreboard class, which is also responsible for adding new scores and sorting scores. Which gets me to the point... I'd like some feedback on the way I've gone about sorting the score list and how I could have done it better, I have no other way to gain feedback =(. I know .NET features Array.Sort() but I wasn't too sure of how to use it as it's not just a single array that needs to be sorted. When a new score needs to be entered into the scoreboard, the player name and level also have to be added. These are stored within an 'array of arrays' (10 = for 'top 10' scores) scoreboardComboData = new int[10]; // Combo scoreboardTextData = new string[2][]; scoreboardTextData[0] = new string[10]; // Name scoreboardTextData[1] = new string[10]; // Level as string The scoreboard class works as follows: - Checks to see if 'scoreboard.xml' exists, if not it creates it - Initialises above arrays and adds any player data from scoreboard.xml, from previous run - when AddScore(name, level, combo) is called the sort begins - Another method can also be called that populates the XML file with above array data The sort checks to see if the new score (combo) is less than or equal to any recorded scores within the scoreboardComboData array (if it's greater than a score, it moves onto the next element). If so, it moves all scores below the score it is less than or equal to down one element, essentially removing the last score and then places the new score within the element below the score it is less than or equal to. If the score is greater than all recorded scores, it moves all scores down one and inserts the new score within the first element. If it's the only score, it simply adds it to the first element. When a new score is added, the Name and Level data is also added to their relevant arrays, in the same way. What a tongue twister. Below is the AddScore method, I've added comments in the hope that it makes things clearer O_o. You can get the actual source file HERE. Below the method is an example of the quickest way to add a score to follow through with a debugger. public static void AddScore(string name, string level, int combo) { // If the scoreboard has not yet been filled, this adds another 'active' // array element each time a new score is added. The actual array size is // defined within PopulateScoreBoard() (set to 10 - for 'top 10' if (totalScores < scoreboardComboData.Length) totalScores++; // Does the scoreboard even need sorting? if (totalScores > 1) { for (int i = totalScores - 1; i > - 1; i--) { // Check to see if score (combo) is greater than score stored in // array if (combo > scoreboardComboData[i] && i != 0) { // If so continue to next element continue; } // Check to see if score (combo) is less or equal to element 'i' // score && that the element is not the last in the // array, if so the score does not need to be added to the scoreboard else if (combo <= scoreboardComboData[i] && i != scoreboardComboData.Length - 1) { // If the score is lower than element 'i' and greater than the last // element within the array, it needs to be added to the scoreboard. This is achieved // by moving each element under element 'i' down an element. The new score is then inserted // into the array under element 'i' for (int j = totalScores - 1; j > i; j--) { // Name and level data are moved down in their relevant arrays scoreboardTextData[0][j] = scoreboardTextData[0][j - 1]; scoreboardTextData[1][j] = scoreboardTextData[1][j - 1]; // Score (combo) data is moved down in relevant array scoreboardComboData[j] = scoreboardComboData[j - 1]; } // The new Name, level and score (combo) data is inserted into the relevant array under element 'i' scoreboardTextData[0][i + 1] = name; scoreboardTextData[1][i + 1] = level; scoreboardComboData[i + 1] = combo; break; } // If the method gets the this point, it means that the score is greater than all scores within // the array and therefore cannot be added in the above way. As it is not less than any score within // the array. else if (i == 0) { // All Names, levels and scores are moved down within their relevant arrays for (int j = totalScores - 1; j != 0; j--) { scoreboardTextData[0][j] = scoreboardTextData[0][j - 1]; scoreboardTextData[1][j] = scoreboardTextData[1][j - 1]; scoreboardComboData[j] = scoreboardComboData[j - 1]; } // The new number 1 top name, level and score, are added into the first element // within each of their relevant arrays. scoreboardTextData[0][0] = name; scoreboardTextData[1][0] = level; scoreboardComboData[0] = combo; break; } // If the methods get to this point, the combo score is not high enough // to be on the top10 score list and therefore needs to break break; } } // As totalScores < 1, the current score is the first to be added. Therefore no checks need to be made // and the Name, Level and combo data can be entered directly into the first element of their relevant // array. else { scoreboardTextData[0][0] = name; scoreboardTextData[1][0] = level; scoreboardComboData[0] = combo; } } } Example for adding score: private static void Initialize() { scoreboardDoc = new XmlDocument(); if (!File.Exists("Scoreboard.xml")) GenerateXML("Scoreboard.xml"); PopulateScoreBoard("Scoreboard.xml"); // ADD TEST SCORES HERE! AddScore("EXAMPLE", "10", 100); AddScore("EXAMPLE2", "24", 999); PopulateXML("Scoreboard.xml"); } In it's current state the source file is just used for testing, initialize is called within main and PopulateScoreBoard handles the majority of other initialising, so nothing else is needed, except to add a test score. I thank you for your time!

    Read the article

  • Embedding Youtube Videos on user's wall with the Javascript API

    - by dragonmantank
    I'm attempting to embed a Youtube video on a user's wall using the Javascript API. I've poured over a bunch of different tutorials and came up with this: var data = { method: 'feed', link: current_video_url, // Link to the vide on our site source: current_video_src, // Link to the Youtube video, http://youtube.com/v/[hash] picture: current_picture_url, // Thumbnail from youtube title: current_video_title, // Title from our page caption: current_video_description // Text from our page } FB.ui(data); Running the Facebook Debugger shows that the current_video_url link is being properly parsed for OG tags and is available as an embedded video. I ran a debugger and all the variables are being properly set in the data variable. This worked fine for about 2 days, and then we pushed the site live. We set up a new AppID in Facebook but now all the videos are just thumbnails instead of being embedded in the user's wall. I thought maybe this is a problem with the live site but now the dev site is broken too. What's the best way to get this to work consistently?

    Read the article

  • DB2 load partitioned data in parallel

    - by Erik Paulson
    I have a 10-node DB2 9.5 database, with raw data on each machine (ie node1:/scratch/data/dataset.1 node2:/scratch/data/dataset.2 ... node10:/scratch/data/dataset.10 There is no shared NFS mount - none of my machines could handle all of the datasets combined. each line of a dataset file is a long string of text, column delimited. The first column is the key. I don't know the hash function that DB2 will use, so dataset is not pre-partitioned. Short of renaming all of my files, is there any way to get DB2 to load them all in parallel? I'm trying to do something like load from '/scratch/data/dataset' of del modified by coldel| fastparse messages /dev/null replace into TESTDB.data_table part_file_location '/scratch/data'; but I have no idea how to suggest to db2 that it should look for dataset.1 on the first node, etc.

    Read the article

  • How can I set controls for a web page ??

    - by Rami Jarrar
    I have this login page with https, and i reach to this approach:: import ClientForm import urllib2 request = urllib2.Request("http://ritaj.birzeit.edu") response = urllib2.urlopen(request) forms = ClientForms.ParseResponseEx(response) response.close() f = forms[0] username = str(raw_input("Username: ")) password = str(raw_input("Password: ")) ## Here What To Do request2 = form.click() i get the controls of that page >>> f = forms[0] >>> [c.name for c in f.controls] ['q', 'sitesearch', 'sa', 'domains', 'form:mode', 'form:id', '__confirmed_p', '__refreshing_p', 'return_url', 'time', 'token_id', 'hash', 'username', 'password', 'persistent_p', 'formbutton:ok'] so how can i set the username and password controls of the "non-form form" f ??? and i have another problem,, how to know if its the right username and password ??

    Read the article

  • What does the "ApplicaionDirectory" Membership condition mean in .NET Code Access Security?

    - by smwikipedia
    I am not sure about the semantic of "ApplicationDirectory" membership condition. I am trying to use it in the .NET Framework 2.0 configuration tool. The tool's explanation to it is as below: The Application Directory membership condition is true for all assemblies in the same directory or in a child directory of the running application. Assemblies that meet this membership condition will be granted the permissions associated with this code group. All the other membership conditions such as strong name, hash, need me to input some criterias, only the Application Directory has not. How to use it? Could someone give an explanation by example? Many thanks.

    Read the article

  • Add shortcuts to (Windows + X) context menu

    - by KasiyA
    I want to add services.msc into Win+X context menu in windows 8 (x64). I know similar question is in here but it's not good with using Win+X Editor, because it doesn't add Underlined key for shortcuts that added with that and it's not good without having quickly underlined key. I want do that for maually Context menu folder is: C:\Users\User_Name\AppData\Local\Microsoft\Windows\WinX And hide desktop.ini files is as bellows (in ...\WinX\group2\desktop.ini) [LocalizedFileNames] 1 - Run.lnk=@%SystemRoot%\system32\shell32.dll,-12710 4 - Control Panel.lnk=@%SystemRoot%\system32\shell32.dll,-4161 5 - Task Manager.lnk=@%SystemRoot%\system32\authui.dll,-12139 3 - Windows Explorer.lnk=@%SystemRoot%\system32\shell32.dll,-22067 2 - Search.lnk=@%SystemRoot%\system32\shell32.dll,-30517 I copied sevices.msc shortcut into above path in group2 folder and add this line 6 - Sevices.lnk=@%SystemRoot%\system32\sevices.msc,????? in desktop.ini file. First Question: I don't know If this line 6 - Sevices.lnk=@%SystemRoot%\system32\sevices.msc,-????? that I added is correct or not? Also I don't know what to use instead of -????? Last Question: Why desktop.ini contents is not Sorted. I triyed to manually sort them but when I restart Explorer again it was become out of order.Why?

    Read the article

  • Passing parameters to custom RESTful routes in Rails (using :collection)

    - by dwhite
    I am trying to add a custom route to my RESTful routes using the :collection param on map.resources like so: map.resources :products, :collection => { :tagged => :get } The tagged action takes in a :tag parameter. I am able to link to the URL route using: tagged_products_path(:tag => tag.name). My issue with this is that the URL that this generates: /products/tagged?tag=electronic I would like the tag to be in the URL and not the tag, like so: /products/tagged/electronic Of course this can be accomplished by a separate named route, but I'm wondering if I'm missing something and there is a way to do this with the :collection hash. Thanks in advance for your help -Damien

    Read the article

  • Getting Wikipedia infoboxes in a format that Ruby can understand

    - by hadees
    I am trying to get the data from Wikipedia's infoboxes into a hash or something so that I can use it in my Ruby on Rails program. Specifically I'm interested in the Infobox company and Infobox person. The example I have been using is "Ford Motor Company". I want to get the company info for that and the person info for the people linked to in Ford's company box. I've tried figuring out how to do this from the Wikipedia API or DBPedia but I haven't had much luck. I know wikipedia can return some things as json which I could parse with ruby but I haven't been able to figure out how to get the infobox. In the case of DBPedia I am kind of lost on how to even query it to get the info for Ford Motor Company.

    Read the article

  • What are some best practises and "rules of thumb" for creating database indexes?

    - by Ash
    I have an app, which cycles through a huge number of records in a database table and performs a number of SQL and .Net operations on records within that database (currently I am using Castle.ActiveRecord on PostgreSQL). I added some basic btree indexes on a couple of the feilds, and as you would expect, the peformance of the SQL operations increased substantially. Wanting to make the most of dbms performance I want to make some better educated choices about what I should index on all my projects. I understand that there is a detrement to performance when doing inserts (as the database needs to update the index, as well as the data), but what suggestions and best practices should I consider with creating database indexes? How do I best select the feilds/combination of fields for a set of database indexes (rules of thumb)? Also, how do I best select which index to use as a clustered index? And when it comes to the access method, under what conditions should I use a btree over a hash or a gist or a gin (what are they anyway?).

    Read the article

  • Why does Git display certain new folders when checking out old revisions?

    - by ConnorG
    Hey all - I'm still learning the ropes of Git (love it!) but the other day I noticed some behavior I just do not understand. We have, in essence, three folders that got moved into the repository at different times (one immediately after we created the repo, one a little while later, and one just recently). Recently, I had to get some code out of an old revision. I used git checkout <old SHA1 hash> to pull up one of our first checkins, when I noticed Git showed the old folder (as it should), as well as the newest folder (which got added to the repo long after the checked out commit was made). But it did not show the second folder. What would cause Git to display the newest folder with the old revision?

    Read the article

  • Sorting an array in descending order in Ruby.

    - by Waseem
    Hi, I have an array of hashes like following [ { :foo => 'foo', :bar => 2 }, { :foo => 'foo', :bar => 3 }, { :foo => 'foo', :bar => 5 }, ] I am trying to sort above array in descending order according to the value of :bar in each hash. I am using sort_by like following to sort above array. a.sort_by { |h| h[:bar] } However above sorts the array in ascending order. How do I make it sort in descending order? One solution was to do following: a.sort_by { |h| -h[:bar] } But that negative sign does not seem appropriate. Any views?

    Read the article

  • Samsung laptop randomly shuts down

    - by Dmatig
    I've rewritten this question because it turned into an indecipherable mess. I have a Samsung R560 laptop that is overheating, and shutting itself down under load consistantly. Thank you quickcel for reccomending me Speedfan to monitor my temps. Here they are (Load / Idle): (Ignore "Temp1 and Temp2", whatever sensors they are they'd always random, pretty sure they're broke). The load temperature is after just 5 minites of playing Fallout 3 - another 5 minutes and it (the GPU - 9600M GS) consistantly breaches the mid 90's then shuts down, so it's hard to get a good picture of it. I'm looking for some solution or way to decrease these temperatures, because they seem far too high even idle. I've tried: Opening up the case and clearing of all dust with compressed air. Updating drivers for my Graphics card Have purchased and am using a notebook cooler I don't want to: Undervolt / underclock (defeats the point of having a more expensive card) Use lower power / performance settings (again, i might as well have bought something cheaper) Is there anything else i can try (software or inexpensive hardware) that can help me fix this? Has anybody had a Samsung laptop and knows if this can be sorted under my warranty, and the turnaround time of sending it off (UK?)(it has always ran hotter than it should, but now at 6 months old is getting hot enough to power off)

    Read the article

  • Refactor/rewrite code or continue?

    - by Dan
    I just completed a complex piece of code. It works to spec, it meets performance requirements etc etc but I feel a bit anxious about it and am considering rewriting and/or refactoring it. Should I do this (spending time that could otherwise be spent on features that users will actually notice)? The reasons I feel anxious about the code are: The class hierarchy is complex and not obvious Some classes don't have a well defined purpose (they do a number of unrelated things) Some classes use others internals (they're declared as friend classes) to bypass the layers of abstraction for performance, but I feel they break encapsulation by doing this Some classes leak implementation details (eg, I changed a map to a hash map earlier and found myself having to modify code in other source files to make the change work) My memory management/pooling system is kinda clunky and less-than transparent They look like excellent reasons to refactor and clean code, aiding future maintenance and extension, but could be quite time consuming. Also, I'll never be perfectly happy with any code I write anyway... So, what does stackoverflow think? Clean code or work on features?

    Read the article

  • How to disable secret_token in Rails 3?

    - by Damian Nowak
    I have several separate Rails 2 applications which share the same cookie. I upgraded one the applications to Rails 3.2.15 now. Mandatory secret_token in Rails 3 makes it impossible to share the session with the Rails 2 apps. I am storing the session in Redis. What the visitor only gets in the cookie is a session ID. There's no need to encrypt it. Therefore, how to disable secret_token in Rails 3? A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb

    Read the article

  • cached schwartzian transform

    - by davidk01
    I'm going through "Intermediate Perl" and it's pretty cool. I just finished the section on "The Schwartzian Transform" and after it sunk in I started to wonder why the transform doesn't use a cache. In lists that have several repeated values the transform recomputes the value for each one so I thought why not use a hash to cache results. Here' some code: # a place to keep our results my %cache; # the transformation we are interested in sub foo { # expensive operations } # some data my @unsorted_list = ....; # sorting with the help of the cache my @sorted_list = sort { ($cache{$a} or $cache{$a} = &foo($a)) <=> ($cache{$b} or $cache{$b} = &foo($b)) } @unsorted_list; Am I missing something? Why isn't the cached version of the Schwartzian transform listed in books and in general just better circulated because on first glance I think the cached version should be more efficient?

    Read the article

  • What CPAN module can summarize arbitrary 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

  • .NET values lookup

    - by Maciej
    Hi, I have a feeling of missing something obvious. UDP receiver application. It holds a collection of valid UDP sender IPs - only guys with IP on that list will be considered. Since that list must be looked at on every packet and UDPs are so volatile, that operation must be maximum fast. Good choice is Dictionary but it is a key-value structure and what I actually need here is a dictionary-like (hash lookup) key only structure. Is there something like that? Small annoyance rather than a bug but still. I can still use Dictionary Thanks, M.

    Read the article

  • How to extract URL parameters from a URL with Ruby or Rails?

    - by Flackou
    Hi, I have some URLs, like http://www.example.com/something?param1=value1&param2=value2&param3=value3, and I would like to extract the parameters from these URLs and get them in a Hash. Obviously, I could use regular expressions, but I was just wondering if there was easier ways to do that with Ruby or Rails. I haven't found anything in the Ruby Module 'URI' but perhaps I missed something. In fact, I need a method that would do that : extract_parameters_from_url("http://www.example.com/something?param1=value1&param2=value2&param3=value3") => {:param1 => 'value1', :param2 => 'value2', :param3 => 'value3'} Would you have some advices? Thanks in advance. Julien

    Read the article

  • Huge file in Clojure and Java heap space error

    - by trzewiczek
    I posted before on a huge XML file - it's a 287GB XML with Wikipedia dump I want ot put into CSV file (revisions authors and timestamps). I managed to do that till some point. Before I got the StackOverflow Error, but now after solving the first problem I get: java.lang.OutOfMemoryError: Java heap space error. My code (partly taken from Justin Kramer answer) looks like that: (defn process-pages [page] (let [title (article-title page) revisions (filter #(= :revision (:tag %)) (:content page))] (for [revision revisions] (let [user (revision-user revision) time (revision-timestamp revision)] (spit "files/data.csv" (str "\"" time "\";\"" user "\";\"" title "\"\n" ) :append true))))) (defn open-file [file-name] (let [rdr (BufferedReader. (FileReader. file-name))] (->> (:content (data.xml/parse rdr :coalescing false)) (filter #(= :page (:tag %))) (map process-pages)))) I don't show article-title, revision-user and revision-title functions, because they just simply take data from a specific place in the page or revision hash. Anyone could help me with this - I'm really new in Clojure and don't get the problem.

    Read the article

  • Two Tables Serving as one Model in Rails

    - by matsko
    Is is possible in rails to setup on model which is dependant on a join from two tables? This would mean that for the the model record to be found/updated/destroyed there would need to be both records in both database tables linked together in a join. The model would just be all the columns of both tables wrapped together which may then be used for the forms and so on. This way when the model gets created/updated it is just one form variable hash that gets applied to the model? Is this possible in Rails 2 or 3?

    Read the article

  • What Windows editor has CORRECT EOL whitespace handling?

    - by blueshift
    I'm looking for a Windows text editor for programming that handles EOL whitespace CORRECTLY, which for my idea of correct means: Strip all EOL whitespace on save, EXCEPT on lines that I haven't edited. This is to minimise the amount of EOL whitespace evil in my world, but not pollute SCM diff/blame with whitespace-only fixes (I have to deal with old / other people's code). I have played with TextPad, Notepad++, Kodomo Edit and Programmer's Notepad 2, and found all of them lacking. Also: I don't get along with vi, and I am unsure about Emacs on Windows. @Matti Virkkunen: I could mess with diff, but I want to fix the problem, not the symptoms. Fixing diff means all my, others, and server side diff tools need to be fixed, and doesn't fix space/noise/hash change issues in SCM. Example pet hate using that system: "update" tells me a file has changed. Diff shows no changes.

    Read the article

  • implementing feature structures: what data type to use?

    - by Dervin Thunk
    Hello. In simplistic terms, a feature structure is an unordered list of attribute-value pairs. [number:sg, person:3 | _ ], which can be embedded: [cat:np, agr:[number:sg, person:3 | _ ] | _ ], can subindex stuff and share the value [number:[1], person:3 | _ ], where [1] is another feature structure (that is, it allows reentrancy). My question is: what data structure would people think this should be implemented with for later access to values, to perform unification between 2 fts, to "type" them, etc. There is a full book on this, but it's in lisp, which simplifies list handling. So, my choices are: a hash of lists, a list of lists, or a trie. What do people think about this?

    Read the article

  • C++ HTML template framework, templatizing library, HTML generator library

    - by Marcin Gil
    I am looking for template/generator libraries for C++ that are similar to eg. Ruby's Erb, Haml, PHP's Smarty, etc. It would be great if I it would sport some basic features like loops, if/else, int conversion to strings, etc. Parameter passing to template rendering engine is also important if I could pass all of them in a hash map instead of calling some function for each of parameters. Do you have any recommendations? I can see also the possibility of embedding languages like Lua, however I haven't found a templatizing library for that either. Thanks!

    Read the article

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