Search Results

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

Page 18/147 | < Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >

  • Hashing a python method to regenerate output when method is modified

    - by Seth Johnson
    I have a python method that has a deterministic result. It takes a long time to run and generates a large output: def time_consuming_method(): # lots_of_computing_time to come up with the_result return the_result I modify time_consuming_method from time to time, but I would like to avoid having it run again while it's unchanged. [Time_consuming_method only depends on functions that are immutable for the purposes considered here; i.e. it might have functions from Python libraries but not from other pieces of my code that I'd change.] The solution that suggests itself to me is to cache the output and also cache some "hash" of the function. If the hash changes, the function will have been modified, and we have to re-generate the output. Is this possible or a ridiculous idea? If this isn't a terrible idea, is the best implementation to write f = """ def ridiculous_method(): a = # # lots_of_computing_time return a """ , use the hashlib module to compute a hash for f, and use compile or eval to run it as code?

    Read the article

  • NSSortDescriptor for NSFetchRequestController causes crash when value of sorted attribute is changed

    - by AJ
    I have an Core Data Entity with a number of attributes, which include amount(float), categoryTotal(float) and category(string) The initial ViewController uses a FethchedResultsController to retrieve the entities, and sorts them based on the category and then the categoryTotal. No problems so far. NSManagedObjectContext *moc = [self managedObjectContext]; NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Transaction" inManagedObjectContext:moc]; NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; [request setEntity:entityDescription]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(dateStamp >= %@) AND (dateStamp =< %@)", startDate, endDate]; [request setPredicate:predicate]; NSSortDescriptor *sortByCategory = [[NSSortDescriptor alloc] initWithKey:@"category" ascending:sortOrder]; NSSortDescriptor *sortByTotals = [[NSSortDescriptor alloc] initWithKey:@"categoryTotal" ascending:sortOrder]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortByTotals, sortByCategory, nil]; [request setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:managedObjectContext sectionNameKeyPath:@"category" cacheName:nil]; aFetchedResultsController.delegate = self; self.fetchedResultsController = aFetchedResultsController; On selecting a row (tableView:didSelectRowAtIndexPath), another view controller is loaded that allows editing of the amount field for the selected entity. Before returning to the first view, categoryTotal is updated by the new ‘amount’. The problem comes when returning to the first view controller, the app bombs with *Serious application error. Exception was caught during Core Data change processing: Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted). with userInfo (null) Program received signal: “EXC_BAD_ACCESS”.* This seems to be courtesy of NSSortDescriptor *sortByTotals = [[NSSortDescriptor alloc] initWithKey:@"categoryTotal" ascending:sortOrder]; If I remove this everything works as expected, but obviously without the sorting I want. I'm guessing this is to do with the sorting order changing due to categoryTotal changing (deletion / insertion) but can't find away fix this. I've verified that values are being modified correctly in the second view, so it appears down to the fetchedResultsController being confused. If the categoryAmount is changed to one that does not change the sort order, then no error is generated I'm not physically changing (ie deleting) the number of items the fetchedResultsController is returning ... the only other issue I can find that seem to generate this error Any ideas would be most welcome Thanks, AJ

    Read the article

  • Using a password to generate two distinct hashes without reducing password security

    - by Nevins
    Hi there, I'm in the process of designing a web application that will require the storage of GPG keys in an encrypted format in a database. I'm planning on storing the user's password in a bCrypt hash in the database. What I would like to be able to do is to use that bCrypt to authenticate the user then use the combination of the stored bCrypt hash and another hash of the password to encrypt and decrypt the GPG keys. My question is whether I can do this without reducing the security of the password? I was thinking I may be able to use something like an HMAC-SHA256 of a static string using the password and a salt as the secret key. Is there a better way to do this that I haven't thought of? Thanks

    Read the article

  • jQuery UI get the sorted position of LI element in UL

    - by PeterBZ
    I'm using jQuery UI's sortable for my UL list. Each time the user sorts the list, I want each li element to update it's "position" attribute to it's position in the list. <ul> <li position="1">a</li> <li position="2">b</li> <li position="3">c</li> </ul> So when a user swaps c with a, the position will also update. I tried to use .each but it seems that javascript doesn't follow the order of how the LI elements are displayed but the order of the element's creation.

    Read the article

  • Inserting an element into a sorted list

    - by Russell Cargill
    Ok I'm using getSharedPreferences to store my high score but before I fill it up I wanted to sort the scores into ascending order via and array, but if it finds a Score less than it in the first pos then it wont check the rest for the smallest? //function to add score to array and sort it public void addscoretoarray(int mScore){ for(int pos = 0; pos< score.length; pos++){ if(score[pos] > mScore){ //do nothing }else { //Add the score into that position score[pos] = mScore; break; } } sortArray(score); } should I call sortArray() before and after the loop to fix this problem or is there a better method to achive the same results? I should also mention that the sortArray(score) funtion is just calling Arrays.sort(score) where score is an array of mScore

    Read the article

  • Sorted sets and comparators

    - by Jack
    Hello, I'm working with a TreeSetthat is meant to store pathfind locations used during the execution of a A* algorithm. Basically until there are "open" elements (still to be exhaustively visited) the neighbours of every open element are taken into consideration and added to a SortedSetthat keeps them ordered by their cost and heuristic cost. This means that I have a class like: public class PathTileInfo implements Comparable<PathTileInfo> { int cost; int hCost; final int x, y; @Override public int compareTo(PathTileInfo t2) { int c = cost + hCost; int c2 = t2.cost + t2.hCost; int costComp = c < c2 ? -1 : (c > c2 ? 1: 0); return costComp != 0 ? costComp : (x < t2.x || y < t2.y ? -1 : (x > t2.x || y > t2.y ? 1 : 0)); } @Override public boolean equals(Object o2) { if (o2 instanceof PathTileInfo) { PathTileInfo i = (PathTileInfo)o2; return i.cost + i.hCost == cost + hCost && x == i.x && y == i.y; } return false; } } In this way first the total cost is considered, then, since a total ordering is needed (consistency with equals) a ordering according to the x,y coordinate is taken into account. This should work but simply it doesn't, if I iterate over the TreeSet during the algorithm execution like in for (PathTileInfo t : openSet) System.out.print("("+t.x+","+t.y+","+(t.cost+t.hCost)+") "); I get results in which the right ordering is not kept, eg: (7,7,6) (7,6,7) (6,8,6) (6,6,7) (5,8,7) (5,7,7) (6,7,6) (6,6,7) (6,5,7) (5,7,7) (5,5,8) (4,7,7) (4,6,8) (4,5,8) is there something subtle I am missing? Thanks!

    Read the article

  • Best way to search for a saturation value in a sorted list

    - by AB Kolan
    A question from Math Battle. This particular question was also asked to me in one of my job interviews. " A monkey has two coconuts. It is fooling around by throwing coconut down from the balconies of M-storey building. The monkey wants to know the lowest floor when coconut is broken. What is the minimal number of attempts needed to establish that fact? " Conditions: if a coconut is broken, you cannot reuse the same. You are left with only with the other coconut Possible approaches/strategies I can think of are Binary break ups & once you find the floor on which the coconut breaks use upcounting from the last found Binary break up lower index. Window/Slices of smaller sets of floors & use binary break up within the Window/Slice (but on the down side this would require a Slicing algorithm of it's own.) Wondering if there are any other way to do this.

    Read the article

  • class method as hash value

    - by demas
    I have this working code: class Server def handle(&block) @block = block end def do @block.call end end class Client def initialize @server = Server.new @server.handle { action } end def action puts "some" end def call_server @server.do end end client = Client.new client.call_server My Server will handle more then one action so I want to change code such way: class Server def handle(options) @block = options[:on_filter] end def do @block.call end end class Client def initialize @server = Server.new my_hash = { :on_filter => action } @server.handle(my_hash) end def action puts "some" end def call_server @server.do end end client = Client.new client.call_server It is incorrect code because action() method calls on create my_hash, but if I try to modify code to: my_hash = { :on_filter => { action } } i get error message. Is it possible to create hash with methods as hash values ?

    Read the article

  • KnockoutJS showing a sorted list by item category

    - by Darksbane
    I just started learning knockout this week and everything has gone well except for this one issue. I have a list of items that I sort multiple ways but one of the ways I want to sort needs to have a different display than the standard list. As an example lets say I have this code var BetterListModel = function () { var self = this; food = [ { "name":"Apple", "quantity":"3", "category":"Fruit", "cost":"$1", },{ "name":"Ice Cream", "quantity":"1", "category":"Dairy", "cost":"$6", },{ "name":"Pear", "quantity":"2", "category":"Fruit", "cost":"$2", },{ "name":"Beef", "quantity":"1", "category":"Meat", "cost":"$3", },{ "name":"Milk", "quantity":"5", "category":"Dairy", "cost":"$4", }]; self.allItems = ko.observableArray(food); // Initial items // Initial sort self.sortMe = ko.observable("name"); ko.utils.compareItems = function (l, r) { if (self.sortMe() =="cost"){ return l.cost > r.cost ? 1 : -1 } else if (self.sortMe() =="category"){ return l.category > r.category ? 1 : -1 } else if (self.sortMe() =="quantity"){ return l.quantity > r.quantity ? 1 : -1 }else { return l.name > r.name ? 1 : -1 } }; }; ko.applyBindings(new BetterListModel()); and the HTML <p>Your values:</p> <ul class="deckContents" data-bind="foreach:allItems().sort(ko.utils.compareItems)"> <li><div style="width:100%"><div class="left" style="width:30px" data-bind="text:quantity"></div><div class="left fixedWidth" data-bind="text:name"></div> <div class="left fixedWidth" data-bind="text:cost"></div> <div class="left fixedWidth" data-bind="text:category"></div><div style="clear:both"></div></div></li> </ul> <select data-bind="value:sortMe"> <option selected="selected" value="name">Name</option> <option value="cost">Cost</option> <option value="category">Category</option> <option value="quantity">Quantity</option> </select> </div> So I can sort these just fine by any field I might sort them by name and it will display something like this 3 Apple $1 Fruit 1 Beef $3 Meat 1 Ice Cream $6 Dairy 5 Milk $4 Dairy 2 Pear $2 Fruit Here is a fiddle of what I have so far http://jsfiddle.net/Darksbane/X7KvB/ This display is fine for all the sorts except the category sort. What I want is when I sort them by category to display it like this Fruit 3 Apple $1 Fruit 2 Pear $2 Fruit Meat 1 Beef $3 Meat Dairy 1 Ice Cream $6 Dairy 5 Milk $4 Dairy Does anyone have any idea how I might be able to display this so differently for that one sort?

    Read the article

  • What c# equivalent encoding does Python's hash.digest() use ?

    - by The_AlienCoder
    I am trying to port a python program to c#. Here is the line that's supposed to be a walkthrough but is currently tormenting me: hash = hashlib.md5(inputstring).digest() After generating a similar MD5 hash in c# It is absolutely vital that I create a similar hash string as the original python program or my whole application will fail. My confusion lies in which encoding to use when converting to string in c# i.e ?Encoding enc = new ?Encoding(); string Hash =enc.GetString(HashBytes); //HashBytes is my generated hash Because I am unable to create two similar hashes when using Encoding.Default i.e string Hash = Encoding.Default.GetString(HashBytes); So I'm thinking knowing the deafult hash.digest() encoding for python would help

    Read the article

  • Reversed Sorted Dictionary?

    - by Mark
    I have a SortedDictionary as defined like this: SortedDictionary<TPriority, Queue<TValue>> dict; But I want to sort the keys in reverse order. I assume I need set the Comparer, but what comparer do I use for a generic TPriority? Note that TPriority implements IComparable.

    Read the article

  • Sequential searching with sorted linked lists

    - by John Graveston
    struct Record_node* Sequential_search(struct Record_node *List, int target) { struct Record_node *cur; cur = List->head ; if(cur == NULL || cur->key >= target) { return NULL; } while(cur->next != NULL) { if(cur->next->key >= target) { return cur; } cur = cur->next; } return cur; } I cannot interpret this pseudocode. Can anybody explain to me how this program works and flows? Given this pseudocode that searches for a value in a linked list and a list that is in an ascending order, what would this program return? a. The largest value in the list that is smaller than target b. The largest value in the list that is smaller than or same as target c. The smallest value in the list that is larger than or same as target d. Target e. The smallest value in the list that is larger than target And say that List is [1, 2, 4, 5, 9, 20, 20, 24, 44, 69, 70, 71, 74, 77, 92] and target 15, how many comparisons are occurred? (here, comparison means comparing the value of target)

    Read the article

  • sorting nested list, allow only li to be sorted witin the same ul

    - by Y.G.J
    $(document).ready(function() { $("#test-list").sortable({ items: "> li", handle : '.handle', axis: 'y', opacity: 0.6, update : function () { var order = $('#test-list').sortable('serialize'); $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); } }); $("#test-sub").sortable({ containment: "ul", items: "li", handle : '.handle2', axis: 'y', opacity: 0.6, update : function () { var order = $('ul').sortable('serialize'); $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); } }); }); <ul id="test-list"> <li id="listItem_10">first<img align="middle" src="Themes/arrow.png" class="handle" /></li> <li id="listItem_8">second<img align="middle" src="Themes/arrow.png" class="handle" /> <ul id="test-sub"> <li id="listItem_4"><img align="middle" src="Themes/arrow.png" class="handle2" /></li> <li id="listItem_3"><img align="middle" src="Themes/arrow.png" class="handle2" /></li> <ul id="test-sub"> <li id="listItem_9"><img align="middle" src="Themes/arrow.png" class="handle2" /></li> </ul> </li> </ul> </li> </ul> the problems i have: sorting the main ul is working but not all the time - i will try to fix that my own but if there is a problem with the code here and not the one in proccess-sortable - tell me. moving li in the main ul is ok but the sub or the sub of the sub is having problem - i can drag something from one sub to it's sub or the other way too - i don't want that to happend. i want to be able to drag li and by selecting that one that only this ul group will send to proccess-sortable to be updated - how can i catch the specific ul of li i am draging?

    Read the article

  • Linked List Inserting in sorted format

    - by user2738718
    package practise; public class Node { public int data; public Node next; public Node (int data, Node next) { this.data = data; this.next = next; } public int size (Node list) { int count = 0; while(list != null){ list = list.next; count++; } return count; } public static Node insert(Node head, int value) { Node T; if (head == null || head.data <= value) { T = new Node(value,head); return T; } else { head.next = insert(head.next, value); return head; } } } This work fine for all data values less than the first or the head. anything greater than than doesn't get added to the list.please explain in simple terms thanks.

    Read the article

  • Best way to save info in hash

    - by qwertymk
    I have a webpage that the user inputs data into a textarea and then process and display it with some javascript. For example if the user types: _Hello_ *World* it would do something like: <underline>Hello</underline> <b>World</b> Or something like that, the details aren't important. Now the user can "save" the page to make it something like site.com/page#_Hello_%20*World* and share that link with others. My question is: Is this the best way to do this? Is there a limit on a url that I should be worried about? Should I do something like what jsfiddle does? I would prefer not to as the site would work offline if the full text would be in the hash, and as the nature of the site is to be used offline, the user would have to first cache the jsfiddle-like hash before they could use it. What's the best way to do this?

    Read the article

  • ruby hash to object - Parsing data from JSON object

    - by Leddo
    Hi all, I'm just starting to dabble in consuming a JSON webservice, and I am having a little trouble working out the best way to get to the actual data elements. I am receiving a response which has been converted into a ruby hash using the JSON.parse method. The hash looks like this: {"response"=>{"code"=>2002, "payload"=>{"topic"=>[{"name"=>"Topic Name", "url"=>"http://www.something.com/topic", "hero_image"=>{"image_id"=>"05rfbwV0Nggp8", "hero_image_id"=>"0d600BZ7MZgLJ", "hero_image_url"=>"http://img.something.com/imageserve/0d600BZ7MZgLJ/60x60.jpg"}, "type"=>"PERSON", "search_score"=>10.0, "topic_id"=>"0eG10W4e3Aapo"}]}, "message"=>"Success"}} What I would like to know, is what is the easiest way to get to the "topic" data so I can do something like: topic.name = json_resp.name topic.img = jsob_resp.hero_image_url etc Many thanks for any help you can offer. Regards Chris

    Read the article

  • Ruby: reduce duplication while initialize hash

    - by user612308
    array = [0, 0.3, 0.4, 0.2, 0.6] hash = { "key1" => array[0..2], "key2" => array[0..3], "key3" => array, "key4" => array, "key5" => array, "key6" => array, "key7" => array } Is there a way I can remove the duplication by doing something like hash = { "key1" => array[0..2], "key2" => array[0..3], %(key3, key4, key5, key6, key7).each {|ele| ele => array} }

    Read the article

  • Is there a circular hash function?

    - by Phil H
    Thinking about this question on testing string rotation, I wondered: Is there was such thing as a circular/cyclic hash function? E.g. h(abcdef) = h(bcdefa) = h(cdefab) etc Uses for this include scalable algorithms which can check n strings against each other to see where some are rotations of others. I suppose the essence of the hash is to extract information which is order-specific but not position-specific. Maybe something that finds a deterministic 'first position', rotates to it and hashes the result? It all seems plausible, but slightly beyond my grasp at the moment; it must be out there already...

    Read the article

  • ASP.NET Membership Password Hash -- .NET 3.5 to .NET 4 Upgrade Surprise!

    - by David Hoerster
    I'm in the process of evaluating how my team will upgrade our product from .NET 3.5 SP1 to .NET 4. I expected the upgrade to be pretty smooth with very few, if any, upgrade issues. To my delight, the upgrade wizard said that everything upgraded without a problem. I thought I was home free, until I decided to build and run the application. A big problem was staring me in the face -- I couldn't log on. Our product is using a custom ASP.NET Membership Provider, but essentially it's a modified SqlMembershipProvider with some additional properties. And my login was failing during the OnAuthenticate event handler of my ASP.NET Login control, right where it was calling my provider's ValidateUser method. After a little digging, it turns out that the password hash that the membership provider was using to compare against the stored password hash in the membership database tables was different. I compared the password hash from the .NET 4 code line, and it was a different generated hash than my .NET 3.5 code line. (Tip -- when upgrading, always keep a valid debug copy of your app handy in case you have to step through a lot of code.) So it was a strange situation, but at least I knew what the problem was. Now the question was, "Why was it happening?" Turns out that a breaking change in .NET 4 is that the default hash algorithm changed to SHA256. Hey, that's great -- stronger hashing algorithm. But what do I do with all the hashed passwords in my database that were created using SHA1? Well, you can make two quick changes to your app's web.config and everything will be OK. Basically, you need to override the default HashAlgorithmTypeproperty of your membership provider. Here are the two places to do that: 1. At the beginning of your element, add the following element: <system.web> <machineKey validation="SHA1" /> ... </system.web> 2. On your element under , add the following hashAlgorithmType attribute: <system.web> <membership defaultProvider="myMembership" hashAlgorithmType="SHA1"> ... </system.web> After that, you should be good to go! Hope this helps.

    Read the article

  • Recommend software: File checksum calculator

    - by Johnny W
    Hi, I'm looking for a light, fast hash/checksum calculator (eg. MD5, SHA1, etc.). I've been using HashCalc and it works fine enough, but I was wondering if there was something better. When downloading .ISOs from MS BizSpark, I've found that it's essential to check the SHA1, and I'm sure that other people have found the same... So what's the defacto, light, fast, simple app that does the job? :) Thanks for any recommendations.

    Read the article

  • Monitoring folder diffs across servers with zabbix

    - by Marcus
    Problem: I want to make sure that a certain folder is equal regarding it's contents across my servers. I do not want an automatic filesync to keep them equal, changing is done manually. My initial thought was to once a day calculate some crc/hash on folder and send to Zabbix, and trigger when values differ. Is there any good tools out there that can calculate crc or similar of a folder? Anyone know of another solution that solves my problem?

    Read the article

< Previous Page | 14 15 16 17 18 19 20 21 22 23 24 25  | Next Page >