Not able to view 'contentsOf' function of NSData in swift4 and xcode 9.2? - nsdata

I have been scratching my head for more than a couple of days now as to how to get 'contentsOf' init method from NSData.
Today I tried using the init methods with a (.)dot operator,
i.e Data.init(contentsOf: fileUrl! as URL)
and at last it worked.
However, I am not very sure about it. Can someone please guide me through what is happening. It might be something very trivial that I might be missing.

Related

How can I fix the internal error in Django?

I don't have a lot of experience in Django and I am a fairly green developer. When I run the localhost I keep getting a Internal Error. I have tried most of the solutions to similar problems here and none of them works. Can anyone help me? The code is not mine so I don't want to alter it as such either.
Here is a picture of the errors I keep getting:
The only thing you can do without altering the code is to enter the value "shop_all_art" in the HomePage table in the database.
Do not share code via images. You should also share the related code.
Your stacktrace clearly says, that Python is not able to access first element of HomePage.objects.filter(value='shop_all_art') in file bidgala/bidgala/pages/views.py. all_art_img is most probably empty.
Looks like all_art_img is empty.
you should check if a Query has any elements before with a method such as
if all_art_img.exists():
all_art_img[0]

How to use merge tool "internal:fail" programmatically?

I am new in the Mercurial, and I am interested in the merging process. I would like to see how it happens programmatically, but something did not work out. I do not understand how to call the option, as we do it from the console using the hg merge --tool internal:fail command.
I did it like this
commands.merge(ui, repo, tool='internal:fail'),
but it still runs the default kdiff3.
I tried to do this
ui.setconfig('ui', 'merge', 'internal:fail')
commands.merge(ui, repo),
but it works like the previous one.
If someone understands what I'm doing wrong and how to fix it, please answer me.
Thank you for your attention to my question, have a good time =)
I managed to find the answer to my question, if someone needs it, look
We need to override the repository as follows:
def reposetup (ui, repo):
repo.ui.setconfig ('ui', 'merge', 'internal: fail') # or smth else, for example "merge3"
repo.ui.setconfig ('ui', 'interactive', 'no')
After this, the merge command will follow the configuration we defined =)

Authentication with taffy

This is Something I am trying my head around but I am not sure why I am not able to grasp this thing. I am reading articles and wiki of taffy but somehow I am getting it. Like this:
https://github.com/atuttle/Taffy/tree/master/examples/api_requireApiKey
I am going down by the following approach:
I have created a table called as: apikeys, The table has just 3 columns, authid,apikey,authtoken
now if i manually add some key and token, how should i pass it to my requests to call it from 3rd party application.
and eventually this is hardcoded, how can i change my token every few hours and if application detects that token has been changed or not matching, what should i call to re-authenticate it again with new token and keep it alive for next few hours
If rather than solving, someone can point me to right direction, that will be great.
I tried reaching the author of taffy, but he is quite busy to answer the questions i have, everyone is pointing me to docs and docs does not tell me anything about this section.

i need to restart django server to make my app properly work

so i made a python script to grab images from a subreddit (from Imgur and imgur albums). i successfully done that (it returns img urls) and wanted to integrate it into django so i can deploy it online and let other people use it. when i started running the server at my machine, the images from subreddit loads flawlessly, but when i try another subreddit, it craps out on me (i'll post the exception at the end of the post). so i restart the django server, and same thing happen. the images loads without a hitch. but the second time i do it, it craps out on me. what gives?
Exception Type: siteError, which pretty much encompasses urllib2.HTTPError, urllib2.URLError, socket.error, socket.sslerror
since i'm a noob in all of this, i'm not sure what's going on. so anyone care to help me?
note: l also host the app on pythoneverywhere.com. same result.
Using a global in your get_subreddit function looks wrong to me.
reddit_url = 'http://reddit.com/r/'
def get_subreddit(name):
global reddit_url
reddit_url += name
Every time, you run that function, you append the value of name to a global reddit_url.
It starts as http://reddit.com/r/
run get_subreddit("python") and it changes to http://reddit.com/r/python
run get_subreddit("python") again, and it changes to http://reddit.com/r/pythonpython
at this point, the url is invalid, and you have to restart your server.
You probably want to change get_subreddit so that it returns a url, and fetch this url in your function.
def get_subreddit(name):
return "http://reddit.com/r/" + name
# in your view
url = get_subreddit("python")
# now fetch url
There are probably other mistakes in your code as well. You can't really expect somebody on stack overflow to fix all the problems for you on a project of this size. The best thing you can do is learn some techniques for debugging your code yourself.
Look at the full traceback, not just the final SiteError. See what line of your code the problem is occurring in.
Add some logging or print statement, and try and work out why the SiteError is occurring.
Are you trying to download the url that you think you are (as I explained above, I don't think you are, because of problems with your get_subreddit method).
Finally, I recommend you make sure that the site works on your dev machine before you move on to deploying it on python anywhere. Deploying can cause lots of headaches all by itself, so it's good to start with an app that's working before you start.
Good luck :)

AntiForgeryToken HtmlHelper throwing NotImplementedException when run within a RazorGenerator class

I'm using RazorGenerator to unit test my Razor/MVC3 per David Ebbo's post here http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html and every time I attempt to use the AntiForgeryToken HtmlHelper (with no method arguments), it throws a NotImplementedException. What gives? As best I can tell, both my cshtml file and the view.generated.cs the correct method in System.Web.Mvc.dll, in the System.Web.Mvc namespace's HtmlHelper class. I've downloaded the latest source for the RazorGenerator project and don't see the word "forgery" contained within it anywhere, so I don't think I'm getting confused about exactly which HtmlHelper.AntiForgeryToken() method I'm hitting.
The code sample of my unit test follows:
[Test]
public void Index_RendersView()
{
var view = new Index();
// For test to succeed, this should not throw exception
view.RenderAsHtml();
}
Pretty basic. I'll spend some time digging under the hood to figure this one out and will follow up here if I figure this one out, but in the meantime I'm wondering if anyone else has encountered this and already worked out a solution.
I corresponded with David Ebbe, one of the (or, the) project owners on CodePlex, and he altered something within the RazorGenerator project source to fix this. Remarkably, he had it fixed within less than 1/2 hour of me asking the question on the CodePlex board.
I'm going to vote to have this question deleted since I don't think there's any value to keeping it around this site.