Apache: handle compression for large static XML files

My site (hosted by Apache 2.4 on ubuntu 14.04) must provide some large XML files (more than 200Mb). I choose to compress them to speed up the download process (.tar.gz) but recently my users need the flat version (no compression). Would it be safe to enable gzip compression for xml files and left them uncompressed? I mean, for small XML files, Apache effort should be insignificant but with large files?

Where can I find more resource about how to handle huge input for a coding problem [on hold]

Take this question as example, https://leetcode.com/problems/game-of-life/

What about the input size is 1TB, 2TB that we can not accommodate the whole input data in memory. To this kind of question, what’s the proper term to search for this sort of questions? Is there any recommended book to read for this kind of question?

My idea for this question is to read three rows in memory at once. And shift a row at a time.

handle file downloads from the server

I am wondering if the following would be a good technique to allow user to download files from the server in the below scenario:

Info about the scenario:

User logs into a system (HTML,JQuery and CSS, Javascript based), There is a Download button in the UI. Clicking on it triggers a backend Java Message based (JMS)process which uploads a file on the server. This process could take few minutes to an hour depending upon how long the back end process takes to generate CSV files and upload it onto a server.

Note:JMS can handle asynchronous requests from the U so I am not worried about browser freezing after first Download click.

Approach I am thinking:

1) Right now I am not sure how I am going to notify user once files are downloaded but let’s say user clicks on the button and returns back after 30 minutes and let’s say files are ready.

2) I am planning to show a new button(which could say Download files from here) after user logs back in after 30 minutes. Maybe I would hide the original Download button in this scenario. This new button will only appear if files are present on the server. Otherwise, I would keep showing the original Download button and maybe I could change the text of original Download button to Come back later as soon as user clicks on it.

Does the above approach sounds good or is there something better I could do. Any better ideas if anyone can share, that would be great.

Please let me know if I can answer any questions.Thanks

How does VirtualBox handle NAT networks i.e., where are NAT tables located? [on hold]

I am trying to understand NAT networks. I understood that it helps in translating Private addresses to public addresses for server to client communication (usecase specific to VirtualBox NAT type network). But, where to see these NAT tables?

I am using my windows host. Is it in memory space of a windows process and can we see it with any command?

User class: How do I handle different user “subjects” and still keep my single responsability principal?

I have a User class, this class handles things like:

  • login (UserAuthenticateModel)
  • Handle user sessions: user login tokens, fetching user from session if set in session, ect’ (UserSessionsModel)
  • Fetch & Set user data to populate $ this user object. (UserFetchModel)
  • Update & change my user data (to this user object – and in the database) (UserUpdateModel)

I’m asking out loud and please correct me if I’m wrong: Does every point is a single responability of some sort of subject inside the “User” class and needs a different class?

I’ll describe 2 examples with some code:

  1. Setting sessios: Insead of just pasting a whole bunch of code in my construct that “does something with sessions”, I use a UserSessionsModel specifically with the method that does whatever it has to do – get data from session if exist. single responability – Setting/changing my user sessions, and populating my user object. and some of this session handling methods might be used elsewhere (example 2).

Code ex:

User class  {      public function __construct()     {         # look for a user in the session if set         $  this->getFromSession();     }      public function getFromSession()      {         # Create UserSession obj         if ( !$  this->UserSessions instanceof UserSessions )             $  this->UserSessions = new \myapp\Models\User\UserSessionsModel();          $  this->UserSessions->getUserFromSession($  this);     }  }  class UserSessionsModel {      public function getUserFromSession(User $  User)     {         if (Session::exists(Config::$  user)) {              $  session = unserialize(Session::get(Config::$  user));              $  User->id             = $  session->id;              $  User->firstName      = $  session->firstName;              $  User->lastName       = $  session->lastName;              $  User->userName       = $  session->userName;              $  User->email          = $  session->email;              $  User->lastLogin      = $  session->lastLogin;              $  User->password       = $  session->password;              $  User->ip             = $  session->ip;              $  User->loginTimestamp = $  session->loginTimestamp;              $  User->isLoggedIn     = $  session->isLoggedIn;               return $  User;         }     }     public function setUserToSession(User $  User)     {         Session::set(Config::$  user, serialize($  User));     }  } 
  1. Logging in: This has 2 parts:
    • First to authenticate the user credentials
    • Set security sessions (token, loggedin flag, ect’.) – using the UserSessionModel from example 1 – since it handles the same “subject”. So both are under the login method (one insice an other or separately – this example handles them the first way) and both are 2 different responsibilities – one is checking a user authentication, the second is handeling the sessions/tokens.

code ex:

User class {      // after setting $  this->username & $  this->password to this object     public function login()     {         if ( !$  this->UserAuthenticator instanceof \myapp\Models\User\UserAuthenticatorModel )             $  this->UserAuthenticatorModel = new \myapp\Models\User\UserAuthenticatorModel();          return $  this->UserAuthenticatorModel->login($  this);     } }   class UserAuthenticatorModel extends Model {      public function login(User $  User)     {         try {              # Connect to new database with $  User->username & $  User->password             ...               # If status is connected              if ($  newConnection) {                  # Check for user credentials data                  $  userData = $  this->UserLoginValidation($  User->userName, $  User->password);                   # If the result isn't a valid array - EXEPTION                   if ( (!is_array($  userData)) || (empty($  userData)) )                     throw new LoginException("Invalid username ({$  User->userName}) or password ({$  User->password})");                  if ($  userData["require_password_change"] === 1) {                     $  this->set($  User, $  userData);                     return true;                 }                  $  this->set($  User, $  userData);                 # Set logged-in security sessions                 $  User->UserSessions = new UserSessionsModel();                 $  User->UserSessions->setSecuritySession($  User);                 # Set User obj to session                 $  User->UserSessions->UserToSession($  User);                  # Update last_login for this user                 $  this->updateLastLogin($  User->id, $  User->loginTimestamp);                  return true;              } else {                 throw new LoginException('User does not exist');                 return false;             }          } catch (LoginException $  e) {             $  e->log($  e);             return false;         }     } 

What is the best way to handle the scenario in C++ where there are two methods that are identical, except one is const?

I am currently working on a program in which I encountered an issue (not for the first time) where I have two acessor methods for a data structure. The methods are identical, except one is const and returns a const pointer while the other is non-const and returns a non-const pointer. The code in the methods is non-trivial, making it ideal to not duplicate it between the two methods for all the same reasons that code duplication is bad in general. What is the best way to solve this issue?

The only reasonable-seeming idea that I have is this, but I am not entirely convinced that this is best because 1) I am not sure if a const_cast is acceptable here with regard to undefined behavior and other violations of the C++ standard┬╣, and 2) I have heard that a const_cast is a sign of bad code.

Node *NodeSet::getNode(int index){     const Node *node = static_cast<const NodeSet*>(this)->getNode(index);     return const_cast<Node*>(node); }  const Node *NodeSet::getNode(int index) const{     //non-trivial code to get the correct node } 

┬╣: It is important to me that I write standard C++ that does not rely on any particular compiler to compile and run correctly.

As a module developer in D8, how do I handle outputting user defined strings with regards to translatability?

A module I maintain is introducing the ability to customize some messaging that is output to users on the site. Up until now, that messaging has been hard-coded and output using the TranslatableMarkup class. I’m now allowing these strings to be customized in configuration.

Is it still appropriate to just dump whatever the configured string is into the TranslateMarkup class? It seems like I should not do that.

I found this old core issue that seems to be related to what I’m discussing, but there’s no clear conclusion on what to do.