w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Offline dictionary for IOS
NSString *word = [dictionary randomWord]; returns a random word from the dictionary without any restrictions. On the other hand running NSDictionary *words = [dictionary wordsWithPrefix:@"A"]; would return a result of about 1800 Adjectives, 400 Adverbs, 500 Verbs... and will probably be too slow :) Such a search does not return a result for nouns and a warning is printed to the log. It is therefore advisable to constrain your searches to prevent such cases. If you must, you can so multiple two-letter prefix searches ('aa', 'ab', 'ac', ...) in advance and cache the results.

Categories : Iphone

Remove / hide the Bing map offline message when offline
You can either handle the LoadingError event per instance or extend the Map control yourself as described in this post. You can then remove the layer than contains the error message so that it's not shown to the user. public partial class CachedMap : Map { public CachedMap() : base() { base.LoadingError += (s, e) => { base.RootLayer.Children.RemoveAt(5); }; } }

Categories : C#

Issue with Dictionary type, If gived a specific text then get the equivalent dictionary key or dictionary value?
If this were my application, I would change the UI element to a datagridview so that I could bind a collection containing a custom class and just hide or show the appropriate columns as needed. This approach will allow you to easily add additional property columns in the future without worrying about the problems you are currently facing. It would also allow you to extend the UI to other platforms (mobile, web) without a lot of hard-coded information in the UI. For example, I would create the following class and collection to hold info about the files: Public Class FileDetails Public Property Index As Integer Public Property Description As String = String.Empty Public Property FullFileName As String = String.Empty Public ReadOnly Property FileName As String Get

Categories : Dotnet

updating list values of dictionary with the values of another dictionary and printing the result as the values of first dictionary in python
Well, first off your syntax for defining literal dictionaries is incorrect. Dictionaries are surrounded by curly brackets like this: {} instead of square brackets like this: [] If you want 'Standard_Animator' and 'Extended_Animator' to be keys for lists of colors, you would want to do something like this: legenddict = {"Standard_Animator" : ["blue", 3f7fff, 00bfff, 3fffbf, "green", bfff3f, ffbf00, ff7f00, "red"], "Extended_Animator" : ["lightgray", "blue", 3f7fff, 00bfff, 3fffbf, "green", bfff3f, ffbf00, ff7f00, "red", "magenta"} colordict = {'blue':'ff00ff', 'red':'808080', 'lightgray':'d3d3d3', 'magenta':'00ff00'} So, to print the values in legenddict using the color names in colordict, you can check to see if the colors are keys in colordict, and if so, look up the

Categories : Python

Python ordered dictionary: Why is [] notation required to change dictionary values using a for loop?
In the loop, name and val are bound to each of the objects in the mapping in turn. Simply rebinding the names will not modify the original iterable.

Categories : Python

SignalR Adding/Removing Connections from a dictionary and finding Group values from dictionary
First of all, SignalR is pretty smart about not wasting resources when sending to groups without any subscriptions, so you should be fine sending to groups without any members as long as it's OK to waste a few cycles doing that. If you don't have too many organizations you can have a ConcurrentDictionary<int,int> with all your organization ids as your keys and the number of connected members as your value. In OnConnected and OnDisconnected in could use Interlocked.Increment and Interlocked.Decrement respectively to keep track of the currently connected members. Then in your task could loop over the keys and skip any organization with zero connected members. This new ConcurrentDictionary could replace _uniqueOrganizations if you don't mind calling key.ToString(CultureInfo.InvariantC

Categories : Asp Net

Check if dictionary key contains any of another dictionary's keys and print matching pairs
This worked for me: full_name1 = 'Will Smith' full_name2 = 'Matt Damon' full_name3 = 'Mark yMark' name1 = 'Will' name2 = 'Matt' name3 = 'Mark' my_dict = {full_name1 : 1, full_name2 : 2, full_name3 : 3} another_dict = {name1 : 'x', name2 : 'y', name3 : 'z'} result = {} for sub, val in another_dict.items(): # start with the substrings for string, key in my_dict.items(): if sub in string: result[key]=val print(result) I used dict.items() to make the code a bit more readable. Combined with some more clear variable names, I think that makes the logic a bit easier to follow. docs: http://docs.python.org/2/library/stdtypes.html#dict.items Could be simplified I'm sure. Note that I assumed that your words like

Categories : Python

How can I implement a fuzzy search across each value of a dictionary in a multiple dictionary list?
You can use something like >>> l = [ ... {"Name":"Arnold", "Age":"52", "Height":"160"}, ... {"Name":"Donald", "Age":"52", "Height":"161"}, ... {"Name":"Trevor", "Age":"22", "Height":"150"} ... ] >>> >>> [d for d in l if any("nol" in v for v in d.values())] [{'Age': '52', 'Name': 'Arnold', 'Height': '160'}] >>> >>> [d for d in l if any("52" in v for v in d.values())] [{'Age': '52', 'Name': 'Arnold', 'Height': '160'}, {'Age': '52', 'Name': 'Donald', 'Height': '161'}]

Categories : Python

What can cause dictionary.ContainsKey(dictionary.Keys.First()) to return false?
The key was first added to the Dictionary<,> when it had one hash code. After that the object was "mutated" to give a state where the hash code is some new number. The Dictionary<,> is therefore in an invalid state. Do not mutate an object that might be a key in some hashtable somewhere, in a way the changes the hash code of that object.

Categories : C#

Add word to user dictionary and retrieve them back from dictionary
I managed to find solution of my question by my own....answering this question in the hope that it might help someone as a reference for the same kind of issue: public class HomeActivity extends Fragment implements TextWatcher { String itemClientName[] = {}; ArrayAdapter<String> clientNameAdapter; ArrayList<String> clientNameList = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AutoCompleteTextView et_client_name = (AutoCompleteTextView) findViewById(R.id.et_client_name); getFromDictionary(); suggestClientName(); et_client_name.addTextChangedListener(this); } public void getFrom

Categories : Android

Creating a dictionary with values identical to keys from another dictionary
Use a dict comprehension: dict2 = {k: k for k in dict1} This simply loops over all the keys of dict1 and echos that key as the value as well for each key-value pair.

Categories : Python

How can I cast a subset of a dictionary to a type derived from Dictionary<>
You get an invalid cast exception because the result of ToDictionary is not MyDict. In order to fix this problem, add a constructor to MyDict that takes an IDictionary<string,A>, and return the result of calling that constructor from your GetSubSet method: public class MyDict : Dictionary<string, A> { public MyDict() { // Perform the default initialization here ... } public MyDict(IDictionary<string,A> dict) { // Initialize with data from the dict ... } } ... public MyDict GetSubSet(int testVal) { var ret = dict.Where(e => e.Value.aValue == testVal). ToDictionary(k => k.Key, k => k.Value); return new MyDict(ret); }

Categories : C#

Efficient dictionary inversion on dictionary like file
I would suggest the following 3 pass solution: Iterate over your original dictionary file once, adding a val, key line to your output file for each val as you go. Sort the output file from step 1 using the unix sort command or some other fast sorting program. If there is a possibility that step 1 produced duplicates that need to be removed, iterate over the output file from 2 and remove duplicates as you write your final output file. Because the output file from 2 is sorted, you need only one pass and minimal memory to do this.

Categories : Python

Why does this Python list of dictionary only have the keys of the dictionary?
You are not making a list of dicts, you are making a list of dictionary keys from the dictionary, list(dict(...)) returns a list of keys: >>> d = dict(username="x", password="y") >>> list(d) ['username', 'password'] Probably you want to define users this way: users = [dict(username="x", password="y")] or users = [{'username': 'x', 'password': 'y'}]

Categories : Python

Bind ComboBox to Dictionary and the Selected to the Dictionary Key
Answer based on comment link from Anatoliy <ComboBox Grid.Row="2" Grid.Column="3" DataContext="{Binding RelativeSource={RelativeSource AncestorType=Page}}" ItemsSource="{Binding Path=DLchars}" PresentationTraceSources.TraceLevel="High" VerticalAlignment="Center" SelectedValuePath="Key" SelectedValue="{Binding Path=EOL}"> <ComboBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="25"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding Path=Key}" />

Categories : Dotnet

Most efficient way to populate dictionary keys with dictionary
I believe you're looking for copy.deepcopy(). friends = { "John": copy.deepcopy(places), "Carter": copy.deepcopy(places), "Bill": copy.deepcopy(places), }

Categories : Python

Extracting key and values in dictionary with in dictionary in C#
Absolutely no clue what you are trying to do but Given Dictionary<string, Dictionary<string,IEnumerable<AGString>>> Data = new Dictionary<string, Dictionary<string,IEnumerable<AGString>>>(); foreach(string k1 in Data.Keys) { foreach(string k2 in Data[k1].Keys) { foreach(AGString ag in Data[k1][k2]) { // do something with k1, k2 and ag } } }

Categories : C#

Python Two Dictionaries within another Dictionary within another Dictionary
In self.__tests = {'test1' : info.copy(), 'test2' : info.copy(), 'test3' : info.copy()} the variable info is only copied by a shallow (ie non recursive) copy. You should use copy.deepcopy here if you want __tBin and friends to be copied.

Categories : Python

How to convert a dictionary pair.value to a dictionary in C#?
Assuming tset in your array is a typo and it actually is test, you can use concerete classes .... string json = @"{""dest"":[ { ""mode"": ""1"", ""test"":""test1,test,test2""},{ ""mode"": ""2"", ""test"": ""test3"" }]}"; var obj = new JavaScriptSerializer().Deserialize<MyObject>(json); public class Dest { public string mode { get; set; } public string test { get; set; } } public class MyObject { public List<Dest> dest { get; set; } }

Categories : C#

How to make a fast dictionary that contains another dictionary?
Don't be afraid of collisions, use cryptographic hash. But choose a fast one. 256 bit collision is MUCH less probable than hardware error. Sun used it to deduplicate blocks in ZFS. ZFS uses SHA256. Probably you can use less secure hash. If it takes $1000000 to find one collision hash isn't secure but one collision don't seem to drop your performance. Many collisions would cost many $1000000. You can use something like (unordered) multimap<SHA, T> to deal with collisions. By the way, ANY hash table suffer from collisions (or takes too many memory), so ordered map (rbtree in gcc) or btree_map has better guaranteed time. Also hash table can be DOSed via hash collisions. Probably a secret salt can solve this problem. It is due to table size is much less than number of possible hashes.

Categories : C++

Python : Match a dictionary value with another dictionary key
third_dict = {k: tr[v[0]] for k, v in scnd_dict.iteritems() if v[0] in tr} This tr = defaultdict(list) is a waste of time if you are just rebinding tr on the next line. Likewise for scnd_dict. It's a better idea to make all the values of tr lists - even if they only have one item. It will mean less special cases to worry about later on.

Categories : Python

dictionary of dictionary key to multi index
a dict of frames forms a panel, to_frame transmutes to a 2-level index, you want an additional level which concat forms when passed a dict In theory you could do something like a recursive reduction if you needed more levels, but that blows up the brain. To get your exact output, you can do a sortlevel. In [36]: concat( dict([ (k,Panel(v).to_frame()) for k,v in t.items() ]) , names= ['level']) Out[36]: 1 2 level major minor a 0 0 1 5 1 2 6 1 0 3 7 1 4 8 b 0 0 1 5 1 2 6 1 0 3 7 1 4 8

Categories : Python

How add dictionary inside another dictionary using loops?
Just from the top of my head (if I understood you correctly): maindict = dict([x, mydict] for x in range(5)) Will give you maindict: {0: <mydict>, 1: <mydict>, ... , 4: <mydict>}

Categories : Python

A dictionary for each variable or a dictionary for all variables?
I would prefer the second solution since you can do: if platform == windows: vars = win_vars elif platform == posix: vars = lin_vars And then later in you application you don't have to deal with de branching. Just use the vars variable. Note: I haven't specified the way to check for the platform since there are multiple ways depending on what you need. You can either check the sys.platform, use the platform module or check if posix, nt... is in sys.builtin_module_names.

Categories : Python

How to check if a dictionary is in another dictionary in python
You're checking if the actual list is in there, not the tuple. Here, you can use all(): all(i in a3.f.items() for i in L[0].f.items()) Or even set notation: >>> set(L[0].f.items()) & set(a3.f.items())) == set(L[0].f.items()) True # Note that without the bool call this returns set([('a', 1)]), which can # be useful if you have more than one sublist tuples.

Categories : Python

Does the order of keys in dictionary.keys() in a python dictionary change if the values are changed?
No, a python dictionary has an ordering for the keys but does not guarantee what that order will be or how it is calculated. Which is why they are not guaranteed to be ordered in the first place. The values stored in the dictionary do not have an effect on the hash values of the keys and so will not change ordering. Taken from the Python Documentation: The keys() method of a dictionary object returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just apply the sorted() function to it). To check whether a single key is in the dictionary, use the in keyword.

Categories : Python

Convert members of interface based dictionary to concrete based dictionary
You can do below. But if your code requires some casting from abstract type to its concrete implementation then you may have some other problems with your design. Dictionary<KeyType, IList<ValueType>> newDict = myDict.ToDictionary( k => k.Key as KeyType, v => v.Value.OfType<ValueType>() as IList<ValueType>);

Categories : C#

What happens when a GIT submodule goes 'offline'?
In a way submodules are are viewed as separate repositories. So if your submodule repo goes offline - there is no way to update a submodule. When you use a submodule you imply that the repo is accessible to all the developers throughout dev cycle. Only use submodules for relatively stable components.

Categories : GIT

JXMapKit offline
Try with return this.baseURL +"/"+(10-zoom)+"/"+x+"/"+y+".png"; where the number 10 is your max level source: https://today.java.net/pub/a/today/2007/11/13/mapping-mashups-with-jxmapviewer.html#using-a-custom-map-server

Categories : Java

OpenStreetMap offline?
Of course this is possible, OpenStreetMap's data is free and so are most of the tools around it. For rendering your own tiles just follow the steps described on switch2osm in the serving tiles guide. You can also import one of the extracts if you don't want to serve the whole planet. Alternatively you can use some of the other available renderers and toolchains for creating your own tiles, for example Maperitive and TileMill. If you are interested in routing then take a look at the routing wiki page and especially at the list of various online routers and offline routers for OSM. For geocoding there are various search engines available of which Nominatim is the most popular one at the moment.

Categories : Misc

IOS: use offline maps
Offline maps require a bit of experience in iOS since there aren't many projects and examples out there. However, you got one project called Route-Me which could give you a starting point. We used it to develop Metro Valencia Offline which successfully made it to the App Store. I wrote a small tutorial on how to add Route-Me into your project. Basically you can use any maps feed you may want (OpenStreetMaps is one of them and also the one we used). What you'll have to do is: Download the map tiles ( https://metacpan.org/pod/Geo::OSM::Tiles ) Put them into a SQLite database ( http://shikii.net/blog/downloads/map2sqlite-bin.zip ) Modify Route-Me for the tiles to be fed from the database instead of from OpenStreetMaps website

Categories : IOS

iOS App Offline and synchronization
I have done something similar just in the beginning of this year. After I read about NSOperationQueue and NSOperation I did a straight forward approach: Whenever an object is changed/added/... in my local database, I add a new "sync"-operation to the queue and I do not care about, if the app is online or offline (I added a reachability observer which either suspended the queue or takes it back working; of course, I do re-queueing if an error occurs (lost network during sync)). The operation itself reads/writes the database and does the networking stuff. My ViewController use a NSFetchedResultsController (with delegate=self) to get callbacks on changes. In some cases I needed some extra local data (it is about counting objects), where I have used NSManagedObjectContextObjectsDidChangeNotif

Categories : IOS

iOS App - No functionality when offline
You could use the Reachability library available here, just follow the examples described in the README.md file, it's pretty straightforward. Basically, after you've set up the library and the required framework (SystemConfiguration.framework), you can import Reachability into your view controller's classes and do something like this: Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"]; reach.reachableBlock = ^(Reachability*reach) { // Your app has internet connection, begin working as usual }; reach.unreachableBlock = ^(Reachability*reach) { // Your app does not have internet connection, // display an alert/image that will notify the user about this }; [reach startNotifier]; You could put this code into the viewDidLoad: method, so when the a

Categories : IOS

NullReferenceException on Dictionary.Add with dictionary variable not Null, key not Null and no multithreading
value: Nothing would be a valid reason to get a Null Reference exception. It's possible that the string in your DataRow is Nothing (if it the column didn't exist, you'd get an exception).

Categories : Dotnet

Make list of dictionary from 3 lists where each list data is key in dictionary
What about: from itertools import izip, repeat a = [1, 2, 3] b = ['a', 'b', 'c'] c = ['aa', 'bb', 'cc'] addresses = repeat('address') ids = repeat('id') names = repeat('names') d = [dict(((i, j), (k, l), (m, n))) for i, j, k, l, m, n in izip(addresses, a, ids, b, names, c)] Re: slower - I tried to simply benchmark it: from time import time t = time() for i in xrange(100000): d = [dict(((i, j), (k, l), (m, n))) for i, j, k, l, m, n in izip(addresses, a, ids, b, names, c)] print time() - t gives 0.68 seconds, the OP's way gives 0.81 seconds. Re 2: and the fastest way (and IMHO also simplest) is: d = [{'address': j, 'id': l, 'names': n} for j, l, n in izip(a, b, c)] giving 0.23 seconds.

Categories : Python

How to build an offline web app using Flask?
I would have thought this one would work: CACHE MANIFEST /static/style.css /static/script.js But in any case, you should not hardcode the URLs for your static files. It's best to serve the manifest as a template (moved to the "templates" folder) so that you can use url_for to generate the path to the static files, something like this: CACHE MANIFEST {{ url_for('static', filename='style.css') }} {{ url_for('static', filename='script.js') }} Then in your HTML template you would have a reference to a route instead of a static file: <html manifest="{{ url_for('manifest') }}"> And finally, you would add a new view function that returns the manifest: from flask import make_response @app.route('/manifest') def manifest(): res = make_response(render_template('manifest.appcache

Categories : Python

Replicating a website for offline use
The webview is already doing that for you once the user visits that view. The page is loaded and cached. You can set the webview to cache on the sd card like this: webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); link to docs If this default behaviour isn't enough for you you can look into fetching the content with a httpclient and storing that information. But then you'll have to adapt your webview to go look there first and you'll have to make sure you download all the resources that webpage needs.

Categories : Android

Offline map (.obf file) in android?
I suggest you to have a look at OsmAnd. It works with .obf format and provides you offline navigation. OsmAnd

Categories : Android

Using GCD for offline persistent queue
If NSOperation vs submitting blocks to GCD ever shows up as measurable overhead, the problem isn't that you're using NSOperation, it's that your operations are far too granular. I would expect this overhead to be effectively unmeasurable in any real-world situation. (Sure, you could contrive a test harness to measure the overhead, but only by making operations that did effectively nothing.) Use the highest level of abstraction that gets the job done. Move down only when hard data tells you that you should.

Categories : IOS

Build an ASP.Net web app with offline functionality
Yes that can be done with ASP.NET, because ASP.NET renders as an HTML page in the client's browser and offline functionality is a pure JavaScript/Html functionality. Here is an article by Stephen Walther showing one way to do it.

Categories : Asp Net



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.