Hacker Newsnew | past | comments | ask | show | jobs | submit | more parham's commentslogin

Thank you for all your efforts and hard work.

It has changed a lot of lives and will continue to do so for a long time.

Enjoy the vacation and take care of yourself.


I can tell you Taarof is one of the worst traditions us Iranians have, it's like playing reverse poker.

Taarof is mostly based on context, with a stranger it's never genuine but with within friends and family you will want to pull your hair out. You will begin to pay for stuff just to skip the awkward Taarof, but will have no choice to engage in it when the other person has to give in to the Taarof.


just two, me and the OP


I have to say these three do wonders and are critical for sustainable productivity.


Meditating/relaxing in bed before sleep I think is pretty important. Just taking 10-30 minutes to completely relax the muscles, stretch everything, forget everything. Pine trees, crickets, water lapping over white sands.

To do it well, I focus on the extremities of the toes and fingers, and give them a really good stretch, then let them relax. Then work inwards. Eventually you'll feel like you're floating, and get a good night's sleep. But I also mean stretch your eyebrows, your jaw etc. Stretch everything possible and let it relax. Its amazing where you can hold tension.


I don't have much experience with stretching before sleep, but sounds like it would work, and work well! I only use meditation to clear my mind so I can get some peace and away from the problem I've been trying to solve during the day, otherwise I would be awake all night!

I really do prefer weight training an hour or so before sleep, it just gets the blood flowing without increasing the heart rate too much.


I agree, I think a good exercise/weight session is equally as good, if not better. Or both. We're pretty sedentary beasts, and I think that can cause a lot of problems.


Might be worth while looking at the video below for more Pythonic gems like this one.

https://www.youtube.com/watch?v=OSGv2VnC0go


Since when did Iran and Turkey become enemies?


Turkey is a NATO member. Additionally, Iran supports Assad in Syria while Turkey generally supports (some of) the rebels.

Turkey is generally seen as the leader of the secular Islamic world, while Iran is seen as the leader Shia Islam.

While they aren't shooting enemies they aren't exactly allies either.

More interestingly, the chart shows Turkey and Iraq as enemies, while in fact Turkey and Iraqi Kurdistan have recently become quite close allies (!!) based on a oil and trade[1][2].

[1] http://online.wsj.com/articles/conflict-shows-new-closer-tur...

[2] http://www.washingtoninstitute.org/policy-analysis/view/turk...


Iran and Turkey became enemies when Iran overthrew the brutal dictatorship of the Shah. Same time the US switched from being pro- the Iranian nuclear program to being anti-.

Highly surprising! Nah, not really.


Different religions. Turkey is "sunni"/secular. Iran is Shi'a/secular. (but the other way round, Turkey's population is "moderately" sunni muslim, the state is aggresively secular. Iran, the population, I think is fair to say, is secular, the state is aggresively Shi'a muslim). The sunnis are the ones that are organising things like ISIS, and the religious cleansings ISIS is doing.

Problem is that one of the values of islam is to militarily dominate, so aside from Lebanon (and formerly Iraq), there is no example of a state with powre sharing. Even in Lebanon there is only power sharing between Christians and muslims, not between different sects of muslims. (the difference being that Christians don't see the need to exterminate muslims (just convert them, eventually), nor do muslims want to exterminate Christians, just dominate them (talking about the values of the religions here). Sunni's do want to exterminate Shi'as and vice-versa. To put it bluntly: sharia is pretty clear on the need to kill any muslim who is not the same sect as you are. But Christians/Jews can get the choice dhimma or death. So Lebanon will not blow up as easily as Iraq will)


Turkey is probably about as strong an opponent of ISIS as there is in the middle east.

Edit: the parent comment was edited while I was writing that. There is a lot I disagree with now, bit the biggest factual problem is the idea that Lebanon "won't blow up like Iraq" seems to ignore 2 decades of civil war in Lebanon.


Not really. Let's say that Erdogan and ISIS agree on goals, absolutely not on means, and Erdogan stands to lose a LOT if ISIS doesn't back down. They are not enemies, even if you have a point that they're absolutely not friends either.

You're right of course that Lebanon hasn't been very stable.


You think Erdogan wants an Wahhabist caliphate centered in Bagdad that claims parts of Turkey? Not likely!

I'm trying to imagine what goals they share?

I guess Turkey probably doesn't want an Iranian-dominated Iraq (and nor does ISIS of course!), but Turkey can probably accept that to some degree provided Iraqi Kurdistan remains autonomous and provides a buffer zone. Beyond that I can't see anything they really have in common.


Of course not. I think he wants the ottoman empire back. He wants a non-wahhabist (but still quite strict) caliphate centered in constantinople. Most of all he wants the basic property of the caliphate : a theocracy.

He has, after, said exactly that. Cost him votes, but not enough.

As I said, he's quite sympathetic with what they're doing, he's doing the same. He's just behaving like any Ottoman vasal did a mere 100 years ago. He agrees with the need for a caliphate, probably even with the method. He just disagrees on the caliph and the capital. Like any ottoman vasal, tough, he sees them as competition as well as potential allies.


Iran is Shi'a/secular

Islamic Republic of Iran is a theocracy.


Bush was republican, doesn't mean all Americans were right-wing.


Exactly the distinction I wanted to make. Iran is a theocracy, with a population that has at least a significant secular fraction.


Is your purpose in drawing this distinction to claim that the secular tendencies of the population of Iran is an effective counterweight to the ambitions of its theocracy?


US ambitions keep the theocracy powerful. Since they overthrew the US backed dictator which had overthrown the secular, progressive democratically elected government of Mossadegh.

Every time the US threatens Iran or imposes sanctions, or funds and arms a terrible dictator in Iraq so he can bomb Iranian cities and drop poison gas on them killing hundreds of thousands of people. The theocracy steps up to the plate the only force powerful enough to stand up to the US.

Any more liberal voices get drowned out by the need for security from the US and its interests.


Same could be said about Django and APIs!


Been writing a Django-based API-heavy app and it still feels very Django. DRF fits the ORM like a glove and there's a Django way of doing things that runs throughout. Models ≈ ModelForms ≈ ModelSerializers ≈ ViewSets ≈ ModelAdmin. Certainly never feels like I'm fighting the framework(s).


Good point, but my impression of this tool is that it's more intended for quickly tacking an external API onto an existing Django app, and not so much for building an internal API for a client-side MVC app (Angular/Ember/Backbone etc). It can certainly be used for that too, but Django is kind of overkill for that use case, and a lighter-weight framework like Flask with a REST plugin like Restless and (optionally) an ORM plugin like SQLAlchemy is probably sufficient.


My thought too but if your data is complex you should consider building an API first using an ORM more powerful than Django's (e.g. SQLAlchemy) then use Django to handle users and then allow your users to access the API directly via signed requests or something... that way you get good performance without network/Django ORM overhead.


I prefer SQLAlchemy, but it definitely has just as much overhead as django's ORM. This is just a microbenchmark, but notice how when frameworks are making raw DB queries they stomp the ones using ORM:

http://www.techempower.com/benchmarks/#section=data-r9&hw=i7...

Looking at only python frameworks using ORM, Flask with SQLA hits 85% of the requests/sec of Django using pypy, and only 73% on stock python. Django has decently lower latency as well (450ms django, 550ms flask pypy, 600ms flask stock python):

http://www.techempower.com/benchmarks/#section=data-r9&hw=i7...

Really, if performance matters at all and you want an ORM use Java. The fastest python solution using an ORM is a tenth as fast as the Java solutions, with literally 10x the latency. :P Flask making raw db queries gets within 2x of this, as does bottle.

http://www.techempower.com/benchmarks/#section=data-r9&hw=i7...


These numbers are somewhat misleading, and the phrasing may confuse people.

> The fastest python solution using an ORM is a tenth as fast as the Java solutions

This may be true if your bottleneck is the ORM in the first place (this is relatively easily verifiable by running a profiler on your python program, comparing the results against (e.g.) EXPLAIN ANALYZE output, etc.)

I run a service with a decently-sized database (over 100G); so far all the bottlenecks were at the "query execution in the DB" level. I use lower-level SQLAlchemy primitives to form the queries, and check the resulting raw SQL against the raw SQL queries that I had designed for the DB before. If you know what you're doing, SQLAlchemy will know, too.

Use cases and situations vary. But the way you phrase those particular benchmarking results is somewhat misleading.


I wasn't refering to performance, but the queries you could do. If performance was an issue and the ORM was the bottle neck then I would use raw SQL and scrap the ORM altogether. Thanks for this benchmarks though good to know that info! :)

Edit: The overhead thing was a secondary point my main point was handling data.


No not really. Django makes a great API framework.


Depends on your data, if you don't need joins/complex queries Django indeed is a great framework, though if an API is all you need a lighter framework might be worth looking into.


Django handles joins just fine using the double underscore in the filter method.

It also provides an easy to use means of doing complex queries via raw SQL:

MyModel.objects.extra(select = {'blah blah raw sql'}) will return a regular queryset.


Django's ORM seems to be one of the areas they're consistently improving upon. Sure it's not SQLAlchemy. But SQLAlchemy is just an ORM, while Django is quite a bit more. Though I really love how SQLAlchemy separates it's core from the higher-level ORM.


Django isn't built to be the main backend for an API, I've previously used Tastypie and it's just not flexible enough, you should really consider using Flask if you're planning to go API first.


It can be used as the main backend for an API just fine. It's also very easy to override just about every piece of what DRF offers. This is pure, unsubstantiated, subjective FUD.

Use the tool that you are most comfortable with, change it up if/when you get big or busy enough to have to. There are some huge sites running Django/DRF successfully.


Well it really depends on the data you have. It can easily be substantiated, it's like saying I want to compete in F1 let me put the biggest engine in this tanker truck, in other words do you need most of Django's layers for an API? That's why I said if you're "planning to go API first" (Note: I love Django for building sites not APIs)


This analogy really isn't useful at all. You aren't ever going to use 100% of every tool your site is built on, and there's no shame in that. If you don't end up using everything that Django does, no big deal.

There are some incredibly large sites with rich APIs that run Django very successfully, so I'm thinking that this is all some pretty subjective generalization that is of limited use.


Why do you think flask is better?


Well Flask is just the "glue" the real thing I like is its flexibility, which allows you to use tools that fit your needs, which for handling data SQLAlchemy blows Django's ORM out of the water. Don't get me wrong I love Django and I do use it a lot for websites but for handling data... it's restrictive to say the least.


It doesn't blow Django's ORM out of the water. It provides some extra functionality for doing the more unusual queries using the ORM, but all of those things are achievable in a terse, neat fashion Django by plugging in raw SQL into the gaps.

There's no real productivity boost between the two in my experience. Those holes in Django's ORM that need to be plugged by raw SQL aren't all that common anyhow. The VAST majority of SQL queries you will need the Django ORM can handle.

In projects I've worked on that don't do weird, strange or bad things with the database (e.g. ignoring foreign keys), the total number of custom, raw SQL queries has been between 5 and 20. Using an ORM for them instead wouldn't have saved more than a couple of lines of code total, if that.

What you DO get with Django's ORM that you don't with SQL Alchemy is the benefit of integration with all of the other django tools and modules - that saves you having to write a TON of code.


Well it's really hard to sell SQLAlchemy when you have never used it (I'm assuming, correct me if I'm wrong), read this blog for an full comparison http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/ (quite old).

For the Django part of your comment the other modules it provides are useful for building a website but not an API which was in the root comment. Indeed for a website Django is my preferred tool too. Although in a project where I know the API is the core I would choose something lighter weight (using flask in my current project but learning from comments here Pyramid is something to look into too) and then build the portal in Django, handle user authentication there and allow access to the authenticated users to the API via requests signed in Django or direct access via API keys. In my experience it's the fastest/most flexible approach in terms of dev.


>Well it's really hard to sell SQLAlchemy when you have never used it (I'm assuming, correct me if I'm wrong)

Consider yourself corrected.

>read this blog for an full comparison http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/ (quite old).

That's not a full comparison. It actually doesn't even touch on some of the advantages to using SQLAlchemy (i.e. in the more complex queries). It even says this at the bottom. Did you see that?

>For the Django part of your comment the other modules it provides are useful for building a website but not an API which was in the root comment.

So now APIs don't require integration work? When I build ANYTHING I want to be able to have as large an ecosystem of libraries to pull from as possible because it will save me from writing unnecessary code and reinventing the wheel. First thing I do before building anything is to check on pypi to see if somebody wrote it first.

Too many junior developers make the mistake of thinking that their problem, project or app is somehow a unique snowflake and end up reinventing the wheel because they had no idea the wheel existed. Semi-experienced developers will still make this mistake by making bad architectural decisions in the name of flexibility or performance that end up locking them out of library ecosystems that means they are forced to reinvent the wheel even when they know it exists.

Being an experienced architect means (among many other things) knowing when to make the trade off between not railroading your code unnecessarily and standardizing it enough to let you use the vast array of free libraries out there.

>Although in a project where I know the API is the core I would choose something lighter weight

It's a myth that Django is heavy weight. You can make a django app with about 10 lines of code in one file using just the URL router if you really want to. Each one of the components can be swapped out nearly seamlessly exactly like with Flask.

You might not want to use it because it's slow, however, but flask will be too.


> That's not a full comparison. It actually doesn't even touch on some of the advantages to using SQLAlchemy (i.e. in the more complex queries). It even says this at the bottom. Did you see that?

Well those are most of the comparisons that could be made, from the top of my head I can't think of any other features that the two share.

> Too many junior developers make the mistake of thinking that their problem, project or app is somehow a unique snowflake and end up reinventing the wheel because they had no idea the wheel existed. Semi-experienced developers will still make this mistake by making bad architectural decisions in the name of flexibility or performance that end up locking them out of library ecosystems that means they are forced to reinvent the wheel even when they know it exists.

Doesn't sticking with Django lock you into the ORM and it's capabilities itself? Unless the library you're using is a Django extension you have the same pool of libraries available to you, so that's an invalid point.

> It's a myth that Django is heavy weight.

I saw that blog post too, however by heavy weight I meant all the remaining stuff you don't need for an API, e.g. you don't need the template, view, form, ... layers

Again my argument is based on building an API not a Website.


>Doesn't sticking with Django lock you into the ORM and it's capabilities itself?

Not really. You're always free to use raw SQL, and it makes it pretty convenient to do so for the occasions when what you want exceeds the ORM's capabilities (which will likely happen).

>Unless the library you're using is a Django extension you have the same pool of libraries available to you, so that's an invalid point.

I was talking about the django extensions. Stuff like a rate limiter, for instance, or a pluggable social media authentication backend. Or the one mentioned by the OP. All useful when making APIs.

>I saw that blog post too, however by heavy weight I meant all the remaining stuff you don't need for an API, e.g. you don't need the template, view, form, ... layers

You're not railroaded into using any of those things if you don't want to (the same way you are with RoR). All of them are optional and most of them are even swappable without too much effort.


So this argument has now been forked into Django's ORM capabilities and wether or not you should use Django for an API. The former is up to taste, the latter is not.

> Not really. You're always free to use raw SQL, and it makes it pretty convenient to do so for the occasions when what you want exceeds the ORM's capabilities (which will likely happen).

I can't argue with this, fine.

> Stuff like a rate limiter, for instance, or a pluggable social media authentication backend. Or the one mentioned by the OP. All useful when making APIs.

Rate limiter is framework independent, can be built using Redis with a few lines of code. So not applicable.

Pluggable social media authentication backend is for websites not APIs for APIs you most commonly use API key/secret. for an api you can still build your portal in Django and do all authentication/whatever there and simply sign requests for the API.

> You're not railroaded into using any of those things if you don't want to (the same way you are with RoR). All of them are optional and most of them are even swappable without too much effort.

I am familiar with Django, and I know that you can (not the ORM though), but do you want to drive a monster truck when all you need is a car to get around? You could, you will get odd looks though.

Since you can't use Django's ORM anywhere else you need to use something that another "car" supports.

I'll leave you with: "if all you have is a hammer everything looks like a nail"


>So this argument has now been forked into Django's ORM capabilities and wether or not you should use Django for an API.

The two are inextricably linked as far as this thread is concerned.

>Rate limiter is framework independent, can be built using Redis with a few lines of code. So not applicable.

Mine is apparently 200 lines of code (library total) and tied to the framework. I guess you are more of a "reinvent the wheel" type programmer.

>Pluggable social media authentication backend is for websites not APIs

APIs do all manner of different things.

Last time I built an API it was a back end for an iphone app. It needed an authentication backend. By using a pluggable framework I could not only let the app log in/sign up using facebook tokens, I could with one added line add twitter or ~40 other back ends, saving me from... reinventing the wheel.

> for an api you can still build your portal in Django and do all authentication/whatever there and simply sign requests for the API.

Or you could just use django for the API as well the portal since it handles everything about making APIs pretty well (with the exception of high load APIs).

>for APIs you most commonly use API key/secret.

For APIs there are many common ways of doing authentication. There's no standard. Basic auth over https, token, oauth, key/secret, cryptographic signature. If you ascribe to a "one true way" you lack judgement and experience.

>I am familiar with Django, and I know that you can (not the ORM though), but do you want to drive a monster truck when all you need is a car to get around?

I already refuted your point that it was a monolithic heavyweight beast. It's composed of multiple small modules all of which exhibit loose coupling and each of which can be used independently or not at all.

>Since you can't use Django's ORM anywhere else

Utterly false. You can use it wherever you like, independently of everything else (sometimes I do that).

Feel free to argue that you don't like it or it's wrong for whatever situation but please refrain from making shit up to justify your point.

Some advice also: curb your instinct to reinvent the wheel, no matter how simple that wheel may seem.


I'm not arsed to explain to you half of what is wrong with that comment, wtf I know you can use the ORM outside of Django but why the f*ck would you.

You're just arguing like a 10 year old fan boy now. Django is great for sites I love it. I also use other tools when I need different things. As for reinventing the wheel it's a very simple code snippet taken from a reliable source then changed to fit needs. So go home sleep learn new things... Don't attempt to build the next OS in Django.


I am a die hard flask fan. I would highly recommend you look @ Pyramid. Much better for APIs than Flask, especially if it's core to your business.


Why do you think pyramid is better?


Flask's import time side-effects and has global objects everywhere. It's great for a quick hackathon and a great eco-system, though arguably you can just use Pyramid for that.

In my experience, growing bigger with Pyramid has been much easier than it has been w/ Flask. We found ourselves writing most of Pyramid using Werkzeug when it would've made sense to start off with Pyramid in the first place.

Pyramid's design for extensibility and design decisions are solid and really make a difference if you're building a real app vs a toy app.


I was wounded in what made VIM flake slow while I was using Flask, I'm guessing it's the amount of modules imported at one go. Thanks for making me aware of Pyramid I will look into it further.


Isn't that problem gone if you follow the app factory pattern? Then you only get fairly empty objects during import time.


You only return a dictionary from Pyramid views and based on the request, you can choose a renderer like JSON. Look at this example[1] Steps 3, line 16-19. Basically you can develop a Rest API with template rendering side-by-side and you don't even need a framework for it like DRF!

[1]: http://static.agendaless.com/pycon2014/json.html


Instead of this:

    # Do this  
    lyrics_set = set(lyrics_list) # Linear time set construction  
    words = make_wordlist()  
    for word in words:  
        if word in lyrics_set: # Constant time  
            print word, "is in the lyrics"
You could do this:

    lyrics_set = set(lyrics_list)  
    words = set(make_wordlist())  
    matched_words = list(lyrics_set & words)  
    for word in matched_words:  
        print word, "is in the lyrics"


Of, off the top of my head:

    for word in (set(lyrics_list) & set(words)):
        print('{} is in the lyrics'.format(word))


Even shorter, nice. How about this one liner, the last bit is looking a bit messy any ideas?

    print " is in the lyrics \n".join([set(lyrics_list) & set(words)]), "is in the lyrics"


How about

  >>> lyrics_list = ["her", "name", "is", "rio"]
  >>> words = ["is", "rio"]
  >>> print '\n'.join("{} is in the lyrics".format(word) for word in set(lyrics_list) & set(words))
  rio is in the lyrics
  is is in the lyrics


Heh, I just replied with pretty much this exact code to someone else trying to make it a one-liner.

Yes, it's possible. I would never, ever publish code like this, though. It's opaque.


Just because it can be written as a one-liner doesn't mean it should be written as a one-liner :)

Don't ever do this.

    print('\n'.join(['{} is in the lyrics'.format(word)) for word in (set(lyrics_list) & set(words))])


I never said it should, it was a challenge.


   matched_words = set(lyrics_list).intersection(make_wordlist())


Power of visuals, so pretty.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: