text:
Q: Accessing first column of pandas value_counts I'm trying to use value_counts() function from Python's pandas package to find the frequency of items in a column. This works and outputs the following:
57     1811
62      630
71      613
53      217
59      185
68       88
52       70

Name: hospitalized, dtype: int64

In which the first column is the item and the right column is its frequency in the column.
From there, I wanted to access the first column of items and iterate through that in a for loop. I want to be able to access the item of each row and check if it is equal to another value. If this is true, I want to be able to access the second column and divide it by another number.
My big issue is accessing the first column from the .value_counts() output. Is it possible to access this column and if so, how? The columns aren't named anything specific (since it's just the value_counts() output) so I'm unsure how to access them.

A: Use Panda's iteritems():
df = pd.DataFrame({'mycolumn': [1,2,2,2,3,3,4]})
for val, cnt in df.mycolumn.value_counts().iteritems():
    print 'value', val, 'was found', cnt, 'times'

value 2 was found 3 times
value 3 was found 2 times
value 4 was found 1 times
value 1 was found 1 times

A: value_counts returns a Pandas Series:
df = pd.DataFrame(np.random.choice(list("abc"), size=10), columns = ["X"])
df["X"].value_counts()
Out[243]:
c    4
b    3
a    3
Name: X, dtype: int64

For the array of individual values, you can use the index of the Series:
vl_list = df["X"].value_counts().index
Index(['c', 'b', 'a'], dtype='object')

It is of type "Index" but you can iterate over it:
for idx in vl_list:
    print(idx)

c
b
a

Or for the numpy array, you can use df["X"].value_counts().index.values

A: You can access the first column by using .keys() or index as below:
df.column_name.value_counts().keys()
df.column_name.value_counts().index


text:
Q: How to prevent this circular reference in Flask/SQLAlchemy Models? I have the following four model classes in my Flask/SQLAlchemy application (a fifth class MyClassA is not shown here but is reference):
class MyClassF(db.Model):
    valid_fs = ['F1', 'F2']
    f_id = db.Column(db.Integer, nullable=False, primary_key=True)
    name = db.Column(db.Enum(*valid_fs, name='f_enum'), default='F1', nullable=False)

class MyClassD(db.Model):
    d_id = db.Column(db.Integer, nullable=False, primary_key=True)
    name = db.Column(db.String(128))
    v_collection = db.relationship('MyClassV', lazy='dynamic', backref=db.backref('d'), cascade='all, delete-orphan')

class MyClassV(db.Model):
    v_id = db.Column(db.Integer, nullable=False, primary_key=True)
    d_id = db.Column(db.Integer, db.ForeignKey(MyClassD.d_id), nullable=False)
    c_collection = db.relationship('MyClassC', lazy='dynamic', backref=db.backref('v'), cascade='all, delete-orphan')
    a_collection = db.relationship('MyClassA', lazy='dynamic', backref=db.backref('v'), cascade='all, delete-orphan')

class MyClassC(db.Model):
    c_id = db.Column(db.Integer, nullable=False, primary_key=True)
    v_id = db.Column(db.Integer, db.ForeignKey(MyClassV.v_id), nullable=False)
    f_id = db.Column(
        db.Integer,
        db.ForeignKey(MyClassF.f_id),
        nullable=False,
        #default=MyClassF.query.filter(MyClassF.name == "F1").one().f_id
    )

Creating this schema using the Flask-Migrate command db init, db migrate and db upgrade works just fine.
However, when I un-comment the line the definition of MyClassC.f_id and try it again (after removing the migrations directory), I get the following circular dependency error:

sqlalchemy.exc.InvalidRequestError: When initializing mapper
  Mapper|MyClassV|my_classV, expression 'MyClassC' failed to locate a
  name ("name 'MyClassC' is not defined"). If this is a class name,
  consider adding this relationship() to the
  class after both dependent classes have been defined.

All I'm trying to do is ensure that the default value of MyClassC.f_id is set by querying the MyClassF table. This check should occur at insertion time -- not when the database is being created. So I don't understand why I am getting this error now.
How can I use db.relationship() (or any other technique) to get around this circular dependency error while enforcing the database integrity rule I'm trying to implement?

A: I believe the default parameter is translated to the SQL DEFAULT constraint. AFAICT this constraint is not evaluated at insertion time, but when creating the table and the value is then used as a default (which means the default value is set once and forall at creation of the table and used for all rows that lack that column, it cannot dynamically change according to the contents of an other table).
However the documentation of SQLAlchemy mentions the fact that you can pass in a python function as default value and it will be called for each insert to obtain the default value to use, so you can do:
class MyClassC(db.Model):
    c_id = db.Column(db.Integer, nullable=False, primary_key=True)
    v_id = db.Column(db.Integer, db.ForeignKey(MyClassV.v_id), nullable=False)
    f_id = db.Column(
        db.Integer,
        db.ForeignKey(MyClassF.f_id),
        nullable=False,
        default=lambda: MyClassF.query.filter(MyClassF.name == "F1").one().f_id
    )

Note however that this will not use any database facility to provide the default value, it's SQLAlchemy first obtaining the default value and then manually inserting it in your queries.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Allow limited number of possibilities for a option in boost program_options Can I tell boost program_options somehow, that a specific options has a limited number of values?
For example, the option "--verbosity" may only be debug,high or low?!?
Thanks!
Nathan

A: The documentation explains how to write Custom Validators.


text:
Q: The use of various `auth` models Other than auth_user, I have never used auth_group, auth_group_permissions, auth_permission, auth_user_user_permissions, and auth_user_user_permissions. What are the specific uses for each of these models? Is it common that one would not need any of these? If so, what would be the best way to get rid of them (doing a straight DROP TABLE or at the django-level)? Would there ever be a downside of removing these?

A: I'd recommend reading the User authentication section in the Django documentation. It describes the components of the auth system as:

*

*Users

*Permissions: Binary (yes/no) flags designating whether a user may perform a certain task.

*Groups: A generic way of applying labels and permissions to more than one user.

The simplest use of permissions is to control the actions a certain user can take in the Django Admin site. You can also use permissions to restrict access to your own views using the django.contrib.auth.decorators.permission_required decorator.
When this is combined with groups you can easily assign the same permissions to a whole group of users.
The other database tables you mention (auth_group_permissions, etc.) store the relationships between users and permissions or groups and permissions.
While you may not be using these parts of the authentication system directly you are almost certainly using other code from django.contrib.auth that relies on them.  If you're using an app you didn't write (whether it's part of Django or not) then it's probably a bad idea to drop the database tables that app creates.


text:
Q: Is this an implementation of the promise pattern? I am writing a library in C++ (making use of many C++11 features) that (as far as I can tell) implements the promise pattern.
The library consists of a class that makes asynchronous network requests. When a user of this class invokes a method that issues a network request, an instance of another class (we'll call it the "promise class") is returned that provides methods for canceling the request.
Since this application uses the Qt framework, the promise class also emits signals when certain events happen, one of which is the successful completion of the request. Because the result of the network request is often included when the signal is emitted, I feel that this class implements the promise pattern.
According to the Wikipedia article:

"In computer science, future, promise, and delay refer to constructs used for synchronizing in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is yet incomplete."
* emphasis mine

Have I missed anything? Does my class indeed implement the promise pattern?

A: I think you have implemented it. Design patterns necessarily have somewhat generous definitions, as they need to work in a variety of application contexts.
Note: If your particular context is a homework problem and you are gathering evidence to challenge an unfavorable grade, well, that's between your and your professor. :) Out in industry, clean, functional code carries a lot more weight than compliance with narrow pattern definitions.


text:
Q: Configure SpecRun in TeamCity I have some specflow test and I have configured it to Run in Teamcity using NUnit Runner. But currently
I have a requiremenet to run all the test using SpecRun Runner in TeamCity.
I am quite clueless as how to configure to run test using specrunner in Teamcity as I didnt find a option
in the Runner dropdown in Teamcity to select SpecRun.
Can anyone please help me in giving some info on configuring specrun in Teamcity.
Thanks

A: I suspect that you will have to use a generic command line step in order to run SpecRun.exe to run the tests. As long as you use the command line switch /buildserver:teamcity then SpecRun should output the correct messages to allow integration with TeamCity so that it shows the tests as passed or failed.

A: Timothy, Teamcity Runner Dropdown does not provide a Specrun Option.
What can be done is write a .bat file to run runtests.cmd, i.e
"C:\Users\username\Documents\Visual Studio 2015\Projects\Blah_Blah_Project\Project_Name\runtests.cmd".
Now, save this .bat file in any C drive location. Select "Command Line" from TeamCity Dropdown, click on Advanced Option. Mention the Working Directory(path to .bat file) and Command Executable (name of the bat file).
I am assuming here, you have downloaded Specrun.Specflow plugin using nuget manager in Visual Studio and configured Default.srprofile file and successfully fired the specflow testcases from command line using runtests.cmd.


text:
Q: Thumbnail Upload Warning getimagesize() warning: Filename cannot be empty I want to add a auto-check thumbnail size function to my WordPress website, if the thumbnail size is less than 770px * 400px, it will not displayed on the top of the articles.
so I replace the original code:
<?php if( has_post_thumbnail() && ! has_post_format('video') && ! has_post_format('audio') && ! has_post_format('gallery') ) : ?>

with
<?php
$display_thumbnail = true;
$thumbnail_size = getimagesize( wp_get_attachment_url( get_post_thumbnail_id() ) );
if ($thumbnail_size[0] < 770 || $thumbnail_size[0] < 400) {
$display_thumbnail = false;
}
?>
<?php if( has_post_thumbnail() && ! has_post_format('video') && ! has_post_format('audio') && ! has_post_format('gallery') && $display_thumbnail ) : ?>

Then the error occur: under the original code, if I didn't upload an image, it will display nothing; but under the new code, if I didn't upload an image, it will show the warning
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty on...

Can someone tell me how to fix this issue?

A: try
<?php
if(has_post_thumbnail()) {
    $attachment_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
    $display_thumbnail = is_array($attachment_src)
                        && $attachment_src[1] >= 770
                        && $attachment_src[2] >= 400;
}
?>
<?php if( has_post_thumbnail() && ! has_post_format('video') && ! has_post_format('audio') && ! has_post_format('gallery') && $display_thumbnail ) : ?>

Edited: added 'full' argument to get the full size uploaded image.


text:
Q: Error compiling INET framework for omnet++ I am attempting to compile the most recent INET 3.3.0 on OMNeT++ 5.0. I am running Arch Linux Linux arch 4.5.4-1-ARCH #1 SMP PREEMPT Wed May 11 22:21:28 CEST 2016 x86_64 GNU/Linux.
Note that this worked for me on my laptop also running Arch Linux. On my desktop it fails however.
OMNeT++ is installed and works, I can run the example projects with no problems.
When I compile INET however, it always fails. I have tried letting the IDE do it all by itself by answering yes to its offer to install the latest INET. I have downloaded it myself, imported as a project, rightclicked and let it build project and I have resorted to going into the INET directory, issuing make makefiles, make MODE=release -j4, but it all leads to the following error:
inet/common/serializer/ipv4/IPv4Serializer.cc:410:129: note: in C++11     destructors default to noexcept
inet/common/serializer/sctp/SCTPSerializer.cc
inet/common/serializer/tcp/TCPSerializer.cc
inet/common/serializer/udp/UDPSerializer.cc
In file included from     inet/common/serializer/sctp/SCTPSerializer.cc:28:0:
./inet/common/serializer/sctp/headers/sctphdr.h:415:22: error:     flexible array member in union
         uint8_t info[];
                  ^

Previous versions of INET lead to different errors, none work. Does anyone have any idea?

A: you have just to modify the code in the sctphdr.h and make it
  uint8_t info [128];


text:
Q: Getting sums of multiple leveled relations efficiently I'm currently building an API and a web app for an internal warehouse system using NET Core.
I have the core entity structure, that goes like this:
"Material" has many "MaterialSubtypes" has many "MaterialClasses" has many "Packs".
Now, I need to create a list, representing a single sale. It can include lots of packs of different materials. The user should be able to add or remove packs to a sale as it is being prepared.
The problem is that I also need to show the user the list of all materials hierarchy that the sale contains, as well as the sum of "Quantity" field of all packs on each sublevel. This quantity is supposed to be updated dynamically in a client app.
What is the most efficient way to do this? Should I just add all packs to a sale, and then, on every GET request, Include everything and recalculate all sums via foreach loops? Or should I create separate entities for Material->MaterialSubtype->MaterialClass within the Sale and update them each time a Pack is added?
None of that seems optimal, but I can't think of anything else.

A: The answer depends on your use case.

*

*If you add many packs but read the sum far less frequently, it will probably be more efficient just to calculate the sum on every read.

*If you add few packs but read the sum very frequently, it will be more efficient to calculate the sum every time you add a pack.

If you're somewhere in the middle, either 1) profile it and then decide or 2) just do either and don't worry about it.


text:
Q: GetEntity from Generic DataRepository not working I am trying to create a generic repository with the basic CRUD operations. I am having trouble with my GetEntity function
protected override T GetEntity(FinancialDataContext entityContext, int id)
{
    var query = (from e in entityContext.Set<T>()
                 where e.Id == id
                 select e);
    var result = query.FirstOrDefault();
    return result;
}

The error is at my e."Id" and says "T does not contain a definition for 'Id' and no extension method 'Id' accepting a first argument of type 'T' could be found ( missing reference?)
How do I reference the 'promise' of an Id? or is there another way around this?

A: If you have some level of control on how your entities are declared, here is what you can do. Create a base class which declares the Id property:
public abstract class BaseEntity
{
    public in Id { get; set; }
}

Then make all your entities inherit this class (make sure to remove Id declaration from them as it is already in a base class):
public class Entity1 : BaseEntity

Now in your generic repository you can actually put some constraint on how it can be typed:
public class Repository<T> where T : BaseEntity

This is good on its own, but it also gives you access to Id (and whatever other common properties this BaseEntity might have).


text:
Q: How to find and replace unicode chars in Haskell? I have a unicode file containing a (Swedish) wikipedia article in MediaText markup. I want to clean it from all markup. In certain cases I want to extract text from the markup tags, such as the link titles from hyperlinks (like a simplified wikiextractor).
My approach is to run a set of regex'es over the file to remove markup. In the link-example, I need to replace [[link]] with link. I manage to fix this well with a regex as long as the text does not contain unicode chars such as ö.
Example of what I've tried:
ghci> :m +Data.Text
ghci> subRegex (mkRegex "\\[\\[([() a-zA-Z]*)\\]\\]") "Se mer om [[Stockholm]]" "\\1"
"Se mer om Stockholm"
ghci> subRegex (mkRegex "\\[\\[([() a-zA-Z]*)\\]\\]") "Se mer om [[Göteborg]]" "\\1"
"Se mer om [[G\246teborg]]"

Why does this not work? How can I make the regex engine realize that ö is indeed a normal letter (at least in Swedish)?
Edit:
The issue seems to not really sit in the pattern, but in the engine. If i allow all characters except q in the link text, one could expect ö to be allowed. But not so...
ghci> subRegex (mkRegex "\\[\\[([^q]*)\\]\\]") "[[Goteborg]]" "\\1"
"Goteborg"
ghci> subRegex (mkRegex "\\[\\[([^q]*)\\]\\]") "[[Göteborg]]" "\\1"
"[[G\246teborg]]"
ghci> subRegex (mkRegex "ö") "ö" "q"
"q"
ghci> subRegex (mkRegex "[ö]") "ö" "q"
"\246"

The problem seems to arise specifically when using character classes. It matches öfine on its own.

A: I've now decided to go with Text.Regex.PCRE.Heavy as suggested in this SO Answer written by the author. It solves my problem.
Thus, the solution becomes
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
Prelude> :m Text.Regex.PCRE.Heavy
Prelude Text.Regex.PCRE.Heavy> :set -XFlexibleContexts
Prelude Text.Regex.PCRE.Heavy> :set -XQuasiQuotes
Prelude Text.Regex.PCRE.Heavy> gsub [re|\[\[([^\]]*)\]\]|] (\(firstMatch:_) -> firstMatch :: String) "[[Göteborg]]" :: String
"G\246teborg"

Unfortunately I still don't know why the POSIX backend cannot handle this, but the PCRE backend can.

A: To find and replace unicode characters in Haskell we can use the streamEdit function, with Megaparsec parsers for the pattern matching (instead of regex). The Megaparsec letterChar parser will match all Swedish letters.
:set -XOverloadedStrings
import Text.Megaparsec
import Text.Megaparsec.Char
import Replace.Megaparsec
import Data.Text as T
import Data.Text.IO as T
import Data.Void

let wikilink :: Parsec Void T.Text [Char]
    wikilink = do
        _ <- chunk "[["
        fst <$> manyTill_ letterChar (chunk "]]")

T.putStr $ streamEdit wikilink T.pack "Se mer om [[Stockholm]]"
T.putStr $ streamEdit wikilink T.pack "Se mer om [[Göteborg]]"

Se mer om Stockholm
Se mer om Göteborg


text:
Q: How to deal with error of purtest on panel data I'm currently working with panel data and need to perform a stationarity test. Using The package plm I ran into the following error message:

Error in urca::punitroot(x, N = Inf, trend = punitroot.exo) :
  NAs are not allowed when na.rm=FALSE

I use panel data without missing values, as I approximated these values with the AMELIA II algorithm.
My code is the following:
STATIONARYTEST <- make.pbalanced(FINALDATA, balance.type = "shared.times")
BALANCED <- data.frame(split(STATIONARYTEST$v2x_pubcorr, STATIONARYTEST$country_name))

purtest(BALANCED, test = "madwu")

Unfortunately I cannot post the dput(FINALDATA) simply because it is too large of data frame.
What I can tell you is, that FINALDATA (a pdata.frame) is unbalanced, which is why is used the make.pbalanced command.
BALANCED looks as follows:
>dput(BALANCED)
structure(list(Albania = c(0.594, 0.606, 0.586, 0.559, 0.586,
0.586, 0.586, 0.442, 0.442, 0.442, 0.691, 0.691, 0.681, 0.681,
0.681, 0.611, 0.611, 0.611, 0.611), Austria = c(0.111, 0.111,
0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111,
0.111, 0.111, 0.111, 0.111, 0.047, 0.047, 0.047, 0.047), Belarus = c(0.424,
0.318, 0.318, 0.292, 0.292, 0.292, 0.292, 0.292, 0.292, 0.29,
0.29, 0.29, 0.29, 0.29, 0.29, 0.299, 0.299, 0.299, 0.292), Belgium = c(0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
0.03, 0.03, 0.03, 0.025, 0.025, 0.025, 0.025), Bosnia.and.Herzegovina = c(0.773,
0.773, 0.773, 0.773, 0.773, 0.773, 0.773, 0.773, 0.773, 0.773,
0.773, 0.773, 0.773, 0.773, 0.773, 0.79, 0.79, 0.788, 0.782),
    Bulgaria = c(0.45, 0.45, 0.45, 0.409, 0.409, 0.409, 0.409,
    0.409, 0.377, 0.361, 0.395, 0.587, 0.542, 0.542, 0.542, 0.471,
    0.471, 0.566, 0.566), Croatia = c(0.708, 0.708, 0.313, 0.313,
    0.313, 0.313, 0.54, 0.54, 0.54, 0.54, 0.54, 0.314, 0.317,
    0.317, 0.317, 0.277, 0.276, 0.274, 0.361), Czech.Republic = c(0.301,
    0.301, 0.301, 0.301, 0.301, 0.301, 0.301, 0.301, 0.301, 0.301,
    0.297, 0.302, 0.262, 0.262, 0.263, 0.248, 0.229, 0.227, 0.227
    ), Denmark = c(0.005, 0.005, 0.005, 0.005, 0.005, 0.005,
    0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005, 0.005,
    0.005, 0.005, 0.013, 0.013), Estonia = c(0.211, 0.151, 0.151,
    0.151, 0.151, 0.151, 0.105, 0.056, 0.056, 0.056, 0.055, 0.055,
    0.04, 0.04, 0.039, 0.041, 0.042, 0.04, 0.041), Finland = c(0.04,
    0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
    0.04, 0.04, 0.04, 0.04, 0.039, 0.04, 0.042, 0.041), France = c(0.072,
    0.072, 0.052, 0.052, 0.052, 0.052, 0.052, 0.052, 0.052, 0.052,
    0.052, 0.052, 0.054, 0.054, 0.054, 0.059, 0.059, 0.059, 0.059
    ), Germany = c(0.011, 0.011, 0.011, 0.011, 0.011, 0.011,
    0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.011, 0.012,
    0.017, 0.017, 0.031, 0.023), Greece = c(0.399, 0.399, 0.399,
    0.399, 0.399, 0.399, 0.399, 0.399, 0.399, 0.399, 0.399, 0.399,
    0.399, 0.376, 0.376, 0.258, 0.258, 0.258, 0.258), Hungary = c(0.156,
    0.162, 0.162, 0.162, 0.162, 0.168, 0.168, 0.168, 0.168, 0.168,
    0.168, 0.168, 0.189, 0.207, 0.207, 0.215, 0.215, 0.215, 0.215
    ), Iceland = c(0.018, 0.018, 0.018, 0.018, 0.018, 0.018,
    0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018, 0.018,
    0.02, 0.02, 0.02, 0.02), Ireland = c(0.05, 0.05, 0.05, 0.05,
    0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.046, 0.046,
    0.046, 0.056, 0.056, 0.056, 0.056), Italy = c(0.177, 0.177,
    0.203, 0.203, 0.203, 0.203, 0.203, 0.203, 0.189, 0.189, 0.2,
    0.2, 0.186, 0.186, 0.186, 0.217, 0.217, 0.217, 0.217), Latvia = c(0.208,
    0.194, 0.204, 0.204, 0.184, 0.163, 0.162, 0.171, 0.171, 0.161,
    0.144, 0.144, 0.129, 0.129, 0.125, 0.093, 0.093, 0.093, 0.19
    ), Lithuania = c(0.162, 0.162, 0.162, 0.138, 0.138, 0.138,
    0.138, 0.138, 0.138, 0.112, 0.112, 0.112, 0.112, 0.112, 0.112,
    0.119, 0.119, 0.119, 0.126), Luxembourg = c(0.054, 0.054,
    0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054,
    0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054, 0.054),
    Malta = c(0.118, 0.118, 0.118, 0.118, 0.118, 0.118, 0.118,
    0.118, 0.118, 0.118, 0.118, 0.118, 0.118, 0.118, 0.118, 0.118,
    0.118, 0.118, 0.118), Moldova = c(0.667, 0.667, 0.667, 0.651,
    0.662, 0.662, 0.662, 0.662, 0.662, 0.662, 0.662, 0.662, 0.559,
    0.559, 0.521, 0.611, 0.609, 0.683, 0.802), Montenegro = c(0.568,
    0.568, 0.568, 0.568, 0.568, 0.568, 0.568, 0.568, 0.568, 0.57,
    0.57, 0.57, 0.57, 0.57, 0.57, 0.561, 0.561, 0.561, 0.561),
    Netherlands = c(0.031, 0.031, 0.031, 0.031, 0.031, 0.031,
    0.031, 0.031, 0.031, 0.031, 0.031, 0.031, 0.031, 0.031, 0.031,
    0.031, 0.031, 0.028, 0.028), North.Macedonia = c(0.412, 0.412,
    0.412, 0.412, 0.412, 0.398, 0.398, 0.398, 0.398, 0.398, 0.418,
    0.418, 0.418, 0.459, 0.459, 0.508, 0.508, 0.508, 0.499),
    Norway = c(0.013, 0.013, 0.013, 0.013, 0.013, 0.013, 0.013,
    0.013, 0.013, 0.013, 0.014, 0.014, 0.014, 0.014, 0.014, 0.014,
    0.014, 0.013, 0.013), Poland = c(0.143, 0.143, 0.143, 0.143,
    0.143, 0.143, 0.143, 0.135, 0.128, 0.129, 0.139, 0.139, 0.139,
    0.139, 0.144, 0.147, 0.147, 0.119, 0.11), Portugal = c(0.12,
    0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12,
    0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.086, 0.125), Romania = c(0.833,
    0.833, 0.846, 0.799, 0.799, 0.799, 0.799, 0.799, 0.682, 0.667,
    0.667, 0.644, 0.644, 0.644, 0.628, 0.582, 0.51, 0.51, 0.522
    ), Russia = c(0.883, 0.883, 0.827, 0.827, 0.827, 0.827, 0.827,
    0.827, 0.827, 0.827, 0.827, 0.827, 0.827, 0.827, 0.828, 0.766,
    0.766, 0.766, 0.799), Serbia = c(0.853, 0.853, 0.882, 0.722,
    0.678, 0.678, 0.678, 0.678, 0.678, 0.678, 0.674, 0.674, 0.674,
    0.674, 0.674, 0.642, 0.602, 0.602, 0.676), Slovakia = c(0.316,
    0.261, 0.261, 0.261, 0.261, 0.261, 0.261, 0.261, 0.261, 0.261,
    0.261, 0.261, 0.253, 0.253, 0.262, 0.233, 0.233, 0.233, 0.233
    ), Slovenia = c(0.087, 0.087, 0.091, 0.091, 0.091, 0.084,
    0.084, 0.091, 0.091, 0.108, 0.108, 0.108, 0.108, 0.108, 0.108,
    0.105, 0.105, 0.105, 0.104), Spain = c(0.033, 0.033, 0.033,
    0.033, 0.033, 0.033, 0.033, 0.033, 0.033, 0.033, 0.033, 0.033,
    0.042, 0.042, 0.042, 0.045, 0.045, 0.031, 0.031), Sweden = c(0.009,
    0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009, 0.009,
    0.009, 0.009, 0.009, 0.009, 0.009, 0.011, 0.011, 0.018, 0.018
    ), Switzerland = c(0.032, 0.032, 0.032, 0.032, 0.032, 0.032,
    0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032,
    0.032, 0.032, 0.013, 0.013), Ukraine = c(0.921, 0.92, 0.854,
    0.856, 0.856, 0.877, 0.689, 0.682, 0.76, 0.729, 0.699, 0.761,
    0.792, 0.791, 0.792, 0.792, 0.72, 0.646, 0.61), United.Kingdom = c(0.032,
    0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032, 0.032,
    0.032, 0.032, 0.032, 0.032, 0.032, 0.035, 0.035, 0.035, 0.035
    ), na.rm = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
    TRUE)), class = "data.frame", row.names = c(NA, -19L))

Additional Information:
STATIONARYTEST$v2x_pubcorr is my main dependent variable of interest.
STATIONARYTEST$country_name is the cross sectional variable.
FURTHERMORE: In an attempt to see how the command behaves when I use a balanced data set (without using make.pbalanced command) I isolated the countries of Austria and Belgium. Using these two countries alone resulted in a balanced data set.
STATIONARYTEST222 <- FINALDATA %>% filter(country_name == "Belgium" | country_name == "Austria")
is.pbalanced(STATIONARYTEST222)
> TRUE

BALANCED <- data.frame(split(STATIONARYTEST222$v2x_pubcorr, STATIONARYTEST222$country_name))

When I tried to execute the last command I got the following error:

Error in (function (..., row.names = NULL, check.rows = FALSE,
  check.names = TRUE,  :    arguments imply differing number of rows: 0,
  67

> dput(STATIONARITYTEST222)
structure(list(country_name = structure(c(2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L), .Label = c("Albania", "Austria", "Belarus", "Belgium", "Bosnia and Herzegovina",
"Bulgaria", "Croatia", "Czech Republic", "Denmark", "Estonia",
"Finland", "France", "Germany", "Greece", "Hungary", "Iceland",
"Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta",
"Moldova", "Montenegro", "Netherlands", "North Macedonia", "Norway",
"Poland", "Portugal", "Romania", "Russia", "Serbia", "Slovakia",
"Slovenia", "Spain", "Sweden", "Switzerland", "Ukraine", "United Kingdom"
), class = "factor"), year = structure(c(1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L,
32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L,
45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L,
58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L,
18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L,
31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L,
44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L,
57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L), .Label = c("1950",
"1951", "1952", "1953", "1954", "1955", "1956", "1957", "1958",
"1959", "1960", "1961", "1962", "1963", "1964", "1965", "1966",
"1967", "1968", "1969", "1970", "1971", "1972", "1973", "1974",
"1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982",
"1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990",
"1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998",
"1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006",
"2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014",
"2015", "2016"), class = "factor"), country_id = c(144, 144,
144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144, 144,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
148, 148), v2elffelr = c(2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281, 2.281,
1.612, 2.24, 2.24, 2.187, 2.187, 2.187, 2.187, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404,
2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.404, 2.329, 2.329,
2.329, 2.329), v2elffelrbin = c(1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239, 1.239,
1.239, 1.239, 1.239, 1.239, 1.157, 1.157, 1.157, 1.157, -0.823,
-0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823,
-0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823,
-0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823,
-0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823,
-0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823, -0.823,
-0.823, -0.823, -0.823, -0.823, 1.105, -0.821, -0.821, -0.821,
1.128, -0.813, -0.813, -0.813, -0.813, 1.096, -0.913, -0.461,
-0.915, -0.915, -0.337, -0.914, -0.914, -0.472, -0.908, -0.351,
-0.965, -0.965), e_migdppc = c(4560, 4845, 5066, 5432, 5945,
6519, 7056, 7468, 7837, 8081, 8508, 9025, 9416, 9755, 10195,
10551, 11132, 11495, 12053, 12671, 13523, 14266, 15115, 15732,
16052, 16305, 16770, 17362, 17210, 17891, 18019, 17855, 18021,
18488, 18361, 18781, 19626, 20468, 21853, 23223, 24175, 25456,
26127, 26424, 27796, 28938, 29266, 31019, 32638, 33821, 35714,
34946, 35923, 35820, 36845, 37653, 39100, 40418, 40828, 40055,
40500, 41446, 43052, 43175, 44894, 44845, 45010, 6975, 7338,
7388, 7701, 8027, 8453, 8690, 8799, 8844, 9104, 9113, 9635, 10445,
10917, 11672, 12048, 12548, 13142, 13747, 14763, 15724, 16337,
17359, 18446, 18728, 18421, 19691, 19867, 20396, 21042, 22057,
20536, 20060, 19497, 19417, 18703, 19640, 20574, 22312, 23118,
23658, 24295, 25562, 25349, 26373, 27199, 26748, 28630, 29919,
31291, 33427, 33294, 34649, 34312, 34665, 35284, 35065, 35943,
36634, 37260, 38592, 38130, 38907, 39398, 39182, 39531, 39733
), v2x_pubcorr = c(0.076, 0.076, 0.076, 0.076, 0.049, 0.049,
0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.078,
0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.078,
0.078, 0.078, 0.078, 0.078, 0.078, 0.078, 0.158, 0.158, 0.158,
0.158, 0.158, 0.158, 0.158, 0.111, 0.111, 0.111, 0.111, 0.111,
0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111,
0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111, 0.111,
0.111, 0.111, 0.111, 0.047, 0.047, 0.047, 0.047, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03,
0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.025, 0.025, 0.025, 0.025
), v2xnp_client = c(0.344, 0.332, 0.325, 0.307, 0.304, 0.346,
0.299, 0.273, 0.273, 0.341, 0.378, 0.378, 0.373, 0.349, 0.349,
0.297, 0.263, 0.263, 0.263, 0.263, 0.289, 0.274, 0.203, 0.203,
0.202, 0.207, 0.225, 0.225, 0.225, 0.21, 0.192, 0.163, 0.163,
0.173, 0.187, 0.187, 0.15, 0.147, 0.147, 0.147, 0.152, 0.179,
0.148, 0.134, 0.138, 0.153, 0.093, 0.07, 0.068, 0.074, 0.095,
0.095, 0.092, 0.069, 0.077, 0.081, 0.078, 0.064, 0.063, 0.062,
0.057, 0.059, 0.059, 0.064, 0.062, 0.095, 0.088, 0.195, 0.202,
0.202, 0.202, 0.172, 0.16, 0.16, 0.16, 0.168, 0.173, 0.153, 0.173,
0.179, 0.179, 0.179, 0.152, 0.135, 0.135, 0.148, 0.152, 0.152,
0.149, 0.131, 0.131, 0.147, 0.151, 0.151, 0.14, 0.136, 0.121,
0.137, 0.139, 0.151, 0.151, 0.151, 0.152, 0.086, 0.087, 0.114,
0.114, 0.114, 0.108, 0.055, 0.055, 0.055, 0.068, 0.073, 0.073,
0.073, 0.063, 0.054, 0.054, 0.054, 0.053, 0.053, 0.053, 0.053,
0.044, 0.036, 0.034, 0.034, 0.033, 0.041, 0.037, 0.036, 0.035,
0.035), e_total_fuel_income_pc = c(53.63, 65.12, 71.28, 85.26,
89.59, 95.07, 94.4, 90.18, 82.48, 75.49, 71.19, 66.02, 66.03,
45.85, 67.08, 66.3, 63.19, 59.55, 53.1, 49.94, 51.7, 57.15, 57.94,
69.03, 161.46, 145.03, 140.7, 146.03, 144.94, 220.9, 201, 161.78,
151.65, 129.92, 118.6, 109.27, 71.69, 71.54, 62.25, 63.51, 73.43,
64.89, 59.23, 55.3, 46.73, 43.44, 50.01, 47.48, 38.7, 47.73,
72.39, 65.97, 58.13, 81.32, 84.8, 106.72, 110.09, 3679.89855133674,
8185.62755709757, 4652.91030179564, 7086.47857954613, 6763.0077814627,
3839.20809400641, 7344.36553794882, 7180.27833621883, 4857.87269571732,
4733.90176929056, 148.06, 150.99, 149.66, 146.94, 129.7, 131.81,
136.29, 135.26, 117.03, 95.53, 91.03, 83.67, 79.36, 76.78, 75.83,
68.57, 59.84, 55.3, 48.35, 43.61, 45.03, 47.45, 47.89, 42.52,
65.21, 68.68, 64, 61.82, 60, 54.02, 52.54, 49.74, 50.96, 44.67,
42.79, 41.96, 34.32, 25.32, 15.59, 9.43, 3.19, 1.13, 0.05, 0.04,
0.01, 0, 0.02, 0, 0, 0, 0.03, 0, 0, 0, 0, 0, 0, 1911.7747504759,
-1199.38536156022, 1411.03507725042, 891.666005834158, 373.197200461489,
2173.00097561386, 2747.12988859581, -27.9550493962888, 1754.64945758216,
4520.91449062753), v2elfrfair = c(1.40132792033515, 1.679, 0.541049141075401,
1.659, 1.60773056697027, 2.8258795416579, 1.664, 1.664, 2.41927270152404,
1.737, 1.71067576513315, 1.61268794176647, 1.668, 1.668, 2.04097689835134,
1.677, 1.677, 1.20718430716776, 0.493204265346457, 2.09457456857527,
1.631, 1.674, 0.377462635065878, 2.13319630561236, 1.712, 1.715,
1.66212044961192, 1.47203087375343, 1.84302996311272, 1.692,
1.684, 2.40176273182624, 1.76907579063065, 1.692, 2.29454682806757,
1.14771611990067, 1.667, 1.73551010714927, 0.365263591522678,
1.17970893416492, 1.666, 2.51327076346352, 1.672, 1.58598030071915,
1.705, 1.703, 2.37540965999566, 2.25362095360046, 1.644, 1.653,
0.376495098917595, 1.82065149356349, 1.645, 1.93587143874116,
1.66, 2.40439785003682, 1.907, 1.28214464690115, 1.891, 2.06539931190712,
1.874, 1.65663063170703, 1.66208239440504, 1.882, 2.40976724048327,
1.17051141409222, 1.038, 1.817, 2.48706887310882, 2.97990251044591,
1.92482550102507, 1.829, 1.25286195347918, 1.95302302093176,
1.68042812924957, 1.831, 1.89041661507571, 1.16215892247556,
1.817, 2.18979828209219, 2.88972026358515, 2.61820894432001,
1.82, 1.07273773829965, 0.935363024284767, 1.826, 2.1705206292172,
1.89259383034004, 1.862, 1.77542675299113, 1.95823662958056,
1.814, 1.7712287688162, 1.73589815811926, 1.876, 1.876, 2.74022402681816,
2.00132073910227, 1.805, 1.26907258714646, 2.21011519378473,
1.38254077621057, 1.858, 2.56569886000421, 1.852, 1.54799194277065,
1.35332732418557, 2.20864519677777, 1.785, 2.34650687424493,
1.77353325866748, 3.13950482610678, 1.827, 2.55173735229479,
1.90836027680683, 2.05224931822916, 1.836, 2.3599183465524, 2.27012267487134,
2.77699381804334, 1.825, 2.71359722355756, 2.00088726810414,
2.10951173384588, 2.145, 2.60046614539633, 2.62040183409194,
2.186, 2.36306647393869, 2.46423986463719, 2.31772202617049,
2.133, 1.64062311419701, 2.92901421425319), e_miurbani = c(0.358,
0.358, 0.359, 0.359, 0.359, 0.36, 0.36, 0.36, 0.361, 0.361, 0.361,
0.36, 0.359, 0.358, 0.356, 0.355, 0.354, 0.353, 0.352, 0.351,
0.349, 0.35, 0.35, 0.351, 0.351, 0.352, 0.352, 0.353, 0.353,
0.354, 0.354, 0.354, 0.354, 0.354, 0.354, 0.354, 0.354, 0.354,
0.354, 0.354, 0.354, 0.353, 0.352, 0.351, 0.351, 0.35, 0.349,
0.348, 0.347, 0.346, 0.345, 0.625104104430152, 0.589183642300823,
0.36174005549091, 0.734486489201076, 0.367615560442693, 0.292709220149293,
0.597384210534355, 0.285554798083621, 0.414711015952627, 0.657507598229605,
0.119745577612342, 0.43489643233861, 0.259398811624056, 0.293541234504069,
0.0284031870313866, -0.0804629746576592, 0.256, 0.257, 0.258,
0.26, 0.261, 0.262, 0.263, 0.264, 0.265, 0.266, 0.268, 0.269,
0.27, 0.27, 0.271, 0.272, 0.273, 0.274, 0.275, 0.276, 0.277,
0.279, 0.28, 0.282, 0.284, 0.286, 0.287, 0.289, 0.291, 0.293,
0.294, 0.296, 0.298, 0.3, 0.302, 0.304, 0.306, 0.308, 0.31, 0.312,
0.314, 0.315, 0.316, 0.318, 0.319, 0.32, 0.322, 0.323, 0.324,
0.326, 0.327, 0.411135722414429, 0.673550869261708, 0.373587901979434,
0.750520482216727, 0.638336666054789, 0.516649360481536, 0.406651564692971,
0.780544843654102, 0.859511524190551, 0.67568530495162, 0.284587641481792,
0.552833092208023, 0.534306603141291, 0.619534615117042, 0.572040557257485,
0.666466866573874), v2x_horacc = c(0.851, 0.856, 0.844, 0.856,
0.853, 0.843, 0.803, 0.805, 0.791, 0.778, 0.796, 0.799, 0.791,
0.805, 0.795, 0.798, 0.851, 0.889, 0.887, 0.873, 0.882, 0.892,
0.881, 0.999, 0.982, 0.985, 1.018, 1.023, 1.015, 1.034, 1.023,
1.19, 1.186, 1.196, 1.179, 1.194, 1.201, 1.415, 1.406, 1.412,
1.327, 1.318, 1.326, 1.317, 1.326, 1.315, 1.329, 1.328, 1.314,
1.329, 1.404, 1.399, 1.406, 1.407, 1.411, 1.419, 1.41, 1.525,
1.512, 1.521, 1.525, 1.514, 1.517, 1.505, 1.498, 1.495, 1.551,
1.256, 1.25, 1.259, 1.258, 1.257, 1.255, 1.258, 1.261, 1.27,
1.269, 1.27, 1.267, 1.271, 1.261, 1.274, 1.264, 1.263, 1.266,
1.275, 1.257, 1.261, 1.258, 1.262, 1.254, 1.259, 1.264, 1.245,
1.258, 1.271, 1.272, 1.27, 1.282, 1.268, 1.288, 1.289, 1.282,
1.28, 1.276, 1.286, 1.24, 1.398, 1.394, 1.439, 1.441, 1.446,
1.445, 1.551, 1.539, 1.543, 1.606, 1.622, 1.606, 1.62, 1.614,
1.603, 1.625, 1.616, 1.682, 1.613, 1.647, 1.61, 1.609, 1.61,
1.693, 1.689, 1.689, 1.684), v2x_gencs = c(0.541, 0.541, 0.541,
0.541, 0.541, 0.541, 0.572, 0.572, 0.572, 0.572, 0.572, 0.631,
0.631, 0.631, 0.631, 0.631, 0.609, 0.609, 0.609, 0.609, 0.609,
0.609, 0.659, 0.659, 0.659, 0.659, 0.705, 0.705, 0.705, 0.705,
0.801, 0.801, 0.801, 0.801, 0.801, 0.801, 0.869, 0.889, 0.889,
0.889, 0.889, 0.889, 0.889, 0.889, 0.889, 0.889, 0.893, 0.871,
0.898, 0.898, 0.898, 0.898, 0.898, 0.898, 0.898, 0.898, 0.886,
0.884, 0.884, 0.884, 0.914, 0.914, 0.914, 0.894, 0.894, 0.894,
0.894, 0.507, 0.507, 0.507, 0.507, 0.507, 0.507, 0.507, 0.507,
0.507, 0.507, 0.535, 0.535, 0.535, 0.535, 0.535, 0.535, 0.535,
0.535, 0.535, 0.535, 0.591, 0.629, 0.629, 0.629, 0.629, 0.629,
0.626, 0.626, 0.626, 0.626, 0.61, 0.61, 0.702, 0.702, 0.702,
0.702, 0.708, 0.708, 0.708, 0.708, 0.853, 0.853, 0.853, 0.853,
0.853, 0.853, 0.853, 0.853, 0.853, 0.853, 0.882, 0.882, 0.882,
0.882, 0.882, 0.882, 0.882, 0.882, 0.881, 0.881, 0.859, 0.882,
0.882, 0.875, 0.884, 0.896, 0.875), v2x_corr = c(0.062, 0.062,
0.062, 0.062, 0.054, 0.054, 0.068, 0.068, 0.068, 0.068, 0.068,
0.068, 0.068, 0.068, 0.068, 0.068, 0.068, 0.068, 0.068, 0.068,
0.067, 0.067, 0.067, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08, 0.08,
0.105, 0.105, 0.105, 0.105, 0.105, 0.105, 0.105, 0.094, 0.094,
0.094, 0.094, 0.094, 0.094, 0.094, 0.094, 0.094, 0.094, 0.094,
0.094, 0.094, 0.104, 0.12, 0.12, 0.104, 0.124, 0.124, 0.109,
0.086, 0.086, 0.086, 0.086, 0.091, 0.085, 0.048, 0.048, 0.048,
0.048, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041,
0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041,
0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041, 0.041,
0.041, 0.042, 0.042, 0.042, 0.042, 0.042, 0.042, 0.042, 0.042,
0.042, 0.042, 0.042, 0.042, 0.042, 0.05, 0.05, 0.05, 0.05, 0.05,
0.05, 0.05, 0.028, 0.028, 0.028, 0.028, 0.028, 0.028, 0.028,
0.028, 0.028, 0.028, 0.028, 0.028, 0.028, 0.028, 0.028, 0.028,
0.025, 0.025, 0.025, 0.025), v2elsnlsff = c(0.814, 0.814, 0.814,
0.814, 0.814, 0.814, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921,
1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921,
1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921,
1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921,
1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921,
1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.921,
1.921, 1.921, 1.921, 1.921, 1.921, 1.921, 1.908, 1.908, 1.908,
1.908, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713,
1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713,
1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713, 1.713,
1.713, 1.713, 1.713, 1.713, 1.976, 1.976, 1.976, 1.976, 1.976,
1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976,
1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976,
1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976, 1.976,
1.976, 1.906, 1.906, 1.888, 1.841), v2pssunpar = c(1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704,
1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 1.704, 2.1, 2.1, 2.1,
2.1, 0.733, 0.733, 0.733, 0.733, 0.733, 1.418, 2.111, 2.111,
2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111,
2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111,
2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111,
2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111,
2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111,
2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111, 2.111,
2.111, 2.161, 2.161, 2.091, 2.091), v2clrgunev = c(0.635, 0.635,
0.635, 0.635, 0.635, 0.635, 1.206, 1.206, 1.206, 1.206, 1.206,
1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206,
1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206,
1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 1.206, 2.088,
2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088,
2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088,
2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.088, 2.216, 2.216,
2.216, 2.216, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52,
2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52,
2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52,
2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52,
2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52,
2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52, 2.52,
2.52, 2.52, 2.52, 2.52), v2clsnlpct = c(12.5, 12.5, 12.5, 12.5,
12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5,
12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 3.333, 3.333, 3.333, 3.333,
3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333,
3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333,
3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333,
3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333, 3.333,
3.333, 3.333, 50, 50, 50, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), continent = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), .Label = "Europe", class = "factor"), CountryShortcut = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L), .Label = c("ALB", "AUT", "BEL", "BGR", "BIH",
"BLR", "CHE", "CZE", "DEU", "DNK", "ESP", "EST", "FIN", "FRA",
"GBR", "GRC", "HRV", "HUN", "IRL", "ISL", "ITA", "LTU", "LUX",
"LVA", "MDA", "MKD", "MLT", "MNE", "NLD", "NOR", "POL", "PRT",
"ROU", "RUS", "SRB", "SVK", "SVN", "SWE", "UKR"), class = "factor"),
    POSTCOM = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0)), row.names = c(NA, -134L), class = "data.frame")


text:
Q: Prevent remounting of layout component if react router params stay the same I have a layout component which renders an image of quite a large size. This layout component is shared between two other components, Map and Explore. When the route changes, it renders either the Map or the Explore component, with the layout component wrapped around it.
A user gets to Map or Explore via the home page. So the link to the page could be '.../map/123' or '.../explore/456'. When switching between map and explore once the user is in the map or explore component, the url params remain the same always. So '.../map/123' or '.../explore/123'
On each route change, the layout component and the map/explore component is re-rendered. The problem is that the large image on the layout component is then re-fetched.
How should I structure the app so I can swtich from Map and Explore without having to refetch the large image?
I have the code in this sandbox...

//index.js
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter as Router, Route, NavLink } from "react-router-dom";

import "./styles.css";

import Map from "./Map";
import Explore from "./Explore";

const Links = props => {
  return (

      <NavLink exact to="/">
        Home
      </NavLink>
      <NavLink style={{ paddingLeft: "5px" }} to="/map/1">
        Map
      </NavLink>
      <NavLink style={{ paddingLeft: "5px" }} to="/explore/1">
        Explore
      </NavLink>

  );
};

function App() {
  return (
    <Router>

        <Links />
        <Route exact path="/" render={() =>
Home
} />
        <Route path="/map/:id" render={({ match }) => <Map match={match} />} />
        <Route
          path="/explore/:id"
          render={({ match }) => <Explore match={match} />}
        />

    </Router>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

//layout MapExploreContainer.js
import React, { Component } from "react";

class MapExploreContainer extends Component {
  state = { imgUrl: null };

  componentDidMount() {
    this.timeout = setTimeout(() => {
      this.setState({
        imgUrl:
          "https://images.unsplash.com/photo-1550396011-0d98206d5b92?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&fit=max&ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
      });
    }, 2000);
  }

  componentWillUnmount() {
    clearInterval(this.timeout);
  }

  render() {
    console.log("hi: ", this.props.match);
    return (

        {this.props.children}

    );
  }
}

export default MapExploreContainer;

//Map.js
import React, { Component } from "react";
import MapExploreContainter from "./MapExploreContainer";

class Map extends Component {
  render() {
    return (
      <MapExploreContainter match={this.props.match}>

Map

      </MapExploreContainter>
    );
  }
}

export default Map;

//Explore.js
import React, { Component } from "react";
import MapExploreContainter from "./MapExploreContainer";

class Explore extends Component {
  render() {
    return (
      <MapExploreContainter match={this.props.match}>

Explore

      </MapExploreContainter>
    );
  }
}

export default Explore;

A: I think the problem here is that Explore and Map each get their own instance of MapExploreContainer which is unmounted when each of those components is unmounted.
You can try something like the following:
Remove all references to MapExploreContainter from Map and Explore
Change your routes to:
function App() {
  return (
    <Router>

        <Links />
        <Route exact path="/" render={() =>
Home
} />
        <Route path="/(map|explore)/:id" component={MapExploreContainter} />
        <Route path="/map/:id" render={({ match }) => <Map match={match} />} />
        <Route
          path="/explore/:id"
          render={({ match }) => <Explore match={match} />}
        />

    </Router>
  );
}

This way the rendered MapExploreContainer is always the same instance whenever you're at either map/123 or explore/123.
Updated sandbox: https://codesandbox.io/s/14xj47667j


text:
Q: How can I replace a plus sign in JavaScript? I need to make a replace of a plus sign in a javascript string. there might be multiple occurrence of the plus sign so I did this up until now:
myString= myString.replace(/+/g, "");#

This is however breaking up my javascript and causing glitches. How do you escape a '+' sign in a regular expression?

A: myString = myString.replace(/\+/g, "");

A: I prefer this:
myString.replace(/[+]/g, '').

A: you should escape your + sign, \+

A: You need to escape the + as its a meta char as follows:
myString= myString.replace(/\+/g, "");

Once escaped, + will be treated literally and not as a meta char.

A: myString.replace(/\+/g, "");


text:
Q: Internal Server Error, status=500 - getHibernateTemplate().delete(entity) In my Springboot application , when calling deleteoneXTwo() I get
There was an unexpected error (type=Internal Server Error, status=500). Removing a detached instance .....entities OneXTwo#1
Below is my code -
@Repository
public class OneXTwoDaoImpl extends HibernateDaoSupport implements OneXTwoDao {

    public OneXTwoDaoImpl(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    @Transactional
    public void deleteoneXTwo() {
        getHibernateTemplate().setCheckWriteOperations(false);
        OneXTwo oneXTwo = (OneXTwo) getHibernateTemplate().get(OneXTwo.class, 1);
        getHibernateTemplate().delete(oneXTwo);
    }
}

-
@SpringBootApplication
@EnableJpaRepositories(basePackages = {"ro"})
@EntityScan(basePackages = {"ro"})
@ComponentScan(basePackages = {"ro"})
public class BoostrapModules {
    public static void main(String[] args) {
        SpringApplication.run(BoostrapModules.class);
    }

            /*
            USE FOR SESSION FACTORY
             */
                @Autowired
                private EntityManagerFactory entityManagerFactory;

                @Bean
                public SessionFactory getSessionFactory() {
                    if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
                        throw new NullPointerException("factory is not a hibernate factory");
                    }
                    return entityManagerFactory.unwrap(SessionFactory.class);
                }
}


text:
Q: Sum column in addtion to display its unique value Wondering if you can help me with this one.
We have a table called Part_Locations. This table contains a list of Part_ID, Location ID, and QTY.
I created a Parts By Location report that works great but now the user wants to know what is the total on hand for that part is.
I tried:
SELECT part_id,qty, SUM(qty)
FROM part_location
GROUP BY part_id

But that returns:
Msg 8120, Level 16, State 1, Line 1
Column 'part_location.QTY' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.

When I try:
SELECT part_id, SUM(qty)
FROM part_location
GROUP BY part_id

I get QTY to sum but then I lose visibility on how many part is at each location.
What I am trying to achieve:

A: You can add this window function to select part of your query
SUM(qty) OVER(PARTITION BY part_id) SumQty

like this;
SELECT
  part_id,
  qty,
  SUM(qty) OVER(PARTITION BY part_id) SumQty
FROM part_location

A: You don't want an aggregation query.  You want to use a window function:
SELECT part_id, qty, SUM(qty) OVER (PARTITION BY part_id)
FROM part_location ;

A: I think the main conceptual issue with this query is that you're mixing qty and SUM(qty) in the returned result set. Remove qty and you should be fine

A: try like this:
SELECT
pl.part_id,
pl.qty,
(SELECT SUM(p.qty) FROM part_location p WHERE p.part_id = pl.part_id)
FROM part_location pl


text:
Q: Is Couchapp a realistic substitution for a web framework? Assuming you're going to use couchdb, is it realistic to try to just use couchapp in place of django, rails, or asp.net mvc?  What would be the benefits and drawbacks?

A: Yes, normally a CouchApp would use AJAX for the whole application, though that's not a requirement. It's possible to create a CouchApp that will provide a fallback and render the core content for browsers without JS (and search engines).
This is normally a little complicated and involes writing your rendering functions twice. Once in the design doc as a show or list function, then again for your client-side code. However, I've been working on a CouchApp framework called Kanso, which allows you to write code once and have it run on the client-side when possible and fall-back to CouchDB when that's not.
Another problem I've found with CouchApps is that the validation and permissions code can get very complicated quickly with a bigger app. So Kanso also provides Type definitions similar to other Model systems you might have used in Django or Rails.
Just to be clear: You will not achieve the same experience for browsers without JS, but what you can do is render the basic content of the page and then progressively enhance it with JavaScript.
This is what Kanso was designed for :)

A: As it stands, a CouchApp essentially require you to use AJAX for the entire application. Generally speaking, that's poor for user experience, as you are downloading the skeleton markup, running JS, usually hitting the server again, and then adding more markup dynamically. (as opposed to just downloading the finished markup up front) In addition, caching data is a different beast on the browser than it is on a server. Also, SEO is much more difficult when you have AJAX-only content.
Basically, all of the reasons you see people going against AJAX-only (ie. obtrusive JavaScript) web applications, will all hold up in this context.
On the other hand, you would be able to replicate the entire application (as well as all the relevent data) to any node that is running CouchDB. I could see mobile versions of your application running only the CouchApp while offline, since a full web server stack wouldn't necessarily be available to you. In addition, it's easy to get up and running with a CouchApp, as opposed to learning a framework like Rails, Django or Express.js.
I have high-hopes for CouchApps becoming a complete web application solution eventually, as I am a huge fan of CouchDB as a database. However, right now it just isn't feasible for me because of the heavy reliance upon obtrusive JavaScript.


text:
Q: How to generate a table in Angular6?

public class TimeSheet
    {
        public int Id { get; set; }
        public int EmployeeID { get; set; }
        public int TaskID { get; set; }
        public WeekDays DayOfWeek { get; set; }
        public int Hours { get; set; }
    }

 public class Days
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Hours { get; set; }
    }

    public class DailyTask: Task
    {
        public List<Days> HoursPerDay { get; set; }
    }

I have a problem in binding data with table rows and columns, lets say we build a simple timesheet application in which we have Task and working hours for every task log in daily basis. For example
Task1 -> Log 2 hours on Monday and Tuesday
Task2 -> Log 5 hours on Friday
I have made some code but unable to bind columns with task, I have a table. How would I implement this in Angular6?
For json data please check attached image

 0">

        Tasks

        {{ day.name }}

         {{t.dailyTask |json }}
            <select (change)="selectTask($event.target.value)" >
                <option *ngFor="let task of time.tasks; let x=index" value={{task.id}}>
                    {{task.name}}
                </option>
            </select>

         {{ day.hours }}

                <input type="number" [(ngModel)] = "time.days[t].hours">

A: You need to create every day of week data array from server side. set 0 as a default value to hours. You'll get unexpected output if array is not valid as per the your requirement.
Please have a look on this demo URL
eg.
    [{
      "employeeID": 1,
      "taskID":2,
      "hoursPerDay":[{
            "id":6,
            "name":"Monday",
            "hours":5
        },{
            "id":7,
            "name":"Tuesday",
            "hours":4
        },{
            "id":0,
            "name":"Wednesday",
            "hours":0
        },{
            "id":0,
            "name":"Thursday",
            "hours":0
        },{
            "id":0,
            "name":"Friday",
            "hours":0
        },{
            "id":0,
            "name":"Saturday",
            "hours":0
        },{
            "id":0,
            "name":"Sunday",
            "hours":0
        }]
    },
    ...
]


text:
Q: Print path to base in template override I am doing a template override with my template.php, and I need to print the path to the base of my site.
Currently I have this:
$output = '
My Basket
' . '
' . $item_count . '
';

The link created is:
My Basket

I understand why this is happening and why this link doesn't work.
If I was adding code to a tpl file, I would use PHP to print the path to the base of my site first. However using the same code in my template.php doesn't work; the code is shown as text on the page.
How can I get around this? Am I trying to do it in the right way?
NOTE - The code $item_count works fine as it is, but when I tried to use it to add a class to a div it also just printed the text: '' . $item_count . ''.
This makes me wonder if I am using the correct code for the base path, but applying it wrongly.

A: You need to use drupal's link function l(). Check this page for the url's options available.
So, your link should be
$output = l('My Basket', 'cart');

If you use that for your links, Drupal will handle the base path for you.


text:
Q: Formatting DateTime in Excel XML worksheet When generating an Excel XML workbook with ASP.NET i'm appending 3 cells in a row like:
sb.Append(String.Format(
"<Cell><Data ss:Type=\"DateTime\">{1}</Data></Cell>{0}",
Environment.NewLine,
item.DateAvailable.ToString("yyyy-MM-ddTHH:mm:ss.fffffffK")
)); // newlines added for readability;

item.DateAvailable is a C# DateTime that has to end in Excel as An cell-DateTime.
so
value from debug in VS2010 in asssembly:
 2011-08-15T01:16:06.8470000

value in excel:
 40761,2299142361

after manual conversion of the cell formatting:
 6-08-11 5:31

However, when converting it outputs in excel as a number, and the cell formatting is set to custom. When I manually change the cell formatting back to DateTime the correct??? date is shown in the correct format. But of course, the business would not accept such a raw data they have to convert themselves ;)
Perhaps I am using the wrong StringFormat?
What is the correct format to write a DateTime in this case and output it in Excel in the correct DateTime Format?

A: Yes, you are using a "wrong" string format, i.e. a format that Excel does not automatically recognize (or parse appropriately) as a date. Drop the T. Also, the date-time format in Excel rounds at least to milliseconds, if not to integer seconds, so you might as well drop some of those decimal places.
This should work:
item.DateAvailable.ToString("yyyy-MM-dd HH:mm:ss.ffff")


text:
Q: Receiving data from Android in a ASP.NET web site I wrote an Android app that sends data to an ASP.NET web site. When I test the app, I get the error:

Connection to https://localhost:1863 refused.

How do I solve this problem? Also, how do I go about storing this data into SQL Server?
HttpClient client1 = new DefaultHttpClient();

HttpPost request = new HttpPost("http://localhost:1863");

String lat = "lat",lng = "lng";

List<NameValuePair> postParameters = new ArrayList<NameValuePair>(3);
postParameters.add(new BasicNameValuePair("lat", lat));
postParameters.add(new BasicNameValuePair("lng", lng));
try {
    request.setEntity(new UrlEncodedFormEntity(postParameters));
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
    request.setEntity(formEntity);
    // request.addHeader("Content-type", "application/x-www-form-urlencoded");
    HttpResponse response;
    response = client1.execute(request);
    BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    String line;
    String page = "";
    line = in.readLine();
    while (line != null)
    {
        page = page + line;
        line = in.readLine();
    }
}
catch (ClientProtocolException e) {
    e.printStackTrace();} catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

A: You need to get the IP address of your server, rather than using localhost, since localhost is local to the calling computer, so the localhost for the Android is different than for the IIS server.
UPDATE:
Just use IP address 10.0.2.2, as explained in Stack Overflow question How to connect to my http://localhost web server from Android Emulator in Eclipse.

A: I made an ASP.NET handler page (.ashx), named it Handler, and replaced "http://localhost:1863"with"http://localhost:1863/Handler.ashx" and it solved the problem.


text:
Q: SQL intersect two timestamp pairs and group up by hours I have A little problem.
I have A table lets call it "events" with columns like: type, (1 or 0) , timestamp start , timestamp end.
I want to group them by hours (60 minutes periods)
Into 4 columns each calculating

*

*How many minutes per hour there was no either type 1 or type 0 event.

*How many minutes per hour there was an event type 1 and in the same time there was not event of type 2.

*How many minutes per hour there was an event type 2 and in the same time there was no event of type 1

*How many minutes per hour there was an event 2 and event 1 at the same time.
Result should look like this:
hour 00 10 01 11
12  10 20 20 10
13   5 15 25  15
Each row should always sum to 60 minutes.
Is it possible to do it in SQL? I need it in vertica so I can use verticas functions too.

A: Interesting Question!  Here is a query which gets you what you need.  I mocked up the following table and some dummy data, and then showed the results from the query at the end.  As you required - the totals always add up to 60 minutes within each hour.
SETUP:
create table public.time_event_test(event_timestamp timestamptz, event_type int);

insert into public.time_event_test(event_timestamp,event_type) select getutcdate() as event_timestamp, 1 as event_type;
insert into public.time_event_test(event_timestamp,event_type) select TIMESTAMPADD('minute',5,getutcdate()) as event_timestamp, 1 as event_type;
insert into public.time_event_test(event_timestamp,event_type) select TIMESTAMPADD('minute',1,getutcdate()) as event_timestamp, 1 as event_type;
insert into public.time_event_test(event_timestamp,event_type) select TIMESTAMPADD('minute',1,getutcdate()) as event_timestamp, 2 as event_type;
insert into public.time_event_test(event_timestamp,event_type) select TIMESTAMPADD('minute',3,getutcdate()) as event_timestamp, 2 as event_type;
insert into public.time_event_test(event_timestamp,event_type) select TIMESTAMPADD('minute',6,getutcdate()) as event_timestamp, 2 as event_type;
insert into public.time_event_test(event_timestamp,event_type) select TIMESTAMPADD('minute',90,getutcdate()) as event_timestamp, 2 as event_type;

QUERY:
select date_trunc('hour',dat) as hr
, 60 - sum(case when event_type1 = 1 or event_type2 = 1 then 1 else 0 end) as type_00
, sum(case when event_type1 = 0 and event_type2 = 1 then 1 else 0 end) as type_01
, sum(case when event_type1 = 1 and event_type2 = 0 then 1 else 0 end) as type_10
, sum(case when event_type1 = 1 and event_type2 = 1 then 1 else 0 end) as type_11
from (
select date_trunc('minute',event_timestamp) as dat
, max(case when event_type = 1 then 1 else 0 end) as event_type1
, max(case when event_type = 2 then 1 else 0 end) as event_type2
from public.time_event_test
group by 1
) x
group by 1 order by 1;

RESULTS:
           hr           | type_00 | type_01 | type_10 | type_11
------------------------+---------+---------+---------+---------
 2016-12-21 01:00:00+00 |      52 |       3 |       2 |       3
 2016-12-21 02:00:00+00 |      59 |       1 |       0 |       0


text:
Q: Displaying menus under Wordpress twentysixteen theme I have a Wordpress installation-in-progress at http://dev.cjshayward.com. I have done a few things to get a main menu to display under a lightly edited child theme to the twentysixteen theme, but so far there is no menu displaying at the top.
What do I need to get a menubar with a few top-level menus to appear?


text:
Q: Why can't I set the system clock on my Dell Latitude C510? Whenever I open Chromium and visit any website, Chromium thinks that the certificate isn't valid yet. I know that's because of the system clock, and when I try to change the system clock nothing happens. The BIOS also gives me a warning on boot saying the system clock has not been set and setting it also does nothing. I would like to fix it.

A: You will likley need to replace the CMOS battery.The C510 service manual can be downloaded.  Battery is likley fairly inexpensive so worth trying.


text:
Q: iOS 6 - When to instantiate (create an object of the class) and when not to? I am trying to understand the instantiation process better.  I understand that some classes need to be allocated and initialized (I have to create an object of the class) before I can use them, such as NSMutableArray.  However, I am running into classes that I do not need to instantiate before I use them, such as NSDate and UIImage.
For example, I have always been instantiating NSMutableArray like this before I can use it:
NSMutableArray *myArray = [[NSMutableArray alloc]init];

With UIImage I can just skip instantiation and just do this:
UIImage *i = [UIImage imageNamed:@"image.png"];

Are there any rules or tell-a-signs for when I can just use a class without instantiating and when I have to instantiate?  I'm trying to see if there is a quick way of knowing this.
Thanks!

A: In general, my own rule of thumb is if the object is only going live within that method and not be used outside the scope of that method, I'll use a creation API for an object thats autoreleased before I instantiate a new object.
But, if you need to access the object anywhere else outside of the scope of the method, you must instantiate it and have the memory retained and stick around.
In your example above, if you're taking "UIImage * i" and dropping it into an image view or doing something with it only within a single method, then "imageNamed" is perfectly appropriate.
If you need to keep "UIImage * i" around for anything outside the scope of the method, use it's designated initializer instead.

A: You are always instantiating an object in either case. It is just that the UIImage class provides some static convenience methods that hide the rather ugly alloc/init process. Even NSMutableArray has [NSMutableArray arrayWithCapacity:numItems] which still does 'alloc', 'init' inside of it but also sets up an initial capacity (for performance reasons). The best way is to peruse the docs, looking for static class methods, or seeing if autocomplete has any methods that begin with the thing you are making, e.g. [UIImage image...] and [NSDate date...]


text:
Q: How can improve this SQL query? I believe this is a SQL query running on Oracle:
SELECT ID, DEVICE_TYPE, S3_KEY, TO_CHAR(CREATION_DATE, 'YYYY-MM-DD HH24:MI:SS') AS CREATION_DAT
FROM KASE_DDL.ARCHIVED_LOG
WHERE
    CREATION_DATE >= TO_DATE('{DIST_YYYY/MM/DD HH24:MI:SS_UTC}', 'YYYY/MM/DD HH24:MI:SS')
    AND CREATION_DATE <= TO_DATE('{DIET_YYYY/MM/DD HH24:MI:SS_UTC}', 'YYYY/MM/DD HH24:MI:SS')

It is running slow and I wonder how can I rewrite it to improve its efficiency. For example, can this query utilize indexing if there is an index built on CREATION_DATE? I remember reading books saying that if there is computation around a column, Oracle may not be able to use any index built on it. Is my query falling into this case? Any other suggestion? Thank you.
UPDATE:
In my problem, CREATION_DATE has an index built in. I am curious about whether this query enables the database to utilize the index or not.

A: Add an index on CREATION_DATE.
I would also use the BETWEEN operator for the dates, but I like to read it that way.

A: For an additional performance gain you can try to use covering indexes.
In your case there is
create index ndxCovering on KASE_DDL.ARCHIVED_LOG(CREATION_DATE, ID, DEVICE_TYPE, S3_KEY);

It allows to read data only from index pages without seeking of data pages.

A: You can check the probable effectiveness of the index by comparing the clustering_factor in the user_indexes table with the number of rows and the number of blocks for the table. The clustering factor will be between the number of blocks and the number of rows, which represent the theoretical minimum and maximum values respectively.
If the clustering factor is closer to the number of blocks (ie. it's relatively small) then the index will be more likely to be chosen and the selection of block from the table based on accessing the index will be require less work by the system.
It's always worth checking if you have any doubts about the performance improvements you're seeing when the index is used to access the table.


text:
Q: Plotting 6 Dimensions in GGPlot Scatter Plot? I am struggling to plot 6 dimensions in ggplot on a scatterplot. Is there a limit to the number of dimensions that can be included in a plot? In the following code I am attempting to plot 6 dimensions in ggplot2, however, the variable that I passed to the shape aesthetic is not included in the graph. Is there a way to fix this? Here is the code:
ggplot(df, aes(x=cp, y=tpr.test.mean, color=minbucket, size=maxcompete, fill = maxdepth, shape = minsplit.cat)) +
  geom_point(pch=21) +
  scale_color_gradient(low="red", high="green") +
  scale_fill_gradient(low = "white", high = "purple")+
  scale_size_continuous(range=c(1,3.4)) +
  facet_grid(maxcompete.cat ~ maxdepth.cat)+
  theme(legend.key.size = unit(0.25, "cm"))+ theme(axis.text.x = element_text(angle = 90))

And here is the resulting figure. Note that the variable I passed to the shape aesthetic is not included, and the shapes do not vary at all. Is this because the ggplot package limits the number of dimensions in a scatterplot, or is there something I am doing wrong?
Thank you.


text:
Q: convert a string of variables to variable I have a String of javascript variables like this in a PHP varaible:
var TopInst='0',LVal18AFC='ولپارس',DEven='0',LSecVal='ساير واسطه گريهاي مالي',CgrValCot='N2',Flow='1',InstrumentID='IRO1LPRS0001',InsCode='48241092863917835',BaseVol=9140768,EstimatedEPS='341',ZTitad=2000000000,CIsin='IRO1LPRS0007',LVal18AFC='ولپارس',CSecVal='58 ',PdrCotVal='',PClosing='',PSGelStaMax='5570.00',PSGelStaMin='5160.00',Title='ليزينگ پارسيان (ولپارس) - بازار دوم بورس',FaraDesc ='',MinWeek='5220.00',MaxWeek='5720.00',MinYear='3200.00',MaxYear='9450.00',QTotTran5JAvg='26445809',SectorPE='12.91',KAjCapValCpsIdx='23',PriceMin=0,PriceMax=0,PriceYesterday=0;ThemeCount='5';ContractSize='0';NAV='0.0000';

and I want to convert it to real javascript or PHP variables so what do you suggest?

split the string or some other way?

Thanks.


text:
Q: How do I make a set where elements are sorted using a local variable? How do I make a set where the elements are always ordered using some local variable?
A simplified example of what I am trying to do is this.
int x[5] {9, 2, 3, 1, 8};
set<int, ???> my_set;
my_set.insert(0);
my_set.insert(1);
my_set.insert(4);
for (int a : my_set)
    cout << a << " ";   // I want the answer 1 4 0 because x[1] < x[4] < x[0]

I think I might be able to do this using a struct, but I am unsure how the use of x changes things.

A: You can set it up like so with a lambda
int x[5] {9, 2, 3, 1, 8};
auto comparator = [&](int a, int b){ return x[a] < x[b]; };
std::set<int, decltype(comparator)> my_set(comparator);

A: Well since you're "pairing" elements, why not use an std::pair?
#include <iostream>
#include <set>

int main()
{
    int order[5] {9, 2, 3, 1, 8};
    int data[3] {0, 1, 4};
    std::set<std::pair<int, int>> s;
    for (std::size_t i = 0; i < 3; ++i)
    {
        s.emplace(order[i], data[i]);
    }
    for (auto a : s)
        std::cout << a.second << " ";
}

This outputs 1 4 0 as expected.

A: voila!
#include <set>
#include <iostream>

int main()
{
    int x[5] {9, 2, 3, 1, 8};
    struct indirect_less
    {
        indirect_less(const int* p) : _p(p) {}
        bool operator()(int l, int r) const {
            return _p[l] < _p[r];
        }
        const int* _p;
    };

    std::set<int, indirect_less> my_set { indirect_less(x) };

    my_set.insert(0);
    my_set.insert(1);
    my_set.insert(4);

    for (int a : my_set) {

        std::cout << a << " ";   // I want the answer 1 4 0 because x[1] < x[4] < x[0]
    }
    std::cout << std::endl;
}

expected output:
1 4 0

A: you can use a pair and sort this elements by y and the pair in x always has the reference example
pair<0,9>
pair<1,2>
pair<2,3>

SORTED
pair<1,2>
pair<2,3>
pair<0,9>


text:
Q: Array Data Calculation I have met problem dealing with multidimensional array. Below are the code to store all the data query from mysql to array. May I know is there any idea how to calculate how many different module name in the multidimensional array and break the status into 2 column which are late and present? The SQL query get the data from a complex table which store all ModuleName and different status. I need to categories them and show in a table. So basically I need to check how many module in the array and how many late or present for the module.
while($array = mysql_fetch_array($result)){
        $list[] = array(
                        "ModuleName"=>$array['ModuleName'],
                        "status"    =>$array['Status']
            );
    }

This is the sample of expected result

A: Updated to group by ModuleName
SELECT ModuleName
      ,COUNT(*) AS module_count
      ,SUM(CASE WHEN Status != 'Present' THEN 1 ELSE 0 END) as late_count
      ,SUM(CASE WHEN Status  = 'Present' THEN 1 ELSE 0 END) as present_count
  FROM ( your original query )
 GROUP BY ModuleName

Just replace "your original query" with the SQL you used to retrieve the data in the array.
Original
SELECT COUNT(*) AS module_count
      ,SUM(CASE WHEN Status != 'present' THEN 1 ELSE 0 END) as late_count
      ,SUM(CASE WHEN Status  = 'present' THEN 1 ELSE 0 END) as present_count
  FROM ( your original query )


text:
Q: Using Beam Search on graph to generate sentence with highest score I'm working with a graph that I extracted from a long article.  The directed weighted graph, which is really nothing more than a dictionary, contains head words as vertices which are connected via edges to each word (tail words) that follows that word in the article.  So, if the word "yellow" appears 3 times in the article, and it's followed by the words "brick", "brick", and "submarine", than the "yellow" entry would be represented like so in the graph:
{"yellow": ["brick", "brick", "submarine"]}

This graph was generated using a python Class that I wrote called ExtractedGraph that, aside from an __init__ method that does the work of generating the graph, has a getProb(self, head_word, tail_word) method that takes as input the head word and the tail word and outputs the probability the head word will follow the tail word, which is the weight of the edge connecting the head word node and tail word node.  So, if we input "yellow" and "brick", the output would be 2/3.
My question is, how would one do a beam search of this graph to find the sentence with the max score.  Specifically, what if the input to the beam search function was a prefix_words string, a beam_width int, and a sen_length int (the max word length of a sentence).  How would the algorithm look?  After reading about the Beam Search algorithm online and watching numerous tutorials, I'm not sure how the Beam Search function would really work in this specific scenario.

A: Let's say graph_nodes is the dictionary and every sentence must start with the <s> symbol with probability 1.0 and all sentences must end with a special symbol </s>. To avoid sorting the hypotheses, I keep them in a heap, so adding an element is constant.
import heapq

beam = [(1.0, ["<s>"])]
for _ in range(sen_length):
    new_beam = []
    for score, hypothesis in beam:
        hypothesis_end = hypothesis[-1]

        # finished hypothesis will return to the beam and compete with new ones
        if hypothesis_end == "</s>":
            heapq.heappush(new_beam, (score, hypothesis))
            if len(new_beam) > beam_width:
                heapq.heappop(new_beam)

        # expand unfinished hypothesis
        for possible_continuation in graph_nodes[hypothesis_end]:
            continuation_score = score * get_prob(hypothesis_end, possible_continuation)
            heapq.heappush(
                new_beam, (continuation_score, hypothesis + [possible_continuation])
            if len(new_beam) > beam_width:
                heapq.heappop(new_beam)
    beam = new_beam

If your hypotheses can have different lengths, you should consider some length normalization (e.g., a geometric mean of the probabilities). Also, multiplying probabilities might not always be numerically stable, so you might want to use sums of logarithms instead.


text:
Q: Share the WiFi connection to the Wired interface in CLI I have a server without access to the Internet but every now and then I need to update some of its packages. In order to make my life easier, I am using my laptop which is also running Linux to share the laptop's WiFi connection over the Ethernet interface of the laptop and connect the server to the laptop with normal Ethernet cable. Of course, I am also changing the GW on the server to match the IP address of the Ethernet interface of my laptop.
I know how I can do that from the network manager GUI but I was wondering how I can do the same using the command line. I want to find a solution which preferably doesn't involve writing IPTables custom rules. The idea is that I want to write a script and an alias, to do exactly that.
As soon as I am done I will share the source code with you guys, here and also on Github, that's the beauty of open-source after all.

A: A bit in a hurry, but basically... If enp0s3 is your LAN and enp0s8 your WLAN:
Laptop side:
#ENABLE PACKET FORWARD
echo 1 > /proc/sys/net/ipv4/ip_forward

#YOU COULD JUST ENABLE FORWARD FOR EVERYTHING WITHOUT LIMITATIONS, USING INTERFACES JUST TO BE MORE SPECIFIC
iptables -A FORWARD -i enp0s3 -o enp0s8 -j ACCEPT
iptables -A FORWARD -i enp0s8 -o enp0s3 -j ACCEPT

#MASQUERADE OUTBOUND CONNECTIONS
iptables -t nat -A POSTROUTING -o enp0s8 -j MASQUERADE

This can be easily scripted, and all conf is cleaned up at reboot.
Server side:
ASSIGN VALID STATIC NETWORK CONFIGURATION WITH LAPTOP IP AS GATEWAY
ASSIGN VALID DNS (VIA /etc/resolv.conf IF LINUX), OR YOU CAN DO ADDITIONAL IPTABLES RULES TO DNAT DNS TRAFFIC LAPTOP SIDE

A: When you use the GUI, that means you basically activate a connection profile in NetworkManager. You can do just the same from command line.
First, find the name of the profile in question, by looking at nmcli connection output. Then activate the profile with nmcli connection up "$PROFILE_NAME".
And of course you can create and modify your profile via command line only, eg by using nmcli. See the manual pages. The relevant setting in the profile is ipv4.method=shared.


text:
Q: Print email address on windows mail message On Windows 10 Mail application, if I print an email it may show the From field with the name only, e.g. From: Jane Doe.
How do I make it also print the email address I see on the message, e.g. From: Jane Doe <jane.doe@example.com>?
I actually want to print as PDF, but I believe the result would be the same as sending it to a physical printer. I know there's the option to save it as an email message (.eml) file.
I couldn't find the relevant configuration in the Mail app settings, or online searches. From a related question on Outlook and past experience, I'm guessing this is not possible, but I'm hoping to learn otherwise. Thanks.


text:
Q: Limit problem involving factorials and trigonometry The limit is: $$\lim_{n\to +\infty}\frac{n ln(\frac{((n+1)!)^{2n}}{n^{2n}(n!)^{2n}})+\frac{arctan(n)}{n}+\frac{sin(n)}{n}}{(-1)^n\sqrt{n}-4n}$$
After some calculations for the numerator i got to this conclusion:
$$\lim_{n\to +\infty}\frac{2n}{(-1)^n\sqrt{n}-4n}$$
At this point it is difficult for me to work around $$(-1)^n$$
which is giving me some problems. Any hints? $$ $$
**I though about simplifying the n's which would lead to:$$\lim_{n\to +\infty}\frac{2}{\frac{(-1)^n}{\sqrt{n}}-4}$$

A: Note that $$\lim_{n\to +\infty}\frac{2n}{(-1)^n\sqrt{n}-4n} = \lim_{n\to +\infty}\frac{2}{\frac{(-1)^n}{\sqrt{n}}-4}$$
where $\frac{(-1)^n}{\sqrt{n}} \longrightarrow 0$.


text:
Q: Who killed Luke's students? As we see in The Rise of Kylo Ren comic, it wasn't Ben Solo.
'He vanished with a handful of my students and slaughtered the rest', says Luke to Rey.
But, again, that wasn't Ben; and Luke wasn't conscious when it happened. He didn't really know, although he was certain. Who else could have been?
'Slaughter' sounds like a lightsaber or a knife of some kind. Here (top right hand corner) we see some corpses:

Already dead. Maybe killed in their sleep.

A: Ben (apparently) killed them. Some of the students did join him, although it's not apparent whether they had any part in the slaughter.

"He must have thought I was dead," Luke said. "When I came to, the
temple was burning. He had vanished with a handful of my students and
slaughtered the rest. Leia blamed Snoke, but it was I who broke that
family. I failed. Because I was Luke Skywalker, Jedi Master. A
legend."
The Last Jedi - Official Novelisation

Your confusion likely stems from the fact that the comic doesn't portray these events as was described in the film. Multiple tweets on the issue are referenced here


text:
Q: stop the php from appearing above background image My php script content is appearing above my background image even the background image is set inside the html tag inside my css, how can I get the image to be behind the text

    <!DOCTYPE html>

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Secret Diary</title>
  <link rel="stylesheet" href="css/bootstrap.css">
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/style.css">
  <?php
  session_start();
  if (array_key_exists("id", $_COOKIE)){
    $_SESSION['id'] = $_COOKIE['id'];
  }
  if(array_key_exists("id", $_SESSION)){
    echo "Logged In! Log Out";
  } else {
    header("location: index.php");
  }
  ?>

css:
    html{
    background: url("../img/bg.jpg") no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

.center{
  position:absolute;
  top:50%;
  left:50%;
  padding:10px;
  -ms-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translate(-50%,-50%);
  transform: translate(-50%,-50%);
  }

A: Place your PHP inbetween the  tags
<?php
  session_start();
  if(array_key_exists("id", $_COOKIE)){
      $_SESSION['id'] = $_COOKIE['id'];
  }
 ?>

<!DOCTYPE html>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Secret Diary</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">

    <?php
      if(array_key_exists("id", $_SESSION)){
        echo "Logged In! Log Out";
      } else {
        header("location: index.php");
      }
    ?>

also update the css line html{ to be body instead
body {
  background: url("../img/bg.jpg") no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

A: Instead of echoing PHP where you excecute it, store it for later. Your current method (echo as you go) will result in difficult code, just like you're experiencing now.
if(array_key_exists("id", $_SESSION)){
    $loggedinText = "Logged In! Log Out";
}
/*
   All your content here,
   and when you're ready for it:
*/
echo $loggedinText;

Offtopic: It is considered good practice if you split html and PHP into seperate files. You place the html in a html file, and place it into a variable with php using file_get_contents.
if(array_key_exists("id", $_SESSION)){
    $loggedinText = "Logged In! Log Out";
    $template = file_get_contents("example.html");
    // Here you do ALL YOUR OTHER LOGIC
    // _nothing_ should echo here, until:
    // And then only at the end of your file:
    echo $template;
} else{
    header("Location: not_logged_in.html");
}

As you can see, you can easily read functionallity without html that distracts you. Now only logged in users can even see your template. From a security perspective, this will also help.


text:
Q: R raster function does not read rasters like it did before? I am currently working through my R scripts and it seems the old raster() function from the raster package doesn't work anymore. I get the following error when I do raster("filename")
Error in extension(x) :
  4 arguments passed to .Internal(nchar) which requires 3
Did something change with the new version of raster package? Or maybe the extension function might have changed and the raster function is still using the same way it did before the update?
Thanks for your help
Robby

A: Alright, it seems there was a version issue between R and the packages. All you need to do is update everything to the newest version.


text:
Q: .Net Impersonation Issue When User Part Of Administrators I am troubleshooting an ASP.Net project issue. I have a network share, and I'm using impersonation https://learn.microsoft.com/en-US/troubleshoot/aspnet/implement-impersonation.
Here's an odd issue I found: if I impersonate a user named domain\foo to enumerate files using Directory.EnumerateFiles, I run into UnauthorizedAccessException for one of the two test cases:
In both cases user foo is part of the administrators group.

*

*Test case 1: If I explicitly give the user NTFS permissions to the folder of the share, I don't get access denied (not that administrators group has full control to the folder).

*Test case 2: If I remove the user from the permissions list, keeping in mind that administrators still has full control, I get the UnauthorizedAccessException.

I cannot explain the above behavior. In both cases I would expect to be able to enumerate files successfully. Is this a bug, or am I not taking into account some key piece?

A: I was able to fix this issue by using a logon type of LOGON32_LOGON_NEW_CREDENTIALS


text:
Q: Java simple OCR algorithm I've been working on a simple OCR project for a couple days. The app is supposed to extract a text from an image. The solution I've come up with is:
greyscaling, rotating, removing noise from the image and isolating every single character on the image. So I need some help with a simple algorithm that would let me recognise the character. I only need to recognise the letters A,B,C,D.

A: The method i'd use would be to make a mask of each letter, scaling it to the rectangle you found when cutting the picture and "score" each letter, by comparing RGB for example.


text:
Q: Set page title when viewing PDF through php script I am using this code to view an PDF file in php instead of just opening it in an browser.
if(isset($_SESSION['access_token']))
{
    require_once('includes/db_connect.php');

    $id = mysqli_real_escape_string($mysqli, $_GET['id']);
    $attest = mysqli_real_escape_string($mysqli, $_GET['attest']);
    $heat = mysqli_real_escape_string($mysqli, $_GET['heat']);
    $mat = mysqli_real_escape_string($mysqli, $_GET['mat']);
    $dikte = mysqli_real_escape_string($mysqli, $_GET['dikte']);

    $file = '../thure/uploads/attesten/'.$id.'.pdf';

    $filename = 'Certificaat plaat '.$id.' met '.$attest.' heat '.$heat.' '.$mat.' '.$dikte.'mm.pdf';

    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="'.$filename.'"');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '.filesize($file));
    header('Accept-Ranges: bytes');
    @readfile($file);
}

The title of the page as Shown in Explorer, Chrome etc. is the name of the php file. How can I set an custom name (same as PDF) here?
When I use the code below the pdf is shown as plain text.
<!DOCTYPE html>
<head>
    <title>Torza</title>
</head>