57

You don't need multiple instances. In fact, HttpClient is designed specifically to persist and be used for multiple requests (see: HttpClient.DefaultRequestHeaders). There's already a lot written about this so I'll redirect you to those resources: Do HttpClient and HttpClientHandler have to be disposed? Is HttpClient safe to use concurrently? What is the ...


40

Semantically, I would suggest using HTML5 elements more. For example, instead of... <div id="header"> <div id="logo"></div> </div> Use instead: (the ID can stay if you want it to) <header> <div id="logo"></div> </header> This would change your CSS from #header {} to just header {} It is common to ...


22

One example of where you should use other HTML Elements <div id="site1Container"> <div id="site1logo"></div> <div id="site1desc">Site description goes here.</div> </div> This should look like this <div id="site1Container"> <img id="site1logo" src="http://www.google.com/...


17

One quick remark: Never leave out the DOCTYPE (<!doctype html> for HTML 5), unless you want to work around the bugs that the browsers will emulate. EDIT: I forgot the "5" in HTML 5. Also: It doesn't really matter which DOCTYPE you use, as long it triggers Standards Mode the browser. Browsers don't differentiate between HTML versions. You could use an ...


15

Short answer: Don't create a DTO per entity. Use the exposed domain model pattern instead. Very long answer: When you say "send to the client," as it is a webapp, this really means render to the browser (or mobile app) in the servlet tier. In which case, it's typically your own teams code and there is little or no value to copying entities into DTOs. ...


11

The CSS rulesets for your #site1desc and #site2desc etc. are all the same (copy-and-pasted). Instead there could be just one class class="sitedesc" and CSS selector .sitedesc; or several ID selectors for the same ruleset #site1desc, #site2desc, #site3desc { position: absolute; left:150px; top: 20%; } Your #site1logo and #site2logo etc. ...


10

There is no guarantee that write writes out the entire buffer. This means that if (FD_ISSET(STDIN_FILENO, &fds)) rv = transfer(STDIN_FILENO, buffer, BUFLEN, sd); may lose data. Consider looping until all data gone out. As long as the portability is concerned, the timeout parameter of select needs attention. The BSD implementation doesn't change it, ...


10

the posted code causes the compiler to output several warning messages. When compiling, always enable the warnings, then fix those warnings. Here is the compile statement and the resulting warning messages. gcc -Wall -Wextra -Wconversion -pedantic -std=gnu11 -ggdb -c "untitled2.c" untitled2.c: In function ‘input’: untitled2.c:86:37: warning: conversion ...


9

If you want an honest opinion, I'd say no, this is not a good controller. I won't bother with code styles, but as far as logic goes: Conditional includes? Not a good idea. You should be writing code that could be included anywhere if necessary (but possibly not used). Using includes like this can quickly turn your project into a complete mess, especially if ...


8

You should add the DOCTYPE at the top (before the html element): <!DOCTYPE html> The meta-charset should come before the title (so the encoding is known before parsers reach it): <meta charset="UTF-8"> <title>Site Title</title> If this is a page from a whole website, and not just a stand-alone page: Your site title (which seems ...


6

Testing? Then create a simple unit test and test your API controller or your business layer classes directly. If you want to create an integration test or need a cleaner solution in production code read further. Wrapping the API calls This is just a disposable wrapper around the WebClient which can be easily reused. public abstract class ...


6

Exception itself actually inherits from a class called BaseException so: class BaseException(Exception): Seems backwards.


6

Good layout and white space. Although the logic works, I think it is very confusing, and not overly obvious. At first glance, it the if statements are very confusing. I would also rename the variables to have an Id or Code to the end of them to keep naming consistent. I think this is a good place where you could incorporate the Specification Pattern. ...


6

No I'm not sure why this question is tagged CakePHP but since it is: This is not CakePHP code =). Some specific points to elaborate: session_start, $_SESSION This should not be in any CakePHP application code - The session is started on demand whenever it is first accessed via the Session component, session helper or the CakeSession class. include_once ...


6

You've turned your IoC container into a Service Locator (happens when you pass the IoC container around as a dependency)! public void Install(IWindsorContainer container, IConfigurationStore store) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ here! Advantages The "service locator" can act as a simple run-time linker. This allows code to be ...


5

For this: public TResponse Request(TRequest request, TClient client) { try { return DoRequest(request, client); } catch (TimeoutException timeoutException) { // Log the time out exceptionLogger.DbLogException(timeoutException); // Change endpoint this.client = switcher.Switch(this.client); ...


5

General approach to build Web API without models, doesn't give the full web API capabilities. E.g: Help: You cannot have Web API help generated automatically. You cannot return error handling scenarios: status, message If you don't want to create the DTOs (Models), you can use the dynamic types. JSON formatter works well with the dynamic types.


5

LINQ is a good choice. You're querying something, so it lends itself to the task. That being said, the exception handling is atrocious. Making your return values null, some command's value from the database or some big honkin' exception text is abusing the string data type. I'd remove the try..catch altogether and let your client app handle the exception if ...


5

Python includes logging in the standard library; rather than write your own, why not use it? You can specify an output file, and handle different levels of logging according to the situation. Per the style guide, the identifiers of constants like freedns_domains should be UPPERCASE_WITH_UNDERSCORES. Also, any import statements should be at the top of the ...


5

First of all, I really liked your C++ code and even though I am not a professional I think there are some points to consider. To the future! It is 2016 so I would say we can safely use C++11 today (at least if you are not held back by embedded, an ancient compiler, etc.). There being at least three major compilers with C++11 support this shoud not be a ...


4

I would move the operations on the web service out to their own class: public class AccountRepository { private readonly void _webService; public AccountRepository() { //authentication header var header = new AuthenticationHeader { header.UserName = ""; ...


4

Building on @Drewverlee's answer, I would consider renaming BaseException to APIException, or something of the like. Also, I don't think passing app as an argument is best practice, I would recommend using the function as a decorator on your endpoints instead: # Your imports from application import app # Or whatever your non-relative reference is def ...


4

A Linq-to-SQL DataContext is an IDisposable, your code isn't calling its Dispose() method. Wrap it in a using block to ensure proper disposal. I would use var in the TestProjectLinqSQLDataContext instantiation as well, but that's just personal preference. I find Foo bar = new Foo() redundant. Using SingleOrDefault assumes that the SP is returning only 1 ...


4

public UserProfile AddSocialLink(string userName, UserSocialLink userSocialLink, string socialLinkType) Shouldn't the socialLinkType be a property of the UserSocialLink class? It seems odd to me that the code has to pass a string along with the object in order to tell the method what type it is. That said, I really do like that you're checking the database ...


4

Your first comment is a lie: # List of domains that should point to the current IP freedns_domains = set(["foo.example.com"]) It's a set, not a list. Plus, one should write {"foo.example.com"} for a set literal. You do a lot of urllib.request.urlopen(ip_check_url).read().decode("utf-8") This should be more like with urllib.request.urlopen(ip_check_url) ...


4

A few things you can do. To help in the future (in case of Def being added, etc.) you can make some of these functions generic. The caveat, is that the way you have it set now you would have to make an interface that AbcImportRequest, etc. would implement. Let's assume all the ImportRequest objects implement the following interface: public interface ...


3

I use volley library to do these work. Volley is a library developed by Google, it is tried and tested. It has other features network response caching, network image caching, request cancelation etc..


3

Your idea seems quite feasible, I just had a brief look through and these would be my suggestions: TaskResult class "code" and "message" members should probably be encapsulated via getter/setter with proper namings. ConnectionManager class Depending on your scenario maybe you should consider calling "shutdown" on your mClient member. When creating your ...


3

A common pattern for your scenario is to create a action...()-method for every page and extract the routing (your outer if) to a separate class. Rename your Model to UserModel and create new Models for every other entity which exists in your system. In a similar way you could group your pages/actions to different controller. In general you should also step ...


3

I'm not sure why your change all of a sudden would expose data to the business layer when it didn't before. If you have a pattern of methods which look like this: public string MyServiceCall() { try { JObject incomingRequestJson = retrieveJson(); JObject returningJson = new JObject(); // do stuff return ...


Only top voted, non community-wiki answers of a minimum length are eligible