w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Why do some languages return nil when a key is not in a dictionary, while Python throws an exception?
From the Zen of Python (import this): Errors should never pass silently. Unless explicitly silenced. Meaning, a key not found is treated as an error, unless you explicitly code for it, e.g. by catching KeyError or using the dict.get(key, default) method. Python was explicitly designed to be very explicit in this and (most) other respects.

Categories : Python

In Umbraco 6.1.1 MVC 4, how can I do a form post back to a surface controller using a model that inherits from Umbraco's RenderModel?
Ok, I've had no responses to this question but am now in a position to answer it myself. Maybe it was a fundamental oversight, but not that obvious imho, and information on the Umbraco forum etc about inheriting from RenderModel is fairly limited. Essentially the answer, as was my first instinct, is to solve the original exception "No parameterless constructor defined for this object" by providing a paramaterless constructor. The difficulty is working out what to put inside the parameterless constructor for my model, since it inherits from the Umbraco RenderModel which requires an IPublishedContent instance passed to it's constructor. Luckily while browsing around I happened across this post on the Umbraco forum: http://our.umbraco.org/forum/developers/api-questions/40754-Getting-Curre

Categories : Asp Net Mvc

Umbraco MVC Implementation - View does not depend on Umbraco implementations
No you can't. Simply because all requests pass through a single action. In order to retrieve a path to a CMS-managed page, you need to use the node/content traversal the @Model provides. See here for more details on this. Edit To clarify, the author of the article is suggesting that the Umbraco implementation should be more in line with a traditional MVC implementation with little or no logic in the views. Therefore, any querying of node data should happen prior to the view (e.g. in the Mappers). So this is where you would have to retrieve the links. Umbraco's default MVC implementation forces all requests to go via a single action on a single controller. The author's implementation allows the requests to be shared across one controller per document type - which is better IMO. But it st

Categories : Asp Net Mvc

URL rewriting not Working in Umbraco
Try this: <add name="redirect_brands" redirect="Application" redirectMode="Permanent" virtualUrl="^~/brand/(.*)" rewriteUrlParameter="IncludeQueryStringForRewrite" destinationUrl="/$1" ignoreCase="true" /> I think you're missing the ~ in the virtualUrl

Categories : Asp Net

Umbraco - error when using umbraco.library:NiceUrl(...)
Ok I found a solution: I added an extra check to this part: <!-- Return the url --> <xsl:if test="$i = $max"> <xsl:if test="$id != '' "> <xsl:value-of select="umbraco.library:NiceUrl($id)" /> </xsl:if> </xsl:if> this fixed my problem.

Categories : Xslt

Umbraco MediaService / Umbraco MediaItem not saving
To Save media, I found this method with MediaService. However, I think it's possible another method more refined [HttpPost] public JsonResult Upload(HttpPostedFileBase file) { IMedia mimage; // Create the media item mimage = _mediaService.CreateMedia(file.FileName, <parentId>, Constants.Conventions.MediaTypes.Image); mimage.SetValue(Constants.Conventions.Media.File, file); _mediaService.Save(mimage); return Json(new { success = true}); }

Categories : C#

Colorbox code working outside of Umbraco, but not within
This looks like a problem with how you have implemented your script in Umbraco. Just looking through Chrome's browser inspector, I can see that your script is failing to find the colorbox objects which means that something is prevent the library from being available. This is usually because a dependent javascript library has failed. Looking at your source code, you are loading all your jQuery libraries at the bottom of your page. This is good practice, but you have placed your a second jQuery file reference, your colorbox file references and the custom colorbox code in the head of the page. There are several things you will need to do: Remove the jQuery reference from the head of the page; Move the colorbox file references to the bottom of the page, after all the other javascript file

Categories : Javascript

Umbraco Rest Extension Not working after moving code from 4.7.1 into 4.11.10
Most probably your code is throwing an exception and this gets converted to a 500 error that masks it. So the problem could be anything. I had the same issue and the best thing I did was wrap all my code inside a try/catch and return the exception as a string. Remember that in order to get all the info from the exception you need to compile in Debug mode and copy the .pdb file along with your .dll. ... [RestExtensionMethodAttribute] public static string GetCountries() { try { return Core.RazorRenderer.RenderScriptFile("LandingPage/GetCountries", 0, GetLandingParameters(false)); } catch (Exception e) { return e.ToString(); } } ... Hope this helps you find the problem ! It worked for me.

Categories : C#

Could not locate Razor Host Factory type: umbraco.MacroEngines.RazorUmbracoFactory, umbraco.MacroEngines
If you are trying to host the blogengine site within a virtual directory of the Umbraco site, then you will have to amend the blogengine web.config to "remove" all the Umbraco-specific handlers and modules, as these will be inherited by the blogengine application, causing this exception because the application can't find the relevant DLLs in its bin folder. I recently had a similar problem and I have posted the web.config I used in the virtual directory below. Mine was a very simple web application, so obviously this will not work by itself in your blogengine app. You will need to add the relevant parts into your web.config file. Also, this was for a v6 Umbraco install in IIS7.5, so you may have to experiment a little. <?xml version="1.0"?> <configuration> <configSecti

Categories : Iis

SPLIT_STR not working with the foreign languages
LENGTH returns the string length in bytes; your foreign language characters are probably 2 or 3 bytes UTF sequences. Try to replace LENGTH with CHAR_LENGHT, which returns the length of the string measured in characters, in the function definition. SQLfiddle: http://sqlfiddle.com/#!2/1bb2d/1

Categories : Mysql

Unexpected results when working with very big integers on interpreted languages
Your Go code uses integer arithmetic with enough bits to give an exact answer. Never touched PHP or Node.js, but from the results I suspect the math is done using floating point numbers and should be thus expected not to be exact for numbers of this magnitude.

Categories : PHP

MS Office spell check is not working with non-English languages from managed api
I have done some tests with both GetSpellingSuggestions in the Word Application and in a Range and the behaviour you describe seems to be the normal one. The language on my computer is Spanish and when I use your code (with WdLanguageID.wdSpanish and "buxs"), I get the suggestions you refer (same ones when I moved to English). On the other hand, when I change to German I don't get anything. Also I have tested "clearly suggestable" words in Spanish ("kasa" or "part") and the results have been fine. My conclusion is that if the word can be found in the target dictionary, it delivers these results; otherwise, it looks in the English dictionary. Apparently, "buxs" is not included in the German dictionary.

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

Dictionary ++ not working as expected
My solution: var dic = new Dictionary<Int32, Int32>(); var ids = new List<int> { 1, 2, 3, 1, 2 }; foreach (var id in ids) { if (dic.ContainsKey(id)) { dic[id]++; } else { dic[id] = 1; } }

Categories : C#

Dictionary passed to js not working
Ignore all the JavaScript. The key line in your problem is: [30/Jul/2013 02:50:51] "GET /visualize/static/js/test.js HTTP/1.1" 404 2732 404 is the HTTP code for 'file not found', which means that you're using the incorrect path to reference your JavaScript file. Fix that, and you may find that your solution then works - or, if not, at least breaks differently.

Categories : Javascript

Adding is not Working in Generic Dictionary in C#
Try changing your code to class GenericDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public void AddToGenericDictionary(TKey key, TValue value) { this.Add(key, value); } } When overriding the dictionary, you do not need to implement the backing store. But if you wish to implement your own Dictionary, have a look at IDictionary Interface Represents a generic collection of key/value pairs.

Categories : C#

if-else comprehension with dictionary not working in python3
This doesn't work because you are trying to access dict.keys while you are creating dict in a dict comprehension. If this was in a for loop, dict.keys would be updated each element, but the dict comprehensions ensures that the dict is not updated mid-creation to improve speed. Something like this should work: myDict = {} for (num, strn) in enumerate(dlist): for w in strn.split(): if w not in myDict: myDict[w] = {num} else: myDict[w].add(num)

Categories : Python

How to avoid run time error while working with dictionary
How to safely avoid the run time error when i pass a key that is not present in dictionary? You haven't shown how you're currently trying to do it, but you can use Dictionary<,>.TryGetValue: foreach (string candidate in keys) { string value; if (items.TryGetValue(candidate, out value)) { Console.WriteLine("Key {0} had value {1}", candidate, value); } else { Console.WriteLine("No value for key {0}", candidate); } }

Categories : C#

WPF-NotifyIcon not working when moved into an XAML dictionary
You should be adding that ResourceDictionary to the MergedDictionaries section if you want to use the resources normally. Example: <Application x:Class="Notifier.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Dictionary1.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>

Categories : C#

Python 3 changing value of dictionary key in for loop not working
print does not return a value. It returns None, so every time you call your functions, they're printing to standard output and returning None. Try changing all print statements to return like so: def addFunc(x,y): return x+y This will give the value x+y back to whatever called the function. Another problem with your code (unless you meant to do this) is that you define a dictionary d and then when you define your function, you are working on this dictionary d and not the dictionary that is 'input': def RootFunc(inputDict): for k,v in inputDict.items(): if v[0]==1: d[k] = addFunc(*v[1:]) Are you planning to always change d and not the dictionary that you are iterating over, inputDict? There may be other issues as well (accepting a variable number of ar

Categories : Python

Dictionary comprehension nested for loop not working as planned
What am I missing about dictionaries? The keys are unique. You can read about dictionaries in the docs here: http://docs.python.org/2/library/stdtypes.html#mapping-types-dict

Categories : Python

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

Watch window in Visual Studio 2010 not working for classes inherited from generic Dictionary
You are looking for the DebuggerDisplayAttribute. Example: [DebuggerDisplay("Name: {LastName}, {FirstName}")] public class Customer { public string FirstName { get; set; } public string LastName { get; set; } } The debugger window will show "Name: Clinton, Bill" as a value if you create a customer named Bill Clinton.

Categories : C#

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

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

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 to use RazorPDF in Umbraco 4.11
The best place to start for what you need is here: http://our.umbraco.org/documentation/Reference/Mvc/ But no, strictly speaking you don't need a SurfaceController. You would only need one if you wanted to access the Umbraco context for the requests you are making via the controller. So if you just want to have a controller serve up your PDF, you can have a standard controller implementation. You will have to adjust your routes for this though, and this is all covered in the Umbraco documentation above. Edit: You'll need a route like this: RouteTable.Routes.MapRoute( name: "PdfRazor", url: "PdfCreator/{action}" ); You will also need to add the path to the Web.config for Umbraco to ignore, e.g: <add key="umbracoReservedPaths" value="~/umbraco,~/install,~/pdfcreator" />

Categories : Asp Net Mvc

Umbraco throwing 404
Unfortunately both your links are going to the IIS error page as well as all the other errors on the site so we cant tell what you sitemap should be, see this link for tips on how to set up the 404 page http://www.simonantony.net/knowledge-base/articles/how-to-setup-a-404-error-page-on-your-umbraco-site/ . Make sure that's working across the whole site then with you Google site map is it an XML sitemap or HTML sitemap and how have you implemented it did you use a package or made it you self.

Categories : Iis

URL rewriting in ASP.Net Umbraco
Try: <add name="301_bname" redirectMode="Permanent" ignoreCase="true" rewriteUrlParameter="IncludeQueryStringForRewrite" virtualUrl="^~/brands/(.*)" destinationUrl="~/$1" /> The virtualUrl parameter uses a regular expression to match the incoming URL. You can then use the $1 notation to pass the pattern to the destinationUrl parameter. Since both urls are on the same domain, and (I assume) within your web application, you don't need the redirect="Domain" part, and you can use relative URL paths.

Categories : Asp Net

Bootstrap 3 in Umbraco
As far as I know there is no starter kit, or package for it. But it shouldn't be too tough Create your new Umbraco site first, just a bare bones site, no themes, no kits, no packages(yet) Download the new bootstrap files and add the bootstrap img folder and css files to your StyleSheets folder, add the bootstrap.min.js to your Scripts folder. Make a new master/global template that references all of your bootstrap dependencies Make all other templates use this new template as their master. Hope this helps get you going.

Categories : Twitter

Upgrading umbraco from 4 to 6
Yes, according to the bug report you can install a Umbraco v4.11.x and then upgrade this to v6.1.x and this should work fine. The downloads are all available here: http://our.umbraco.org/download However, the easiest way to get Umbraco set up is to use NuGet in Visual Studio. So you could run the following line from the NuGet console: Install-Package UmbracoCms -Version 4.11.10 You'll have to use the console for this because if you use the Package manager, it will just install the latest Umbraco package version. Next, load your site in a browser and configure the database settings. Then upgrade using NuGet again. I find the easiest way to do this is to open the NuGet package manager in Visual Studio, select "Updates", find the Umbraco package and click "Update". This will automatical

Categories : Mysql

FileSystemProvider for Umbraco v6.1
Why is it that I spend hours trying to find the answer and then find it soon after I post? The issue was two fold: 1) I should've been implementing IFileSystem (took inspiration from AmazonS3Provider source) 2) the parameter name being passed from FileSystemProviders.config file was not included in the constructor

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

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#

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#

Umbraco not rendering IE box shadows
I'm guessing the link to your css is relative or something, it's got absolutely nothing to do with umbraco - you have full control over the html. Perhaps paste a link to your website or your html code. also for cross browser drop shadows you need something like this -moz-box-shadow: 3px 3px 4px #444; -webkit-box-shadow: 3px 3px 4px #444; box-shadow: 3px 3px 4px #444; -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#444444')"; filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#444444');

Categories : HTML

Umbraco css vs images path
Items stored in the media section will have a path like: /media/<row_id>/filename.ext Where <row_id> is literally the id of the row in the database where the media item's information is stored. One way you can determine the path of the media item is to click on the thumbnail (if it's an image) and copy what is in the address bar. You can also access the file by id via a macro using xslt or razor. Here's a razor example: @{ int imageId = 1069; var media = Library.MediaById(imageId); <img src="@media.umbracoFile" alt="" /> } However, this is a content management system, and you will no doubt have end-users managing the content and, therefore, it wouldn't make sense to place design specific images in the media section. A more full-proof approach would b

Categories : CSS

Umbraco 6.05 on Windows Azure
There are no different in term of how they store the file whether you use Web Sites or Cloud Services as long as you didn't modify the Umbraco. Both Web Sites and Cloud Services keep the file, in this case, the Media folder in their local storage unless you modify Umbraco to save into Blob Storage to have a better scaling. You can write and modify your own custom Media location or try to look at this URL http://our.umbraco.org/projects/backoffice-extensions/universal-media-picker

Categories : Azure



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