api-design

When do I define objective-c methods?

↘锁芯ラ 提交于 2019-12-18 10:01:45
问题 I'm learning Objective-C, and have a C/C++ background. In object-oriented C++, you always need to declare your method before you define (implement) it, even if it is declared in the parent class. In procedural-style C, IIRC, you can get away with just defining a function so long as it is only called from something else in the same compilational unit (ie. the same file) that came later on in the file (well, provided you don't declare it elsewhere with "extern"). Now, in Objective-C, it appears

How to do inclusive range queries when only half-open range is supported (ala SortedMap.subMap)

隐身守侯 提交于 2019-12-17 21:10:09
问题 On SortedMap.subMap This is the API for SortedMap<K,V>.subMap: SortedMap<K,V> subMap(K fromKey, K toKey) : Returns a view of the portion of this map whose keys range from fromKey , inclusive, to toKey , exclusive. This inclusive lower bound, exclusive upper bound combo ("half-open range") is something that is prevalent in Java, and while it does have its benefits, it also has its quirks, as we shall soon see. The following snippet illustrates a simple usage of subMap : static <K,V> SortedMap

How to do inclusive range queries when only half-open range is supported (ala SortedMap.subMap)

点点圈 提交于 2019-12-17 20:57:49
问题 On SortedMap.subMap This is the API for SortedMap<K,V>.subMap: SortedMap<K,V> subMap(K fromKey, K toKey) : Returns a view of the portion of this map whose keys range from fromKey , inclusive, to toKey , exclusive. This inclusive lower bound, exclusive upper bound combo ("half-open range") is something that is prevalent in Java, and while it does have its benefits, it also has its quirks, as we shall soon see. The following snippet illustrates a simple usage of subMap : static <K,V> SortedMap

Tweepy - Exclude Retweets

限于喜欢 提交于 2019-12-17 18:24:31
问题 Ultimate goal is to use the tweepy api search to focus on topics (i.e docker) and to EXCLUDE retweets. I have looked at other threads that mention excluding retweets but they were completely applicable. I have tried to incorporate what I've learned into the code below but I believe the "if not" piece of code is in the wrong place. Any help is greatly appreciated. #!/usr/bin/python import tweepy import csv #Import csv import os # Consumer keys and access tokens, used for OAuth consumer_key =

What is the proper REST response code for a valid request but an empty data?

 ̄綄美尐妖づ 提交于 2019-12-17 02:53:08
问题 For example you run a GET request for users/9 but there is no user with id #9. Which is the best response code? 200 OK 202 Accepted 204 No Content 400 Bad Request 404 Not Found 回答1: TL;DR: Use 404 See This Blog. It explains it very well. Summary of the blog's comments on 204 : 204 No Content is not terribly useful as a response code for a browser (although according to the HTTP spec browsers do need to understand it as a 'don't change the view' response code). 204 No Content is however, very

Why does int num = Integer.getInteger(“123”) throw NullPointerException?

◇◆丶佛笑我妖孽 提交于 2019-12-17 02:35:22
问题 The following code throws NullPointerException : int num = Integer.getInteger("123"); Is my compiler invoking getInteger on null since it's static? That doesn't make any sense! What's happening? 回答1: The Big Picture There are two issues at play here: Integer getInteger(String) doesn't do what you think it does It returns null in this case the assignment from Integer to int causes auto-unboxing Since the Integer is null , NullPointerException is thrown To parse (String) "123" to (int) 123 ,

What are best practices for REST nested resources?

时光怂恿深爱的人放手 提交于 2019-12-16 22:34:32
问题 As far as I can tell each individual resource should have only one canonical path. So in the following example what would good URL patterns be? Take for an example a rest representation of Companies. In this hypothetical example, each company owns 0 or more departments and each department owns 0 or more employees. A department can't exist without an associated company. An employee can't exist without an associated department. Now I'd find the natural representation of the resource patterns to

What should be the return value of a custom function addEdge in a new class based on BGL?

五迷三道 提交于 2019-12-13 15:25:14
问题 I try to implement a graph class based on https://stackoverflow.com/a/950173/7558038. When adding an edge I return the edge descriptor of the added edge, but if the edge already exists, it shouldn't be added. What shall I return then? Unfortunately, null_edge() does not exist (unlike null_vertex() ). It could be an std::pair<e_it_t,bool> with an appropriate edge iterator type e_it_t , but how can I get an iterator to the new edge? 回答1: Don't use that class that is almost 10 years old. It is

Rest api - adding tags to an entity

允我心安 提交于 2019-12-13 07:03:55
问题 I am designing a rest api in which I need to add tags to an entity. The entity is created using POST /content where the json data is passed in the request body. I want to allow adding tags while the POST request is being made, and also later on. This is what I have. POST /content?tag=foo&tag=bar PUT /content/{id}?tag=baz&tag=bat Now, how do I allow deleting tags? What would be a better approach> 回答1: Short answer: is you would do it like this Assuming your entity is the content in your to

How to RESTfully support the creation of a resource which is a collection of other resources and avoiding HTTP timeouts due to DB creation?

独自空忆成欢 提交于 2019-12-13 01:03:07
问题 In my application I have the concept of a Draw, and that Draw has to always be contained within an Order. A Draw has a set of attributes: background_color, font_size, ... Quoting the famous REST thesis: Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. So, my collection of other resources here would be an Order. An Order is a set