Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

You must ensure that you add the location of your .class file to your classpath. So, if its in the current folder, add . to your classpath. Note that the Windows classpath separator is a semi-colon, i.e. a ;.
3 years ago
Execute the same commands but replace the "-A" with "-D". For example:
***
iptables -A ...
***
becomes
***
iptables -D ...
***
3 years ago
The trick is to use useradd instead of its interactive wrapper adduser. I usually create users with:
***
RUN useradd -ms /bin/bash newuser
***
which creates a home directory for the user and ensures that bash is the default shell.

You can then add:
***
USER newuser
WORKDIR /home/newuser
***
to your dockerfile. Every command afterwards as well as interactive sessions will be executed as user newuser:
***
docker run -t -i image
newuser@131b7ad86360:~$
***
You might have to give newuser the permissions to execute the programs you intend to run before invoking the user command.

Using non-privileged users inside containers is a good idea for security reasons. It also has a few drawbacks. Most importantly, people deriving images from your image will have to switch back to root before they can execute commands with superuser privileges.
3 years ago
You can script it with a tool like expect (there are handy bindings too, like Pexpect for Python).
3 years ago
I check for both Wi-fi and Mobile internet as follows...
***
private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
***
Obviously, It could easily be modified to check for individual specific connection types, e.g., if your app needs the potentially higher speeds of Wi-fi to work correctly etc.
3 years ago
If the device is in airplane mode (or presumably in other situations where there's no available network), cm.getActiveNetworkInfo() will be null, so you need to add a null check.

Modified (Eddie's solution) below:
***
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
}
***
Also add the following permission to the AndroidManifest.xml:
***

***
One other small point, if you absolutely need a network connection at the given point in time, then it might be better to use netInfo.isConnected() rather than netInfo.isConnectedOrConnecting. I guess this is up to the individual use-case however.
3 years ago
You don't need wildcards in the REPLACE - it just finds the string you enter for the second argument, so the following should work:
***
UPDATE dbo.xxx
SET Value = REPLACE(Value, '123', '')
WHERE ID <=4
***
If the column to replace is type text or ntext you need to cast it to nvarchar
***
UPDATE dbo.xxx
SET Value = REPLACE(CAST(Value as nVarchar(4000)), '123', '')
WHERE ID <=4
***
3 years ago
You can try to disable the only_full_group_by setting by executing the following:
***
mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
***
3 years ago
An index is used to speed up searching in the database. An index can be used to efficiently find all rows matching some column in your query and then walk through only that subset of the table to find exact matches. If you don't have indexes on any column in the WHERE clause, the SQL server has to walk through the whole table and check every row to see if it matches, which may be a slow operation on big tables.

The index can also be a UNIQUE index, which means that you cannot have duplicate values in that column, or a PRIMARY KEY which in some storage engines defines where in the database file the value is stored.
3 years ago
You cannot alter a column to be an IDENTITY column. What you'll need to do is create a new column which is defined as an IDENTITY from the get-go, then drop the old column, and rename the new one to the old name.
***
ALTER TABLE (yourTable) ADD NewColumn INT IDENTITY(1,1)

ALTER TABLE (yourTable) DROP COLUMN OldColumnName

EXEC sp_rename 'yourTable.NewColumn', 'OldColumnName', 'COLUMN'
***
3 years ago
Count all the DISTINCT program names by program type and push number
***
SELECT COUNT(DISTINCT program_name) AS Count,
program_type AS [Type]
FROM cm_production
WHERE push_number=@push_number
GROUP BY program_type
DISTINCT COUNT(*) will return a row for each unique count. What you want is COUNT(DISTINCT ):
***evaluates expression for each row in a group and returns the number of unique, non-null values.
3 years ago
Without using CTE and ROW_NUMBER() you can just delete the records just by using group by with MAX function here is and example
***
DELETE
FROM MyDuplicateTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyDuplicateTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)
***
3 years ago