.NET DPAPI and AES Encryption: Sense-Check

Question: I am just about to write a new encryption system for a website I'm currently working on, and wanted to see if i could get someone to sense-check it before I get started if possible!
Update: Should have been clearer with my original question.  I need to encrypt some user data that I also need to be able to read back at a later data.  And, I also need to store the users password or a hash of the password for verifying the user upon login.
The plan is:

Master Key: Create a DPAPI key-setter application to take a text-based master key, encrypt via DPAPI, then save the encrypted output to a text file on the server.  This is a one-off task that I'll perform every time I move the site to a new server.  The master key will be used to perform AES encryption.
When a new user registers:
2.1. Save password data / hash of password data.
2.2. Load master key file, decrypt the key using DPAPI.  Use the decrypted master key, and a new random IV for each piece of user data to create an AES-encrypted string.  Save each encrypted string by prefixing the encrypted string with the corresponding random IV, and insert into a varchar column in the database.
Upon user login:
3.1. Match password hash to validate user.
3.2. For each encrypted user data field, split content into two parts: the IV and the encrypted data. Taking the master key from DPAPI, and the IV, decrypt the data and display on-screen.

How does that sound?  Are there any obvious flaws to the above?
I'm new to this having previously used Enterprise Library Security for this sort of the stuff in the past (which is no longer available in .NET core!), so any help would be massively appreciated!
Comment: It's generally better to hash than encrypt passwords.
Comment: **Do not encrypt passwords**, when the attacker gets the DB he will also get the encryption key. Iterate over an HMAC with a random salt for about a 100ms duration and save the salt with the hash. Use functions such as password_hash, PBKDF2, Bcrypt and similar functions. The point is to make the attacker spend a lot of time finding passwords by brute force. See the answer by @bartonjs for more information.
Comment: I understand using hashing is a good idea, but in this case - the hacker would not get the encryption key from the DB, because the key itself would be encrypted using DPAPI.  Having said that, I am intending to use password hashing anyway, and use DPAPI + aes for the non-password user fields
Answer: You should never store a password if you can avoid it.
I'm unclear what the password is in step 1. If a new user isn't showing up until step 2, whose password is this?
Anyways, for your users a much better plan is to use/save derived material. For example, upon new user registration do something like
byte[] exportBytes;
byte[] exportSalt;
int exportPasswordSettingsVersion = YourSystemConfiguration.NewPasswordSettingsVersion;

using (Rfc2898DeriveBytes registerer = new Rfc2898DeriveBytes(
    newUserPassword,
    YourSystemConfiguration.GetSaltSize(exportPasswordSettingsVersion),
    YourSystemConfiguration.GetIterationCount(exportPasswordSettingsVersion)))
{
    exportSalt = registerer.Salt;

    exportBytes = registerer.GetBytes(
        YourSystemConfiguration.GetDerivedKeySize(exportPasswordSettingsVersion));
}

Then you export the salt bytes (which were randomly generated for you), derived password bytes, the sett as part of the user's profile. When the user comes to log in, you load these values back and check that they match:
using (Rfc2898DeriveBytes verifier = new Rfc2898DeriveBytes(
    inputPassword,
    loadedProfile.Salt,
    YourSystemConfiguration.GetIterationCount(loadedProfile.PasswordSettingsVersion)))
{
    byte[] verifyBytes = registerer.GetBytes(loadedProfile.PasswordVerify.Length);

    if (!ConstantTimeEquals(verifyBytes, loadedProfile.PasswordVerify))
    {
        return false;
    }

    if (loadedProfile.PasswordSettingsVersion < YourSystemConfiguration.GetIterationCount(exportPasswordSettingsVersion))
    {
        // Re-derive their password and save it with your newer (stronger, presumably) cryptographic settings.
    }

    return true;
}

This scheme:

Uses RFC2898's PBKDF2 algorithm to derive a key from a password, storing this derived value is better than storing the password, because if your credentials database is compromised it doesn't give away the password.
Uses a new random salt for each new user. (And can also be re-generated on password change or an upgraded login)
Saves (and loads) information about what settings were used when the password was set so you can change your defaults in the future.
Doesn't use DPAPI (DPAPI isn't bad, but it's Windows-only, and if you're using .NET Core then you might want a cross-platform solution)
Comment: Apologies, my original question wasn't very clear.  I've updated it. Thanks for the code samples, very useful.
Comment: Also, with regards to the hashing, do you see any harm in saving the salt / hash / number of iterations in a blob, to be stored in a single DB column?
Comment: And similarly, do you seen any harm in storing the IV and along with the encrypted AES string for the non-password user data fields?
Comment: Typically these things are prepended to the hash and encrypted respectively, they are not secrets.
Answer: Ignoring the question of passwords, and just considering user data, your scheme is fine, but can be improved.
Basically, you have a master key -- a symmetric key or maybe 16 or 32 bytes, that is protected at rest (on disk) and you decrypt this in memory on the server.
User data is encrypted using the master key, with a random IV for each piece of data. Be sure to use cryptographically strong random data.
You are storing the IV and ciphertext together, which is fine. Although, the IV and ciphertext are binary so you'll either have to use a blob database type, or encode the binary using Base64 to store it as varchar.
What you should consider adding to this is some form of tamper detection. For example, you could use two master keys -- one for encrypting/decrypting, and one to use for an HMAC on the data. You would use the encrypting key to encrypt the data, and then, apply an HMAC on the IV + ciphertext (using the second master key for HMAC) and store the HMAC alongside the IV and ciphertext (you could even just append it). Before decrypting, you validate the HMAC. This tells you if anything in the IV + ciphertext has been altered.
You did not mention padding. If you use AES CBC mode, you'll need to pad the data if it is not a multiple of 16 bytes. With padding, you just have to be careful that you don't accidentally provide a "padding oracle", where an attacker can send arbitrary ciphertext to the server and the response from the server tells the attacker either "padding error" or "invalid decryption" -- i.e. there is a difference in the server response.
If you use AES GCM mode, then the equivalent of HMAC is built-in -- you only need the single master key, and GCM itself will detect tampering of the ciphertext. This also lets you include "associated data" which is not part of the encryption, but is included in the "authentication", i.e. as if it were included in the HMAC. For example, the user name, "Joe", could be included as associated data in the GCM encryption of Joe's data. Then, when GCM mode decrypts the data, not only would it detect tampering of the IV + ciphertext, but the user name must also still be "Joe" -- note that "Joe" is not encrypted here.
Individual IV, random each time, for each piece of data, is a very good idea. You might also think about how long the master key is used before it is replaced. It should have a limited lifespan, and when it is "rotated" or "rolled" or "rekeyed" (all meaning the same thing -- you are replacing it) you'll need some way to re-encrypt everything. You want to change the master key periodically (it could be 3 months, it could be a year) to 1) limit the amount of data that is exposed should the master key be compromised (e.g. only 3 months worth) and 2) limit the amount of data a single key is used to encrypt (because technically, there is a limit to how much data you can encrypt with a single key and still be mathematically "secure").
Comment: @JimFlood Thank you for the comprehensive answer.  I was planning to use RijndaelManaged().GenerateIV() to create the random IV.   As there's no AES HCM mode in .NET (at the time of writing), I'll probably use AES CBC and go with your HMAC and two-key suggestion.  I found an example where someone was doing something quite similar: [link to Github](https://gist.github.com/jbtule/4336842#file-aesthenhmac-cs). I'll probably use this as a base, swap to RijndaelManaged and make a few modifications to add configuration versioning so it's easy to change the salt size/iterations at a later date
Comment: @zaph The OP described protecting the key with DPAPI. That would be up to Windows then -- it could be tied to the Windows userid (i.e. security principal) or to the machine. That is beyond the scope of this question, how exactly DPAPI protects the key. Google "Windows Data Protection API" for details.
Comment: Understood, comment deleted.


How can i make sure an element was appended and exists after ajax request is succesfull?

Question: If I have use the following, assuming my returned data from the server is an html element like  text :
...,
success: function(res){
    $(res).appendTo('body');
    $('#hiMark').css({ … })
}

If I use this, is it safe to use methods on the appended element, I know I can check if an element exists using .length and maybe a timer, but, do I have to check in this case ?
If everything goes well server-side, will the css({}) method execute only after the element was appended ? Or do I need to check first if it exists ?
Answer: You're safe without checking for existence of the element.
Assuming the res string contains an element with ID of hiMark, it will be appended to the body immediately when success runs, and the code will run as expected.
If res does not contain such an element, any jQuery methods called on that ID will quietly do nothing.
Answer: You should check the response with soemthing like this:
if(response != null && response!= undefined){
//append my stuff
}

or:
//if your response is a string

       if (response != "" )

    // if your response is a json object

        if(isEmpty(response)) {
            // response is empty (Would return true in this example)
        } else {
            // response is NOT empty
        }


How to get across testchamber 18?

Question: I'm replaying Portal before diving into Portal 2 and I'm somewhat stuck in testchamber 18

I've tried using gravity to get across, but I fear I'm doing something wrong.
Any suggestions?
Comment: You need to start the platform straight ahead of you moving. Unfortunately I can't remember how you do that.
Answer: Clue: Look down, near the water
Full answer on how to do the room:

 1. Clear turrets if you're a wuss by using the energy balls.
 2. Activate the platform by putting the energy ball in the socket.  Once you redirect it with the portal, you need to quickly (but not too quickly) portal a couple feet up and hit the button to open the doors protecting the socket.
 3. Take the tram across and drop down into the lower alcove
 4. Push the button, then quickly portal back to the main platform, placing a portal on the now slanted up, "door" panel.  Quickly head to the right and use the platform below near the water to fling yourself out of said portal to where the cube is.
 5. Grab cube, drop down to lower alcove (the moving platform can help).
 6. Hit button, portal back to the main platform and escape before the panel closes once again

How to do it quickly ("traditional" way of doing a speed run, without jamming doors with cameras or using glitches):

 1. Immediately when entering chamber, fling yourself across the room to the cube.  Avoid activating turrets as best as possible by hiding behind solid panels (not the glass) while the door opens.
 2. Grab cube and drop down to lower alcove
 3. Hit button to open panel, portal across and escape.
 Deaths to turrets and missing the drop are common.  Do your best.
Comment: Props for clue+spoiler
Answer: First, you need to activate the platform.  To do that, you have to use a portal to redirect the energy ball that is being shot by the turning shooter to the closed, upraised door to your left.  Immediately after the energy ball goes through the portal, you need to quickly shoot a portal with one end next to the upraised switch and the other near your feet, then jump through and hit the switch before the energy ball hits the door.
Once that's done, then you need to ride the platform across, jump to the lower platform, hit the switch, put a Portal on the door that just opened (and the other end next to you), go through the Portal, put the non-door end of the portal down the pit to the right of where the screenshot is, and jump through it to long jump using the door portal to reach the top platform on the other side.  Then you need to bring the weighted storage cube back over to the near side via the platform, then jump on the platform again to activate the door again...
Phew, that's a lot just to gain one weighted storage cube.
Comment: It seems there's a lot of ways of getting there!

How to get across testchamber 18?


Apply safe filter to concatenated html string

Question: I have been trying to do this:
{% set error_message = '' + field.errors[0]|e + '' %}
{# ... code ... #}
{{ error_message|safe }}

Trying to get this output in html:
Some message'

However the html is escaped and I get the above printed out as a string.
So question is how to mark a concatenated string as safe in Jinja2 ?

Current output (firebug):

Expected output:

Update: Tried this but didn't work:
{% autoescape false %}
    {{ error_message|safe }}
    {# also tried without safe #}
{% endautoescape %}

Comment: Does `{% autoescape false %}` help? http://flask.pocoo.org/docs/templating/#controlling-autoescaping
Comment: @frb just tried, it doesn't work, any other ideas? see update to how i tried
Comment: No, sorry. I think assignments in Jinja using `set` might be escaped in a way that doesn't respect `|safe` or `autoescape`. That might be a bug.
Comment: @frb alright, i did find a way to do it though, albeit it doesn't look like a good solution. posting it as an answer for now, looking for a better solution.
Answer: Marking each part string of the concatenation as safe however gives the desired output:
{% set error_message = ''|safe + field.errors[0]|e + ''|safe %}

OR slightly better:
{% set error_message = ('' ~ field.errors[0]|e ~ '')|safe %}

(combined safe filter for entire string concatenated with ~ instead. + doesn't work for this)


Host ghost on github: buster generate... failed: Connection refused

Question: I'm trying to host ghost on github page. I can see my ghost blog on my Mac. But, when I run:
buster generate --domain=http://localhost:2368

The connection is error. The display like this:

The display in terminal like this:
--2018-07-05 11:07:26--  http://localhost:2368/
Resolving localhost... 127.0.0.1, ::1
Connecting to localhost|127.0.0.1|:2368... failed: Connection refused.
Connecting to localhost|::1|:2368... failed: Connection refused.
Converted links in 0 files in 0 seconds.

Any idea to solve this problem?
Answer: If you are trying to create a static site using ghost then check out ember-ghost
Ember Ghost

A fully-functional, SEO friendly static site implementation of a blog system built on Ember.
It currently has 2 ghost themes Casper, Attila which have been ported to work with ember-ghost. You can also create your own ember-ghost theme if you want.
Write your blog using Markdown
Answer: You have to start ghost in localhost and use buster tool to convert the pages. Buster then stores the files in a folder called static
try
ghost start

and find which port ghost is running on with the command
ghost status

browse to
http://localhost:2368

replace the port number if it is different
then use buster
sudo buster generate --domain=http://localhost:2368
sudo buster deploy

Check out my repo of my blog on github pages for any help.


What kind of chlorine solution do I use in water treatment system?

Question: We recently bought a house in which the previous owner had installed a Culligan softener system with not only brine and resin tanks but also a chlorine tank with a pump. There isn't a Culligan representative remaining within a 50 mile radius of the house, the ones outside of that range aren't willing to come without a huge fee (understandable) or at all.
The salt part is easy. What I don't know is what kind of chlorine solution or pellets or powder or [???] should I be adding to the chlorine tank? Google is usually my friend, but not on this issue. I don't want to just dump a bottle of Clorox in there, since I don't know (a) if sodium hypochlorite is the correct chemical for use in water treatment without poisoning us all to death, and (b) what other odd chemicals are in Clorox that will poison us all to death.
Our water is sourced from a well that is by itself fails on lead (0.023 mg/l) and is heavily laced with iron (20.4 mg/l). What can almost not be made out in the pictures below is a 10" carbon pre-filter (you can see the bottom sticking out from under the controller on the resin tank). The pre-filter does a pretty good job of removing the iron, though we have to replace it every 2 to 3 months.
There are two tanks that are obviously labeled Culligan; the third is of a slightly different color; no brand name on the tank itself, but written in blue ink are the words "gallon chlorine" (possibly a faded numeral before).

On the top of the tank marked "chlorine" is a pump:
Comment: We need a bit more information - could you give a model series or model number?  Why do you think it is a chlorine tank and is it Culligan branded?   do you have a picture? Is your water from a well or other non-treated source?

You are right to not put just anything in the tank as chlorine exposed to water can cause a vigorous reaction - if the tank is sealed, if could burst  if the wrong form is used.
Comment: Thanks, Ben - I've added the information and pictures as requested.
Answer: This looks very similar to a pool chlorine feeder - these could use cal hypo or sodium hypo, either way you would need to know the concentration to mix and the dosing for your qty of water to treat. Not sure we'll be able to answer those questions directly.
Sodium hypo - bleach - would be the cleanest option, but also will become ineffective the quickest.
Cal hypo is granular (and cheapest) and has the most shelf life, but you'd probably want to source food grade supply for long-term use.
Concentration of chlorine would be determined by the qty of water to be treated at one time, level of final level of chlorine needed for decontamination, how the chlorine solution is dispensed (continuous or on demand) and how much chlorine is dispensed at any given cycle.
Chlorine would only be used to correct organism growth not other chemical/mineral constituents of concern.
Due to the health risks, I 'm not sure how much I'd trust free advice at this point.  Spend the money and be sure this is set up properly.  Your health is worth it.
Comment: I have no idea what you guys are talking about; +1 for the last line.
Answer: This actually is a chlorine tank.  I have one, I personally buy the pool chlorine at a pool supply store to put in mine, but you can just use regular chlorine bleach.  It's slightly cheaper to do from the pool store.  I was actually searching to see if anyone just tossed tablets in their tank instead of feeding it.  Usually you should put about 1/4 amount of chlorine to water, there should be a spigot on your holding tank where you can test and ideal amount should be in the same range as your pool.  After it goes through the filters though, there should be zero.  However in looking at your setup, it seems like yours goes directly through the filter and then into the tank so I don't know how exactly you'd test percentage on yours?
Comment: I test the percentage by running the water for several minutes through a utility sink faucet (next to my washer/dryer and maybe 15 feet from the tank) and then using a test strip. I need to get a specific type of test strip that will show between 1 and 5-10 ppm max; you want the drinking water percentage to be below 4ppm (I shoot for 2ppm). Regular pool test strips start turning blue at 10ppm and then give you a range to something like 50ppm; that makes the pool test strips useless because when they start showing blue, you already have too much chlorine.
Answer: This looks like my former house. If it is,
I paid Culligan to install it.
I used 50% liquid chlorine from pinch a penny pool company and 50% of water.
The inside spigot, I used a water hose on for the salt water kidney shaped pool.
I converted the pool to salt water.
It was chlorine.
The outside fiberglass tank, you have to open the valve and flush the backwash water out.
Answer: I have a water softener just like yours , mine is a little more newer , and I have twin tanks.
I put in 7 lbs of soda ash and about a quarter of a gallon of hypochlorite every time I fill my 35 gallon feeder tank. That was how Culligan instructed us , when we purchased new. Water has been great and no issues. Hope this helps!!!


Emitting sparks in Pac-Man Championship Edition

Question: In Pac-Man Championship Edition for the iPhone, one of the achievements is something like "emit sparks for 5 seconds". How do you emit sparks, and what effect does it have?
Answer: Sparks happen when you are trying to turn, but can't. That is, when you're pushing into a wall. This also has the side effect of making you turn faster when the turn becomes possible. So if you plan ahead and "spark into" your turns, you'll corner faster than if you had waited until the actual intersection to change your direction.


Set value to model in view

Question: I have a bunch of templates/views that consist of labels and inputs. I want to set the label values into the controller models ($scope.data.details which is an array).
Code: http://plnkr.co/edit/XqtyFKKNuo8upzPuaImo?p=preview
HTML

    Label 1
    <input type=text/>
    {{ data.details[0] }}
    Label 2
    <input type=text/>

JS
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.data = {
    details: []
  };
});

app.directive('setModel', function() {
  return {
    restrict: 'EA',
    link: function(scope, element, attrs) {
      // var pair = JSON.parse(attrs)
      scope[attrs.setModel] = element.html();
      console.log(scope);
      // console.log();
    }
  };
})

So basically:

data.details[0] = "Label 1"
data.details[1] = "Label 2"
...

I know I could do this in ng-init but it would be a long list on top. I want to do it inline in the  itself.
But right now it doesn't work as $scope basically shows this in Developer Console:
data: Object
data.details[0]: "Label 1"
data.details[1]: "Label 2"

So it didn't put details as a key inside data object but it created a new key data.details[0] completely. Also the data structure could be different later on so I don't want to hardcode anything.
How do I fix this?
Or is there a better way to do this?
Answer: Try to use this:

    Label 1
    <input type="text"/>
    {{ data.details[0] }}
    Label 2
    <input type=text/>

Plunker: http://plnkr.co/edit/d9lMXWJDUG6yTxsXFD33?p=preview
If you want result in array only try something like this: http://plnkr.co/edit/KZS1wO1cIvEo7sUpWoDU?p=preview
Answer: it does not work this way because when you get key like this 'attrs.setModel' it take whole string which means it takes data.details[0] you either resolve this with another javascript code just simply using scope attribute of directive like this
app.directive('setModel', function() {
  return {
    restrict: 'EA',
    scope: {model : '=setModel'},
    link: function(scope, element, attrs) {
      // var pair = JSON.parse(attrs)
      scope.model = element.html();
      console.log(scope);
    }
  };
})

right now your directive take parent scope object instead of string so any value change on this affect parent scope object as well...
here is working PLUNKER...

Set value to model in view


ODBC Remote connectioon problem

Question: I'm trying to set a connection through ODBC to an SQl Server Express 2005 instance
the following connection string is working fine when I use it on the same machine
Conn string: "DSN=_Vendas;TrustedSecurity = yes;";
I have an ASP.NET application that needs to use the same connection remotel, and this fails
Exception: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
any configuration needed on SQl Server Express? Or is anything missing in the conn string?
tks
PS: already set Remote connections to use TCP\IP and named Pipes
Comment: Can we assume that the DSN is defined on the web server?
Answer: I'd hazard a guess that you've defined the data source "_Vendas" on the 'local' machine but haven't defined it on the 'remote' machine.  Go into ODBC Administrator on the 'remote' machine and define the DSN as you've defined it on the 'local' machine and try it again.
Comment: yeah, I defined it as "User DSN" when I should have done it as "System DSN"... well, maybe it's because it's monday... =P

ODBC Remote connectioon problem


Unused cable (hot and neutral wire), from one circuit (covered with wire nuts), in same outlet box as a newer outlet on a different circuit...This ok?

Question: Found a couple of these in outlet boxes in a bedroom of house. Is that ok to leave this way? Really not wanting to tear out plaster, if possible. Thank you all.
Answer: If they are safely capped off, it's technically fine - though the better option would be to find the other end of them and disconnect and cap off there (so it's just a dead wire for possible future use, ideally also labeled as to where it goes) rather than leave it live but unused.
If you are not actually "abandoning" the wire you don't have to remove all accessible parts, much less rip walls open to remove it (which is never required. Removing accessible parts is, if abandoning.)
Since there might conceivably be use for the wire in the future, just isolate and label. But definitely better to have it isolated if it's disused.
Comment: If you've found the other end of _these_ wires, @Brad, you can disconnect them at the other box and wire nut them there as well. Labels at each end to help someone in the future identify where & why these go will be helpful.
Comment: Appreciate it. It definitely won't be used by me.......old cloth 2 wire stuff, but has newer looking grounded 14/2 Romex on the outlet, though. I'm gonna try to see where it goes. I've found the circuit it's on, but the same circuit is powering a currently used hallway light and an overhead light in bedroom.


Prime Model and boundary functions for n-types

Question: Find a prime model and a countable $\omega$-saturated model of $Th((\mathbb{Q},+,0))$.
Define a function from $\mathbb{N}$ to $\mathbb{N}$ such that, for each n, $Th((\mathbb{Q},<))$ has not more than $f(n)$ $n$-types.

I know for the first part that i have to find a model $\mathfrak{A}$ of $Th((\mathbb{Q},+,0))$ such that every other model embedds elementary in this model $\mathfrak{A}$ (here we can use Fraisse's Method). I think that $(\mathbb{Q},+,0)$ self i such a model but is this true? But what about a counatble-saturated model. I know the definition but it is very difficult to understand this definition. Can someone give a hint?
For the second part: i know that for each n holds: $(q_0,\cdots,q_{n-1})$ in $Th((\mathbb{Q},<))$ realized the same n-type as $(r_0,\cdots,r_{n-1})$ iff for all i$,j<n$: $q_i<q_j$ iff $r_i<r_j$ (this is a equivalence relation with finitly many equivalence classes). The statement is clear, but how to define such a function $f$ with this information?
Thank you for help. :)
Answer: A prime model is not one into which every model embeds elementarily. It's one which embeds into every model elementarily.
The prime models in a countable language can be characterized as those which omit all non-isolated types. Dually, an $\omega$-saturated model is one which realizes all types over finitely many parameters.
Do you know about the quantifier elimination for $\text{Th}(\mathbb{Q},+,0)$? You can use this to understand all the types relative to this theory, and once you understand all the types, you should see what it means to omit or realize them.
For the second question, you're correct that the type of $(q_1,\dots,q_n)$ depends only on the order of $q_1,\dots,q_n$. So there's exactly one $n$-type for each way of ordering these $n$ elements. It's a counting problem: you have $n$ choices for which one comes first, $n-1$ choices for which comes next...
EDIT: as pointed out in the comment, there's also the possibility that some of the $q_i$ could be equal, i.e. $q_1 < q_4 = q_3 < q_2$. So the counting becomes a little more complicated.
Comment: The $q_i$ could be equal, not?
Comment: ah yes, of course


Prove that function with positive second derivative grows faster than a linear function

Question: The statement of the problem is as follows, Let $f: \mathbb{R} \rightarrow \mathbb{R}$ be differentiable, and $f''(0)$ exists and is greater than $0$. We also have $f(0) = 0$. Prove that there exists an $x > 0$ such that $f(2x) > 2f(x)$. I have tried doing this based on the sequential definition of limits and the definition of the derivative but I have only been able to show that there exists $x > 0$ such that $f(2x) > f(x)$.
EDIT: There was an additional condition I forgot to include, $f(0) = 0$
Comment: What about $x\mapsto e^{-x}$? Both your statement and what you claim to have proved are wrong.
Answer: \begin{align}
f(x) = f(0) + f'(0) x + \frac{f''(0)}{2} x^2 + R(x)
\end{align}
We have $f(0) = 0$ and $a = f''(0) > 0$ and some $b = f'(0)$. Thus
\begin{align}
\Delta(x) = f(2x) - 2 f(x)
&=
2 b x + 2 a x^2 + R(2x) - 2 b x - a x^2 - 2 R(x) \\
&=
a x^2 + R(2x) - 2 R(x)
\end{align}
where
$$
\lim_{x \to 0} \frac{R(x)}{x^3} = 0
$$
This means the rests decrease faster than positive $ax^2$ when we make $x$ smaller (but keep $x > 0$), so there must be a $x > 0$ with $\Delta(x) > 0$.
Comment: I forgot an additional condition on f, with $f(0) = 0$, is it true?
Comment: That makes a big difference.


Save docker output file in workdir

Question: I am a newby in docker
My Dockerfile
FROM python:3
WORKDIR /app
COPY . /app
RUN pip install numpy
RUN pip install pandas
CMD ["python", "app.py"]

And in app.py I have a line
pd.DataFrame(predictions, columns=['predictions']).to_csv('output.csv')

I build and run the image, that's ok but I can not to save this dataframe in my work directory. How to change Dockerfile so that I can do it?
Comment: What do you want to achieve exactly? Do you need the output on your host machine? Or is `output.csv` not being created in `/app` at all?
Comment: I need the output on my host machine. The file is created
Answer: Probably the best way to get output.csv out of the container onto your host machine is using a volume. Volumes are storage paths that can be shared between host and container, much like shared folders for VMs.
In your case:
docker run --rm -v $(pwd)/volume:/app your_image

You should then find everything from the container's /app path in your working directory under ./volume.
Comment: It looks like `/app` is not empty, from to the `COPY` instruction in the Dockerfile. The original contents of `/app` would get hidden when the volume is mounted this way. Using any other path to mount the volume instead of `/app` should be fine in this case.
Comment: I agree, @Proyag. @Edward, you could change your Python code to save your CSV somewhere else, e.g. `/home/your_user/output.csv`. Then you would change the volume definition to `-v $(pwd)/volume:/home/your_user`.
Comment: @Proyag can I delete `COPY` or change `WORKDIR` in Dockerfile?
Comment: I use `docker run --rm -v $(pwd)/volume:/e/test my_image` It works but the output is not saved. If I channge in `app.py` `to_csv('/e/test/output.csv') I get error
Comment: `No such file or directory`
Comment: In local it works `to_csv('E:\\test/output.csv')` and the file is saved but this path is not correct for `docker`
Comment: I see. You have to choose a path that exists _inside_ your container, e.g. `/e/test` doesn't seem to exist when you run your Python script. Either choose another path, or add `RUN mkdir -p /e/test` to your Dockerfile. Let me add that it doesn't matter whether the path in the container reflects those on your machine.

Save docker output file in workdir


Does Google's V8 require C++14 standard?

Question: I am currently trying to build Google's V8 engine, following its official documents.
And I get some errors here:

Need a newer glibc
python ../../tools/run.py ./bytecode_builtins_list_generator gen/builtins-generated/bytecodes-builtins-list.h
./bytecode_builtins_list_generator: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./bytecode_builtins_list_generator)
Return code is 1
[115/1639] CXX obj/torque_base/torque-parser.o

Some C++14 grammar
Such as in include/v8-internal.h, there is a std::remove_cv_t
template <class T>
V8_INLINE void PerformCastCheck(T* data) {
  CastCheck<std::is_base_of<Data, T>::value &&
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
}

When looking into its building procedure, I find it actually uses third_party/llvm-build/Release+Asserts/bin/clang++ with a -std=c++14 flag.
So I am wondering if I can build a V8 engine with some old gcc, like gcc 4.4.6/4.8.5?
Comment: The first error is just some precompiled utility that was built on a newer version of Linux
Comment: why do you need to work with such ancient gcc versions?
Comment: @phuclv Because I need to embed v8 into a old project which compiles with such old gcc
Comment: @calvin people stick to old GCC usually because the new libc isn't available on the target. So you can try to compile with new gcc and link the libc statically, or distribute the new libc's .so files
Answer: Yes, V8 currently requires C++14.
Expect future changes to be in the direction of requiring C++17 (though there's no timeline for that yet), rather than going back to older C++ standards.
Comment: Yes, you can use `git checkout` to check out old versions. You'll probably have to run `gclient sync` afterwards. Obligatory warning: old versions typically contain known bugs, including exploitable security bugs, so you should not use them to execute code you haven't written yourself. I don't know what the last version was that compiled with GCC 4.x, sorry.
Comment: Yes, you can `git bisect` the entire history of V8; though as you already noticed, some things have changed over time. The official docs you linked indicate that the 7.1 branch (~2 years old) still compiled with GCC 4.8, so you can start the bisection there. I don't think the build system has changed much since then. As an alternative, you can simply use the bundled Clang, or spend your time on updating your GCC instead.
Comment: So if I can only use gcc 4.8.5/4.4.6, I can only compile some old version of v8? How can I identify with version compacts with my gcc?
Comment: I don't know how to switch to a certain branch of v8, should I simply run `git checkout`?
Comment: It is possible that I can `git bisect` the whole `master` branch?
Comment: Hi, when I look into old versions of V8, I find it has different build process, for example, it provides a Makefile, rather than currently ninja. However, I still can't find a way to build v8's statis library `v8_monolith`.
Comment: I tried with branch 2558, after modified some gyp files I can now compile with gcc 4.8. Moreover, I don't know if it still compiles with gcc 4.4.6, because V8's document at that moment has not guarantee so. My question is, if branch 2558 not works, can I try to find an older branch, or V8 just can't compile wieh gcc before 4.8, and I don't need to waste time here?
Comment: There are certainly old V8 versions that can be compiled with GCC 4.4. That was the default GCC in Ubuntu Trusty/14.04 after all, so V8 versions from around 2014-2016 probably compile fine with it. As I said before, I don't recommend using such old versions though; updating your toolchain is probably a better investment of your time.
Answer: Unfortunately, you can't build C++14 code with older gcc.
As here shown, you can build C++14 with gcc 5.0, which is C++14 compliant.
EDIT: Actually it would be easier to download gcc 5.0 on your platform and compile it with your current gcc version and then compile V8 with this newer compiler.
Comment: My question is if I can build V8 with my old gcc, for example, if there exists some compile flags that disable all c++14 codes.
Comment: unfortunately not, but if you have the code, you can modify it by yourself with the #ifdef guards in the parts where you want to deactivate it. The _cplusplus macro has value 201402L for C++14.
Comment: So, is there any js engine you know that supports g++4.4.6?
Comment: unfortunately no


Flash stopped working on Chrome

Question: I upgraded my system to Ocelot from Narwhal and Flash stopped working on Chrome, the plugin is installed on the Software Center, I removed it and installed it thrice but still, no Flash support on Chrome.
Comment: chromium or the official google-chrome browser ?
Answer: Something similar happened to me too during my upgrade. I did the following and everything's working now:
<code>sudo apt-get install ubuntu-restricted-extras
sudo apt-get install flashplugin-downloader flashplugin-installer
</code>
Comment: Nice, it worked. :D
Comment: @Jgrimaldos if it worked, it would be nice to mark it as answered
Comment: I can conform this works also in 12.04

Flash stopped working on Chrome


How can I set a bluetooth default controller

Question: I have ubuntu 18.04 and using 2 bluetooth sources. When I type bluetoothctl I get 2 bluetooth controllers but one of them (less desired) is set as default. How can I set other controller as default via terminal?
Answer: using list command in bluetoothctl prompt will give you the list of controllers  with their mac id,  also showing which one is the default

[bluetooth]# list
Controller 14:16:91:15:F6:A0 david-acer #2 [default]
Controller 14:D3:A7:56:F4:D0 david-acer #1

type select command with the mac id of the desired controller to use this controller as the default

[bluetooth]# select 14:D3:A7:56:F4:D0
Controller 14:D3:A7:56:F4:D0 david-acer #1 [default]
Comment: Be aware this only sets the default for this specific session of bluetoothctl, which can be a problem for scripted use.
Answer: bluetoothctl has a default agent which is (at time of writing) the first enabled bluetooth device encountered when you run the application. There is no way to control this for future launches.
Within a single interactive session, you can use select <bt addr> to switch to a controller as default for that specific session of bluetoothctl.
For scripted use, you will have to issue that command first in standard input, using something like
echo -e "select aa:bb:cc:dd:ee:ff\npair gg:hh:ii:jj:kk:ll" > bluetoothctl

to run multiple commands


About training data for spaCy NER

Question: I'm new to NLP.
Now I'm trying to create NER model for extracting music artist's name from some text.
But It hasn't gone well.This is what I've done.

I got 1500,000 artist's name list.

I created training data with string template.like this "{artist's name} is so sick."
All 1500,000 training data is like this string.

TRAIN_DATA = [
    ("Nirvana is so sick", {"entities": [(0, 7, "ARTIST")]}),
    ("City girls is so sick", {"entities": [(0, 10, "ARTIST")]}),
    ("Taylor swift is so sick", {"entities": [(0, 12, "ARTIST")]}),
]

(Maybe this is the reason it doesn't go well?)

I used the model after training 30,000 datas.

But I didn't work at all.All sentence was extracted as ARTIST.
Below is example. 'Chris Thomas King' is artist's name in this case.

Entities [('Not sure how they handled it during filming, but Tim Blake Nelson did sing his own parts (as did Chris Thomas King).', 'ARTIST')]

Do you have any idea?
Thanks in advance.
Comment: Do you have a finite number of artist names? or are you looking to generalize?
Comment: To generalize is better.But It looks so diffcult.
My plan is it let model learn finite artist(1.5M).
Then it gradually let model learn few additional names.
Answer: If all your training data is just the same sentence but with different artist name e.g. "[artist] is so sick", you need more variety in your training data.
For example, "This song is by [artist]", "[artist] won an Emmy for this song", "Is this the best song by [artist] ever?". Generating training data by replacing just the artist name in one sentence will not work.
What you need is not a lot of artist names but a lot of different sentences with different words.
Comment: Thank you for telling that!

> you need more variety in your training data.

I think this is point.I'll try to create training data with many variety templates.

> What you need is not a lot of artist names but a lot of different sentences with different words.

You mean it's possible even if model doesn't learn specific name(Let's say "Taylor swift")
model learn a lot of different sentences without the word "Taylor swift"
then model can extract "Taylor swift"?
Comment: You mean it's possible even if model doesn't learn specific name(Let's say "Taylor swift") model learn a lot of different sentences without the word "Taylor swift" then model can extract "Taylor swift"? -<<<< Yes, that's the point of machine learning so that you teach it general pattern rather than all possible examples.
Comment: That's awesome...! I was thinking NER need to make model learn specific name(ex.Taylor Swift). If I don't do that,model never extract the name. I see.Thank you for telling that!
Answer: I would approach this problem differently. The way you are generating training data is biased in my opinion. Below are the steps I would follow to generate the training data.
To generate the training data:

Start with the list of artist names that you have and initialize a PhraseMatcher. See here for details on how to do this.
Then, use the matcher to tag the names of artists in your sentences (30k sentences that you have)
The sentences that you found matches on, select say 2k of them. Each match will have start and end index of the match. Use this to generate the training data i.e. TRAIN_DATA

Once, this is done, you can train your model using the training data.
EDIT

You have 1.5 million artist names
Next, you need now think of, "what context do I want my model to detect these names in?"
Once you have an answer to 2, it is time to generate training data. You should train your model in similar contexts in which you would want them to detect names. For example:

If you want your model to detect artist names in news headlines, you should collect 1k to 2k new headlines which have artist names in them.
If you want you model to detect names in reddit comments, you should get 1k to 2k reddit comments which have the artist names in them.
How do you know if these have artist names you ask? You have the 1.5M artist names, you can do dictionary lookup to verify.

Now that you have your context set, and good amount of training data set, it is time to "annotate" the data.
There are many ways to annotate

Manually annotate using an annotation software, Doccano, Prodigy, and many more
Use PhraseMatcher to match detect the names of artists just like you did in (3).

Now you have your annotated data; time to train the model.
Voila, you are done and now have a generalized model in hand.
Still unhappy with the results?

Add more training data, go to (3), repeat
Comment: Thank you for commenting!
That sounds so nice!

But Do you expect I have 30k sample sentences that include artist name like this?

```
・I like Taylor swift so Much
・City girls just release their new songs!
・Nirvana is one of the greatest band in rock history.
etc...30k sentences
```

Unfortunately,I don't have them.
I only have just 1.5M artist name list.

I think I've understood about spaCy Matcher.
Do you think I still should use this approach?
Comment: Do you expect I have 30k sample sentences that include artist name like this?
No. I do not expect you to have 30k sentences. You need about 1k to 2k sentences with artist names in them. Then you can use the matcher to detect the artist names in those sentences. You need to keep in mind that the 1.5M artist names should have the names of the artists you are looking to detect in the 1k-2k sentences that you are "annotating"
Comment: I added a more in depth explanation in my original post under EDIT.
Comment: It looks so nice.Thank you for writing!
You mean I need to collect only 1k-2k sample data?
My question is If I make model learn 1k-2k datas,is it possible that model extract 1.5M artist name?
Comment: Yes. It is possible, but I cannot give you an answer for sure. You have to test. You have to understand that the model doesnt know all the names, it is trying to generalize. So you might have to train with more data if the generalization isnt good.
Comment: I see.I'll try to get 1k-2k real sentences.then training and test them.Thank you for your great advice!

About training data for spaCy NER


Can I reset my characters' AI Personalities?

Question: I recently started playing Divinity: Original Sin without really knowing what I was getting myself into. I didn't know what AI Personality did, so I kind of just picked something that sounded good.
However, after having to restart on an easier difficulty, I apparently set my second party member's AI Personality differently than the previous time, as their response to the same dialogue option in the same conversation the second time around was different and ended up influencing a non-beneficial stat for that character. I'd like to change their AI Personality, because the dialogue I've been hearing so far really doesn't suit the character I had in mind.
Is there a way for me to reassign my party members' AI Personality without starting the game over (again)?
Answer: Yes, you can, by doing so:

The portal you open after the hall of heroes in the homestead has a
  magic mirror you can use to redo (primarily) the cosmetic aspects of
  character creation, including the AI personality.

Sources:

On Gamefaqs
On official forums

Edit: It is possible to access the mirror after getting a 3rd stone. Source is the last message on Gamefaqs site.
Comment: @Vemonus I think the Hall of Heroes unlocks after you find two stones and take them to the end of time. Presumably the room after that unlocks after 3 or maybe 4.
Comment: @V4karian you misspelled my name so I didn't get pinged for your comment, but since your answer was updated, I accepted
Comment: Do you have any estimate on how far in the game that is?


How can I stop players from spawning at their beds in Minecraft 1.14?

Question: I have been making a custom UHC map for a while now. It wouldn't be PVP-based, just try to last the longest, but the catch is that after dying, that's it: you are back to spawn, then teleported to a new random location in the world, from -1000000 to 1000000.
If the players were to sleep, their spawn point would be their bed, which would mean that if they'd die, they could respawn at their bed, collect items, and go on with their day. This is not how I want it to work (UHC is where you only regenerate with golden apples or potions, so hearts are valuable).
Comment: Possible duplicate of [Force a Player out of bed on a certain night?](https://gaming.stackexchange.com/questions/240745/force-a-player-out-of-bed-on-a-certain-night)
Comment: Have you thought of other ways to tackle the problem? Trying to avoid them respawning at their beds, for example?
Comment: Is there a way to stop this happening? To spawn them at spawn? (The setspawn)
Comment: I'm voting against the duplicate vote because this question specifically asks about preventing the respawn mechanics of beds, not preventing the ability to sleep altogether. Players in this UHC map might want to sleep the night away, which is different mechanic than respawning at a bed.
Answer: You can track people who sleep with the sleep_in_bed scoreboard:
/scoreboard objectives add sleeping minecraft.custom:minecraft.sleep_in_bed

Then you can remove beds around people who are sleeping:
/execute at @e[scores={sleeping=1..}] run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace #beds

And finally reset the score:
/scoreboard players reset @e sleeping

Comment: Thank you! I am going to try this solution. I may do some tests myself to see if the split second they would be in the bed for would stop phantoms or not. I also would like them to be able to sleep to stop phantoms but this could be difficult. Will do tests. Thank you. Also, I assume this has to be in spawn chunks?
Comment: Does this work in minecraft 1.13+ with the new command block changes? As there is no 'sleep_in_bed' apparently?
Comment: If you use command blocks, they have to be loaded, sure. Or you use a function. I think that the subtick of sleeping time might actually be enough to prevent phantoms, yes. The solution for this would be to throw away all this sleeping detection and just run `execute at @a run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace bed` all the time, thereby deleting all beds around players. Edit: I just increased the range in this comment and the answer from 3 to 5, because with a range of 3, players might still be able to click on beds.
Comment: Sorry, I misread the wiki before, the command is now fixed, using the correct scoreboard `minecraft.custom:minecraft.sleep_in_bed`.
Comment: Sorry I am really bad with command blocks; so I need to just have the 1 command block running execute at @a run fill ~-5 ~-5 ~-5 ~5 ~5 ~5 air replace bed? Or do I need the scoreboard one minecraft.custom:minecraft.sleep_in_bed ?
Comment: It works! I need to do it for every colour of bed but it works! It breaks and is sent to their hand. No sleeping at all, would be nice if they could so something to stop phantoms though :/. I used the run fill command by the way! What about the other command; how do you use it? thanks
Comment: Do you have discord? Would prefer to speak there lol. Easier than going back and forth here
Comment: I forgot that this is 1.13+ and beds aren't just beds anymore. Replace "bed" with "#beds" and it should work. Wait, you wanted to stop phantoms? I thought you wanted to prevent all effects of sleeping. I'm currently experimenting more in the new direction. If you want to chat, you should now have enough points that you can use the chat on this site: https://chat.stackexchange.com/rooms/28/minecraft-talk
Comment: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/93040/discussion-between-goofball-2-and-fabian-roling).
Answer: If you just want to a player out of bed after a small delay, without destroying the bed (that it drops instead of being overwritten by air in my other solution is caused by a bug), you can explode him out of it! But carefully, of course…
You still need the sleeping scoreboard:
/scoreboard players add sleeping custom:sleep_in_bed

These are the looped commands, they should be in a repeating command block chain or function:
execute at @a[scores={sleeping=1..}] run summon fireball ~ ~1 ~ {ExplosionPower:0,direction:[0.0,-1.0,0.0]}
effect give @a[scores={sleeping=1..}] resistance 1 5 true
scoreboard players reset @a[scores={sleeping=1..}] sleeping

The first command creates a fireball above the player's head that flies downwards very quickly. It has an explosion power of 0, so it won't damage the environment, even the bed stays where it is.
But you still get damage from it (probably because it's still a burning ball of stone hitting your head), so you are protected from that with a resistance effect that is so high that it absorbs all damage. This would in theory interfere slightly with effects like poison, but you can't sleep while poisoned anyway, so it's not too bad.
And finally, the last command resets the scoreboard so that you don't summon an army of fireballs on top of you every tick.
Comment: Wow this did not work lol. I had like 1000 fireballs flying at me, will try putting the commands in reverse lol
Comment: You probably didn't actually reset the scoreboard. Just put those three commands into a repeating and two chain command blocks or into a function.
Answer: If you don't mind it being constantly day, you could have two repeating command blocks setting the time to noon, and the weather to clear, because those are the only times they can sleep: time set day and weather clear.
If you wanted to have the sun rise, go all the way across and then reset back to rising, you'd need a repeating command block detecting a scoreboard, which when the scoreboard (let's call it stopSleep) is 12000 (sunset) it triggers this command: execute if score @a stopSleep matches 12000.. run time set day. Then, you'd need another standalone repeating command block setting the score of stopSleep to the current time of day: execute store result score @a run time query daytime. What this does is when the current time is 12000, which is tracked in the scoreboard, the command block runs and resets the time to 1000, meaning no one could sleep. You'd still need another one keeping the weather clear. Hope this helps.
Comment: This is a Survival challenge, disabling night is not an option.
Comment: Thanks but I'd rather have night to add the difficulty of surviving. Thanks though :)
Answer: The easiest way to it is:
/time set
then do:
/gamerule doDayLightCycle false
Comment: This is a Survival challenge, disabling night is not an option.


Who to call about sinking porch and mud room?

Question: I live in Massachusetts and have a porch and mud room that are sinking. I was stupid enough to think they had "settled" when I bought the house, but now I can see that they're still sinking, which is causing some damage to the inside of the house (cracks in drywall, etc). I have heard of mudjacking, but can't seem to find anyone local. There was one guy who I stumbled on a couple of years ago that came out and quoted me $10k just to drill these things under it to stabilize it, but I didn't (don't) have the money. At this point, however, I think I may need to take out a loan to address this, but don't want to just jump at the first guy who gave me a quote. I want to gather a few quotes.
Also, I want to know what my options are. If there is someone who can do something to alleviate the problem in a creative (less $$) way, that would preferred.
EDIT: The mudroom is 8 x 10, the porch is 10 x 20. I just signed up for Angie's List and I am still facing the same problem: I can't find someone to call. I'm searching for "foundation" and "porch". I just can't seem to find a business that mentions anything like this.
Comment: Feel free to e-mail me or even call. I'm in Maine, so I won't be able to directly help you, but I can give you some direction in finding a good GC to evaluate and solve your problem. There are several routes you can explore. email@example.com We could also meet on the chat section for some real time Q&A.  All the answers are sincere, but there are a lot of questions that need to be addressed in your case.
Comment: Additional question (note: yes, clearly I screwed up and bought this disaster of a house)...
- Does homeowners insurance ever cover something like this?
Comment: I think that most home insurance policies will not cover settling or subsidence of the foundation. This will surely be stated in the policy, but you CAN ask your agent to be sure. Be careful though, as even simple questions asked of your agent can cause later problems for you, in the form of raised premiums or potential cancellation. (Sigh.) So it really may be a better idea for you to simply wade through the verbiage of your policy. http://ask.metafilter.com/105569/Does-homeowners-insurance-cover-porch-settling-due-to-drought
Comment: There aren't really specialized business just for specific 'porch foundations'. Any good structural engineer or qualified General Contractor is where you'd want to start. Note that this may be a huge deal (need entire new structur) or it could be incredibly minor (need the porch jacked up a few inches and a few new support piers poured).
Answer: Foundation problems are NEVER cheap to solve, and sadly, someone got cheap when the work was first done. Do the work right the first time. Was this addition even inspected by the local building inspector? If not, then you may have some legal recourse if the owners did work and failed to get the necessary permits. I doubt it would work, but only a lawyer would know.
This is not your fault of course, except for buying the house in the first place. A good home inspector should have pointed this out and warned you of the cost to repair it at the time. It is yet another reason to have a home inspection done.
Given all of that, you are now stuck with a problem, that MUST be resolved. I don't even know positively that mudjacking can solve this, only a good mudjacking contractor will know for sure. No matter what, there will surely be some excavation involved, even if only to determine how much must be done to repair the problem.
Start asking around. There are foundation services companies around who specialize in problems like this. Get and check references. Don't just jump at the cheapest estimate you get.
Comment: I'd be surprised that there is not someone to call, although they will probably be serving a wide area. In the upstate NY area, we had a company come out to do a repair for us. They claim to serve customers across about a 100 mile radius around Rochester.
Answer: How large of a porch are we talking about? Typically you'd want someone to come jack up the porch and replace the foundation piers. 10k seems really high, but then again, I don't know the size of the porch or foundation piers.
You'll want to call a licensed contractor to handle it. They might need to bring out a structural engineer or a soil expert. Hard to say why it's sinking...could be undersized foundation, could be poor soil/improper footings, could be water problems, etc.
EDIT:
If the first guy quotes 10k, it may very well be a 10k job. But do get other quotes. Call up a few structural engineers and/or general contractors.
Also note that you need to figure out why the porch was sinking in the first place. I've seen this happen before due to simply bad gutter downspouts where the water was pouring out right on top of the foundation piers. That's bad.
Answer: You need to search on "foundation" and "engineering".
Several years ago I worked for a company who did this type of work in the Boston area.  Basically, we would jack up the foundation, build a new foundation and then lower the existing structure on to the new foundation.
However, it not as simple as that.  The firm was run by engineers who studied the structure and soil conditions to ensure the new foundation woud be able to handle the load.
Boston is famous for sinking foundations since a good part of the city sits on sand that was brought in and filled up the harbor.  So, you should be able to find some firms that specialize in this type of work.


Issue when deploying Yesod 1.4 to Heroku

Question: im having a problem when deploying a new Yesod application to heroku. I am following the steps here;
https://github.com/yesodweb/yesod/wiki/Deploying-Yesod-Apps-to-Heroku
But since yesod 1.4 was released, I am getting the following issue show up in my logs (PaperTrail);
Dec 21 04:42:51 fxtest heroku/web.1:  Starting process with command <code>./dist/build/fxtest/fxtest production -p 37347</code>
Dec 21 04:42:52 fxtest app/web.1:  loadAppSettings: Could not parse file as YAML: production
Dec 21 04:42:52 fxtest app/web.1:  fxtest: InvalidYaml (Just (YamlException "Yaml file not found: production"))
Dec 21 04:42:53 fxtest heroku/web.1:  Process exited with status 1
Dec 21 04:42:53 fxtest heroku/web.1:  State changed from starting to crashed
This appears to say that I have a missing yaml file called "production". If I try to negate this error by adding a dummy yaml file, then I get a similar error telling me I am missing a file called "-p". This leads me to think that the issue is being caused by my Procfile, which only contains one line;
web: ./dist/build/fxtest/fxtest production -p $PORT
thanks in advance for any help
Answer: If you're using the new scaffolding, it no longer requires the command line parameter. Try dropping production from the command, and probably leave of the-p $PORT as well.
Comment: Thanks, that worked! :) BTW - how/where should I have found that out?
Comment: There was a blog post and email to the mailing list about the scaffolding changes: https://www.fpcomplete.com/blog/2014/12/experimental-packages-stackage


autocomplete ajax on two fields

Question: I am having trouble executing the following code successfully. I want to get autocomplete data from the server on 1st field (drug1) which is successful. I want that the 2nd field (drugdose1) should return result based on the value of the 1st field (drug1). But I am unable to pass the value of the drug1 to the php file. The firefox debug displays as localhost/lib/searchdose.php?d=&q=xx.
Here is the code:

<link rel="stylesheet" type="text/css" href="lib/autocomplete.css" />

<form name="hello">
<input type="hidden" id="testing" value="hi there">
Drug Name: <input type="text" tabindex="1" size="40" name="drug1" id="drug1">

Drug Dose: <input tabindex="2" type="text" name="drugdose1" id="drugdose1" size="35">

</form>

I am using autocomplete.js from https://github.com/dyve/jquery-autocomplete ... I am not using jquery.ui autcomplete ..
Comment: Please note that I am not using autocomplete.js from the [link]https://github.com/dyve/jquery-autocomplete[/link] because this is a small sized script as compared to jquery UI autocomplete ...
Answer: Try this,
src = 'lib/searchdose.php';

    $("#drugdose1").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: src,
                dataType: "json",
                data: {
                    d: $("#drug1").val()
                },
                success: function(data) {
                    response(data);
                }
            });
        },
        min_length: 3,
        delay: 300
    });

Comment: OP is not using jQuery UI autocomplete.
Comment: How do you know that the person who asked the question is using jquery-ui autocomplete?
Comment: @SalmanA sorry I am guessing he using `lib/autocompletefull.js`.
Comment: The above code doesnt work because I am not using jquery-ui autocomplete ... i am using autocomplete from https://github.com/dyve/jquery-autocomplete because its small sized ..
Answer: I have sort this problem on my own. Here is the solution:

<form name="hello">
<input type="hidden" id="testing" value="hi there">
Drug Name: <input type="text" tabindex="1" size="40" name="drug1" id="drug1" onchange="javascript:newv();">

Drug Dose: <input tabindex="2" type="text" name="drugdose1" id="drugdose1" size="35">

</form>

autocomplete ajax on two fields


php convert 12hr to 24hr 12:00:am -> 00:00:00

Question: I am getting a datetime format from a form in this format
// $start equals 2014-04-19 12:00:am
// I need to convert to 24hr 2014-04-19 00:00:00

$startconvert = str_replace(':am', '', $start);
$startconverted = date( 'Y-d-m H:i:s', strtotime($startconvert));
echo($startconverted);

//becomes 2014-19-04 12:00:00 which is 12pm

Anyone know how to do this? This looks right to me but it ends up being 12pm
Comment: Do you really have a `:` before `am`?
Comment: I was just about to ask the same.  That may be your only issue.  Don't replace the `am` and just replace that last `:` with a space.
Answer: $date = DateTime::createFromFormat('Y-m-d h:i:a', '2014-04-19 12:00:am');
echo $date->format('Y-m-d H:i:s');

This just takes the date you have and reads it in by its parts using DateTime::createFromFormat(). That DateTime object can then be formatted normally.
Comment: its a DateTime object that is recognized.. so there are formatting options available


KeyListener not triggering actions

Question: The keyListener does not fire action though i registered the frame to the keyListener.
In the other code, implementing the KeyListener interface, registering the JFrame and overriding the appropriate methods was all that was needed for the keyListener to work.
import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Mains implements KeyListener {
    private static Point point = new Point();

    public Mains() {
        final JFrame frame = new JFrame();
        frame.setUndecorated(true);
        JButton button = new JButton("Close Me");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });

        frame.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                point.x = e.getX();
                point.y = e.getY();
            }
        });
        frame.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                Point p = frame.getLocation();
                frame.setLocation(p.x + e.getX() - point.x, p.y + e.getY()
                        - point.y);
            }
        });

        frame.setSize(300, 300);
        frame.setLocation(200, 200);
        frame.setLayout(new BorderLayout());

        frame.getContentPane().add(button, BorderLayout.NORTH);
        frame.getContentPane().add(new JLabel("Drag Me", JLabel.CENTER),
                BorderLayout.CENTER);
        frame.setVisible(true);
        frame.addKeyListener(this);
    }

    public static void main(String[] args) {
        new Mains();
    }

    public void keyPressed(KeyEvent e) {
        System.out.println("pressed");
    }

    public void keyReleased(KeyEvent e) {
        System.out.println("released");
    }

    public void keyTyped(KeyEvent e) {

    }
}

Answer: By default, JFrame window components are not focusable. Although you can call JFrame.setFocusable(true), it is far better to use Key Bindings.
KeyListener requires focus with components for the interaction with KeyEvents to work. In contrast, when using Key Bindings, you can map an Action to a KeyStroke even when a component doesn't have focus.
Comment: Thanks, that solved the problem. well in the other code, there was no where i added the setFocusable(true) method but the code worked just fine, can you enlighten me?
Comment: See update. I would recommend `Key Bindings` for use in Swing though.
Answer: A KeyListerner is only capable of receiving key events if the component it is attached to can receive focus and has focus.
The problem with a JFrame is that it contains a JRootPane, which contains a content pane which occupies the entire surface of frame, which will prevent the frame from ever gaining focus, this, never be capable of receiving key events.
KeyListener is rarely the right API of choice, normally, it's better to use key bindings
You may also find How to use root panes of interest

KeyListener not triggering actions


Using a wildcard IP Address to get a Domain Name

Question: I am trying to write a class that will return a domain name from an IP Address that is in my /etc/hosts file. For example I know a block of IP Address which Google own are 126.96.36.199 - 22.214.171.124 and in my hosts file I have;
220.127.116.11   Google
184.108.40.206   Google
18.104.22.168   Google
18.104.22.168   Google
188.8.131.52   Google
18.104.22.168   Google

I have wrote a simple piece of code that will look to the hosts file and search for the name of the corresponding IP Address. Here is the code;
String destination = "184.108.40.206";
InetAddress address = InetAddress.getByName(destination);
String resolvedHost = address.getHostName();
System.out.println("Translated " + destination + " to host name " + resolvedHost);

That will return the following Translated 188.8.131.52 to host name Google.
I then tried;
String destination = "74.125.24.*";
InetAddress address = InetAddress.getByName(destination);
String resolvedHost = address.getHostName();
System.out.println("Translated " + destination + " to host name " + resolvedHost);

But got the following error in response;
java.net.UnknownHostException: 74.125.24.*
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(Unknown Source)
at java.net.InetAddress.getAddressesFromNameService(Unknown Source)
at java.net.InetAddress.getAllByName0(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getAllByName(Unknown Source)
at java.net.InetAddress.getByName(Unknown Source)
at IPToDomainName.main(IPToDomainName.java:12)

Is there a way that I can use a wildcard to represent Googles IP addresses?
Comment: Why do you need to do this? This is exactly the opposite of what domain names try to achieve. I suspect if you describe your actual goal, there will be a better way to achieve it.
Comment: We have a router in which it collects IP Addresses of the websites that people connected to the WiFi are viewing. From that we can chart this, show how many people visited what website, but the result is only showing the IP Address. I have had the /etc/hosts file edited but there is always more IP Addresses
Comment: why dont you feed the collected ip address to an prog and get host name list to create charts
Comment: Afraid that is out of my hands, I am just a small cog in a big machine and just trying to solve this issue that was given to me
Comment: @dan why are you putting things in the host file? Your code should do reverse DNS without putting anything in host file.
Answer: Can you iterate through it?
for (int i=0;i<=255;i++) {
    String destination = "74.125.24." + i;
    InetAddress address = InetAddress.getByName(destination);

    if (address == null) // Or any exception.
         continue;

    String resolvedHost = address.getHostName();

    System.out.println("Translated " + destination + " to host name " + resolvedHost);
}

Comment: You forgot to use `i` in that loop. I suspect you mean `"74.125.24." + i;`. You also might need to include the `255` value, at least according to the question.
Comment: check address null before gethostname :)


How to make an NSTextView layer backed?

Question: How can you make an NSTextView layer backed?
I know you can make an NSView layer backed by setting the NSView.wantsLayer property to true.
When I do this on an NSTextView the text it normally displays is not visible.
This is my swift (playground) code:
import Cocoa
import QuartzCore

let tv = NSTextView(frame: NSRect(x: 0, y: 0, width: 100, height: 50))
tv.string = "Hello world."
tv.wantsLayer = true

The property tv.layer returns an NSTextViewBackingLayer, which sounds at least something related to displaying text.
What is going wrong here?
Thanks in advance.
Comment: Why would you want to do that?
Comment: It works in a Cocoa project. Don't know why it doesn't work in Playground
Comment: Do you use the same code in the Cocoa project? Does the text view have a layer before `tv.wantsLayer = true`?
Comment: I wanted to add a mask to the `NSTextView.layer.mask` property, to create a truncating fade out effect on the end of the string.
I use the same code in a cocoa project, where it is also not working. `tv.layer` returns nil before `tv.wantsLayer = true`.
Comment: @CodeDifferent it doesn't work in a Cocoa project. Add a text view to a XIB/storyboard and check the Core Animation Layer checkbox. The width of the frame is 0.0 in the nib. Any ideas?
Comment: `tv.layer` returned also all kinds of zero sized frames and bounds. Before you set `tv.wantsLayer = true` the `tv.frame` and
`tv.bounds` properties return both a correct size of 100x50. After setting `tv.wantsLayer = true` the properties are changed to zeros.

So if we try to set the correct sizes again in combination with a `tv.layerContentsRedrawPolicy` set to the default value `NSView.LayerContentsRedrawPolicy.duringViewResize`, then `tv.layer.contents` will be updated when we change these geometry properties.
Comment: I had to set both `tv.frame = NSRect(x: 0, y: 0, width: 100, height: 50)` and `tv.minSize = NSSize(width: 100, height: 50)`.
After this a correct layer is displayed. This is quite cumbersome and I'm not sure why this works. It seems like something goes wrong when enabling layer support.
Answer: Adding a CALayer to a NSTextField screws up the frame, you have to set those values as the new CALayer sets them to 0,0,0,0.

How to make an NSTextView layer backed?


No sound on Huawei 14S with Ubuntu 22.10

Question: We bought a Huawei 14S, it pretty nice but there's troubles with sound on speaker and headphones, sometimes headphones don't work, often speaker doesn't work.
It's a nightmare !
Answer: It's not a perfect solution, more a workaround :
Sound of speaker works and need to use external adapter for headphones (something like this one)
1 - add this line at bottom of /etc/modprobe.d/alsabase.conf :
options snd-hda-intel dmic_detect=0

2 - reboot
3 - try command alsactl init.
Speaker should work (go to sound parameters if not).
4 - if alsactl init works, add startup application in gnome :
launch gnome-session-properties command and add a new app :
name :    Alsactl Init
command : alsactl init
comment : to make speaker work

. . save, close and reboot
Speaker should work (go to sound parameters if not).
! Never use the integrated headphones
! Use external usb to jack adapter
PS : The command listed here might help if still doesn't work (need to install alsa-tools package to use hda-verb command).
Answer: I encountered a similar problem, and based on the materials I found, I wrote a daemon that solves it.
Problem
The headphone and speaker channels are mixed up in the sound card driver for Linux distributions.
When headphones are connected, the system considers that sound should be output from the speakers. When the headphones are off, the system tries to output sound through them.
Problem details (found here)
Looks like there is some weird hardware design, because from my prospective, the interesting widgets are:

0x01 - Audio Function Group
0x10 - Headphones DAC (really both devices connected here)
0x11 - Speaker DAC
0x16 - Headphones Jack
0x17 - Internal Speaker

And:

widgets 0x16 and 0x17 simply should be connected to different DACs 0x10 and 0x11, but Internal Speaker 0x17 ignores the connection select command and use the value from Headphones Jack 0x16.
Headphone Jack 0x16 is controlled with some weird stuff so it should be enabled with GPIO commands for Audio Group 0x01.
Internal Speaker 0x17 is coupled with Headphone Jack 0x16 so it should be explicitly disabled with EAPD/BTL Enable command.

Solution
A daemon has been implemented that monitors the connection/disconnection of headphones and accesses the sound card device in order to switch playback to the right place.
You can get installer in my github repo: huawei-ubuntu-sound-fix.
Hope it helps.


update-manager crashes with undefined symbol (libpyglib-gi-2.0-python2.7.so)

Question: When I lauch the software updater from the App launcher's icon,
it crashes, runing it from the command line shows what the error is :
I've been getting this since 12.10, and it's still present on 13.10
max@max-ubuntu:~$ update-manager
Traceback (most recent call last):
  File "/usr/bin/update-manager", line 28, in <module>
    from gi.repository import Gtk
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 27, in <module>
    from ._gi import _API, Repository
ImportError: /usr/lib/x86_64-linux-gnu/libpyglib-gi-2.0-python2.7.so.0: undefined symbol: _Py_ZeroStruct
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python2.7/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python2.7/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python2.7/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python2.7/dist-packages/apport/packaging_impl.py", line 20, in <module>
    import apt
  File "/usr/lib/python2.7/dist-packages/apt/__init__.py", line 21, in <module>
    import apt_pkg
ImportError: /usr/lib/python2.7/dist-packages/apt_pkg.so: undefined symbol: _Py_ZeroStruct

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/update-manager", line 28, in <module>
    from gi.repository import Gtk
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 27, in <module>
    from ._gi import _API, Repository
ImportError: /usr/lib/x86_64-linux-gnu/libpyglib-gi-2.0-python2.7.so.0: undefined symbol: _Py_ZeroStruct
max@max-ubuntu:~$

Comment: Similar question here: http://askubuntu.com/q/607210/367990
Answer: update-manager is a Python 3 application. However I suspect your PYTHONPATH contains directories referring to your Python 2 installation. The problematic one is /usr/lib/python2.7/dist-packages, which causes the incompatible Python 2 version of the apt package to be picked up.
Try unsetting your PYTHONPATH or run as
PYTHONPATH= update-manager


Sharing ssh credentials with dev container in vscode

Question: I have setup a VS Code dev container and I can run and debug my code inside. My ~/.gitconfig from my host system was correctly copied into the container. However, my ssh credentials don't seem to work (or are not available), neither are my gnupg signing files (~/.gnupg) available.
Must I manually copy these files ( ~/.ssh and ~/.gnupg) into the container?
The documentation cautions:

There are some cases when you may be cloning your repository using SSH keys instead of a credential helper. To enable this scenario, the extension will automatically forward your local SSH agent if one is running.

The only stated requirement is the SSH-agent server running on my host system, which it is:
C:\Windows\system32> Get-Service ssh-agent

Status   Name               DisplayName
------   ----               -----------
Running  ssh-agent          OpenSSH Authentication Agent

What is the correct way to make my SSH credentials available to my dev container?
Comment: Could you share your container config and any relevant settings in your `.gitconfig`? I'm having difficulty reproducing.
Comment: So I updated my answer this morning, I think maybe the issue is you have terminal.integrated.inheritEnv unchecked? See my answer.
Comment: That was it, I overwrote it in my local project.
Comment: Since it works on your machine, I gave it a try on another and it works there as well. I think I found the culprit, the `.ssh` folder was set to another path and hence the mounting of `.ssh` pointed to the wrong folder. Feel free to post your example `.devcontainer.json` and I staple my bounty to it. Don't want the points being lost, so better they serve someone who tried checking out this question.
Answer: There are a couple prerequisites.

You must have VS Code setting terminal.integrated.inheritEnv enabled.
You must have your ssh-agent ran at login.

VS Code supports your ssh settings via doing two things:

Copying in known_hosts from your ~/.ssh/known_hosts.
Finding your ssh-agent socket created when you logged into the system.

For me on macOS, the ssh-agent creates a file in a random location, e.g.:
SSH_AUTH_SOCK=/tmp/vscode-ssh-auth-1a6abf46-1c35-41bf-aedd-e08135a38f5f.sock

My login scripts performs two commands, in this example I ran them on the command line:
% eval `ssh-agent`
Agent pid 15376

% ssh-add
Identity added: /Users/risner/.ssh/id_rsa (/Users/risner/.ssh/id_rsa)

For Windows, this answer should help in setting up the agent:
How to run ssh-add on windows?
Once created, all your containers should pick it up without specific settings. Here is a test .devcontainer.json file:
{
  "build": {
    "dockerfile": "Dockerfile",
    "args": { "VARIANT": "hirsute" }
  },
  "forwardPorts": [3000]
}

For a M1 Mac, the hirsute variant picks up the native arm64.
My test Dockerfile is rather generic:
FROM mcr.microsoft.com/devcontainers/javascript-node:0-18
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install git

Once in the container, I verified the keys worked:
node ➜ /workspaces/MySSH (master) $ set|grep -i ssh
PWD=/workspaces/MySSH
REMOTE_CONTAINERS_SOCKETS='["/tmp/vscode-ssh-auth-1a6abf46-1c35-41bf-aedd-e08135a38f5f.sock","/tmp/.X11-unix/X0"]'
SSH_AUTH_SOCK=/tmp/vscode-ssh-auth-1a6abf46-1c35-41bf-aedd-e08135a38f5f.sock
node ➜ /workspaces/MySSH (master) $ ssh email@example.com
Last login: Mon Mar  6 08:31:03 2023 from 184.108.40.206

Comment: The official docs indicate that ssh agent forwarding should work by default on macOS however they _do not_ mention that setting `terminal.integrated.inheritEnv` is required. This answer is the only place I've seen it mentioned in many hours of troubleshooting. Edit: I forgot to mention - the answer is correct and this is incredibly helpful, thanks :)
Answer: It is also possible to achieve this with the mount capability of the devcontainer.json configuration file:
    {
        "name": "container name",
        ...
        "remoteUser": "root",
        "mounts": [
            "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached",
        ]
       ...
    }

Comment: That's neat, thanks!
Answer: With my version of dev containers there is a folder
/home/vscode

The correct mount option is therefore
"mounts": [
    "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached",
]

extra info:
I needed this, since I have two github accounts with two ssh keys. When only the ssh agent is forwarded, git is picking up the wrong ssh key and authentication fails.
To solve this I added two hosts in the .ssh/config.
Host git_priv
  Hostname github.com
  IdentityFile ~/.ssh/id_rsa_git_private
  IdentitiesOnly yes

Host github.com
  Hostname github.com
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes

Basically I set one ssh key as standard (using github.com as the host) and the the other to only work with github-private.com as domain. If I now inlclude this git config with the above command into the devcontainer, I get the correct ssh key resolution.


Liquibase: how to load date fields from CSV?

Question: I'm on a Spring-Boot project and I'm using Liquibase in order to populate the DB from CSV files. Among them, there are some entities with date fields.
Here is my databaseChangelog for creating the table:
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <property name="now" value="now()" dbms="h2"/>

    <property name="now" value="current_timestamp" dbms="postgresql"/>

    <property name="floatType" value="float4" dbms="postgresql, h2"/>
    <property name="floatType" value="float" dbms="mysql, oracle, mssql"/>

    <changeSet id="20180424154826-1" author="jhipster">
        <createTable tableName="container">
            <column name="id" type="bigint" autoIncrement="${autoIncrement}">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(255)">
                <constraints nullable="false" />
            </column>

            <column name="description" type="varchar(2000)">
                <constraints nullable="true" />
            </column>

            <column name="container_type" type="varchar(255)">
                <constraints nullable="true" />
            </column>

            <column name="created" type="timestamp">
                <constraints nullable="true" />
            </column>

        </createTable>
        <dropDefaultValue tableName="container" columnName="created" columnDataType="datetime"/>

    </changeSet>

</databaseChangeLog>

And here the changelog for populating the Table:
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <property name="now" value="now()" dbms="h2"/>

    <property name="now" value="current_timestamp" dbms="postgresql"/>

    <property name="floatType" value="float4" dbms="postgresql, h2"/>
    <property name="floatType" value="float" dbms="mysql, oracle, mssql"/>

    <changeSet id="20180425154950-1" author="developer">
        <loadData catalogName="container"
                  encoding="UTF-8"
                  file="config/liquibase/containers.csv"
                  schemaName="public"
                  separator=";"
                  quotchar="'"
                  tableName="container">
        </loadData>
    </changeSet>

</databaseChangeLog>

And in the end the CSV containing the data for the table:
id;name;description;container_type;created
1;'Human';'Human container';'HUMAN';${now}
2;'IT';'IT container';'IT';${now}
3;'Physical';'Physical container';'PHYSICAL';${now}
4;'Intangible';'Intangible container';'INTANGIBLE';${now}

The problem is that if I run:
mvn clean install

I get the following log in the console, complaining about the date field:
nested exception is liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20180425154950_added_Containers_data.xml::20180425154950-1::developer:
     Reason: liquibase.exception.DatabaseException: Cannot parse "TIMESTAMP" constant "${now}"; SQL statement:
INSERT INTO public.container (id, name, description, container_type, created) VALUES ('1', 'Human', 'Human container', 'HUMAN', '${now}') -- ('1', 'Human', 'Human container', 'HUMAN', '${now}') [22007-197] [Failed SQL: INSERT INTO public.container (id, name, description, container_type, created) VALUES ('1', 'Human', 'Human container', 'HUMAN', '${now}')]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:297)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:189)
    at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:131)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:283)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:173)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20180425154950_added_Containers_data.xml::20180425154950-1::developer:
     Reason: liquibase.exception.DatabaseException: Cannot parse "TIMESTAMP" constant "${now}"; SQL statement:
INSERT INTO public.container (id, name, description, container_type, created) VALUES ('1', 'Human', 'Human container', 'HUMAN', '${now}') -- ('1', 'Human', 'Human container', 'HUMAN', '${now}') [22007-197] [Failed SQL: INSERT INTO public.container (id, name, description, container_type, created) VALUES ('1', 'Human', 'Human container', 'HUMAN', '${now}')]
    at liquibase.changelog.ChangeSet.execute(ChangeSet.java:619)
    at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
    at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:79)
    at liquibase.Liquibase.update(Liquibase.java:214)
    at liquibase.Liquibase.update(Liquibase.java:192)
    at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:431)
    at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:388)
    at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:94)
    at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.afterPropertiesSet(AsyncSpringLiquibase.java:84)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1688)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1626)
    ... 43 common frames omitted

While if I run:
mvn process-resources
mvn liquibase:update

the result is a BUILD SUCCESS
Comment: I don't know if that will work, but try to add nested element to`` that will be your column. Something like this: `` Maybe you should use `valueComputed` attribute. Just read [this page](https://www.liquibase.org/documentation/column.html)
Answer: In your csv just use now instead of ${now}. Then it should not throw Cannot parse "TIMESTAMP" constant "${now}"; any more


Is there a way to get an arraylist element by its name?

Question: I write a program in Java, and i have the following problem:
//this is the important part of my class student
public class Student{
    private String name;
    public Student(String name){
        this.name = name;
    }
    //Getter
    public String getName() {
        return name;
    }
}

//this is the other class (could be the main for example)
public class Load {
    private ArrayList<Student> student= new ArrayList<Student>();
    student.add(new Student(name));
}

Later in the program I need those students again. I can get them like this:
System.out.println(student.get(0));

But I dont have the number of the students. Is there a way to get them by the name, which is in the class Student?
Comment: iterate through your list, check if student.getName() equals your search and return if it does. Since Names aren't necessarily unique you might want to return a List
Comment: you can check if name present in list, student.contains("dfighter3")
Comment: `student.stream().filter(x -> x.equals("name")).findAny().orElse(null)`
Comment: Why don't you use a `Map` (or better a Guava `Multimap` to support multiple students with the same name)  instead?
Comment: the names are unique in my case
Answer: What you can do is create a function which takes a String as input, searches the student list and returns if the object was found.
public Student findStudentByName(String name) {
    for(Student studentObj : student) {
        if(studentObj.getName().equals(name)) {
            return studentObj;
        }
    }
    return null;
}

Answer: In this case maybe you can use a Map to save that list of Students. Then you shoud get Students by name.
Map<String, Student> students = new HashMap<String, Student>();
Student maryIn = new Student();
maryIn.setName("Mary");
students.put(maryIn.getName(), maryIn);

Student maryOut = students.get("Mary");

Answer: You can get the number of elements in a list by using student.size().
Additionally, you should use interface type whenever possible, in your case List<Student> student = new ArrayList<Student>();.
Also, have a typo in your code: student.add(new Student(name));.
As for the last question, just use an extra method inside Load that searches for the desired student name in the current list:
public Student searchByName(String targetStudentName) {
    for (Student s : student) {
        if (targetStudentName.equals(s.getName())) {
            return s;
        }
    }
    return null;
}


"New" tag in clan info next to name. How long does it last?

Question: How long does the "new" tag last next to players names that have joined your clan?
Answer: A new member of a clan has the new tag for 3 days or until the player is promoted.
Answer: I agree that it will disappear after the player is promoted, but I think the "new" tag disappears at the end of the current season (1-month period).
Comment: 3 days is when it goes away I tested it
Answer: It leaves in about 10 days unless you're promoted
Comment: 3 days not 10...


Can Erwin Forward Engineer a Physical model to generate T-SQL Table Creation scripts?

Question: I never used ErWin, but I think it would be a shame if the DB Developers had to manually create all of the tables that have already been defined in a huge ErWin Physical model.
Can Erwin generate SQL Server specific DDL?
Answer: Yes, Erwin can generate MS SQL Server specific DDL.