问:
How to store Apache Sling content in MongoDB?
I am new to Java and Apache Sling as well. I've been trying to link Sling with MongoDB and these are what I've done so far:

I configured NoSQL MongoDB Resource Provider in Sling console:

Then the Oak Document Node Store Service:

And finally I ran java -Dsling.run.modes=oak_mongo -jar org.apache
.sling.launchpad-9.jar -c sling -f - to run the sling launchpad in mongodb mode. This was the results:

As a result, a database named "sling" was created in MongoDB which I could see  via Robo-3T (a MongoDB management tool):

After creating some content through my maven application using the below plugin and deploying it on Sling, I was able to see my newly created nodes and resources in the Sling browser (http://localhost:8080/bin/browser.html):

```<code><build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>3.3.0</version>
            <configuration>
                <instructions>
                    <Sling-Nodetypes>
                        SLING-INF/nodetypes/nodetypes.cnd
                    </Sling-Nodetypes>
                    <Sling-Initial-Content>
                        SLING-INF/scripts;overwrite:=true;uninstall:=true;path:=/apps/test1/nodes,
                        SLING-INF/content;overwrite:=true;uninstall:=true;path:=/content/test1
                    </Sling-Initial-Content>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>
</code>```

However, I need to to store everything inside the MongoDB database but currently, nothing stored in the database. How can I achieve this?

答:
The simplest way is to start the Sling Launchpad with the following argument: -Dsling.run.modes=oak-mongo . This will ensure that the Oak is configured to use Mongo. You must remove the sling directory, otherwise the run modes will not be changes.

What you've done with your attempts is to:

add a new resource provider which shadows the current one at the repository root. I am not sure of the actual effects, it is probably rejected - please see the sling error log

configure a new Oak NodeStoreService which uses Mongo - but it's probably not picked up since there is already a NodeStoreService in action - Sling requires one to start up.

Body:
I am new to Java and Apache Sling as well. I've been trying to link Sling with MongoDB and these are what I've done so far:

I configured NoSQL MongoDB Resource Provider in Sling console:

Then the Oak Document Node Store Service:

And finally I ran java -Dsling.run.modes=oak_mongo -jar org.apache
.sling.launchpad-9.jar -c sling -f - to run the sling launchpad in mongodb mode. This was the results:

As a result, a database named "sling" was created in MongoDB which I could see  via Robo-3T (a MongoDB management tool):

After creating some content through my maven application using the below plugin and deploying it on Sling, I was able to see my newly created nodes and resources in the Sling browser (http://localhost:8080/bin/browser.html):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>3.3.0</version>
            <configuration>
                <instructions>
                    <Sling-Nodetypes>
                        SLING-INF/nodetypes/nodetypes.cnd
                    </Sling-Nodetypes>
                    <Sling-Initial-Content>
                        SLING-INF/scripts;overwrite:=true;uninstall:=true;path:=/apps/test1/nodes,
                        SLING-INF/content;overwrite:=true;uninstall:=true;path:=/content/test1
                    </Sling-Initial-Content>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

However, I need to to store everything inside the MongoDB database but currently, nothing stored in the database. How can I achieve this?


来源: stackexchange

问:
Jinja2 marking HTML string as safe
I have a HTML tag in jinja2 that I want to embed a variable into.

Format.html:

```<code>{% set color="red" %}
{% set tag="<img src='{{ color }}.png' />" %}
This is red {{ tag|safe }}.
</code>```

If I mark tag as safe, it doesn't render the variable color. If I don't render it as safe it sanitizes the HTML img tag and I can't embed my image. How do I properly embed my image ? I don't want to write out the img tag because I need it as a reusable variable throughout the code.

答:
The problem is that you can't use{{ }} inside another template tag. You can, however, concatenate the string and the variable color inside a template tag like this:

Method #1: Using the ~ symbol. From Jinja2's docs, it converts the variables into strings and concatenates them.

```<code>{% set tag = "<img src='" ~  color ~ ".png' />" %}
</code>```

OR

Method #2: Using the format filter:

```<code>{% set tag = "<img src='%s.png' />"|format(color) %}
</code>```

ContentLicense: CC BY-SA 3.0

Title: Jinja2 marking HTML string as safe

Body:
I have a HTML tag in jinja2 that I want to embed a variable into.

Format.html:

{% set color="red" %}
{% set tag="" %}
This is red {{ tag|safe }}.

If I mark tag as safe, it doesn't render the variable color. If I don't render it as safe it sanitizes the HTML img tag and I can't embed my image. How do I properly embed my image ? I don't want to write out the img tag because I need it as a reusable variable throughout the code.

Body:
The problem is that you can't use{{ }} inside another template tag. You can, however, concatenate the string and the variable color inside a template tag like this:

Method #1: Using the ~ symbol. From Jinja2's docs, it converts the variables into strings and concatenates them.

{% set tag = "<img src='" ~  color ~ ".png' />" %}

OR

Method #2: Using the format filter:

{% set tag = "<img src='%s.png' />"|format(color) %}


问:
Google Map API V3 : Map is not displayed if I don't choose "The website .... would like to use your current location" on IE popup
I use Google Map Api v3 and I've a problem with IE (11) location.

When i launch IE 11 the browser ask me (in a popup) if I want to be localized. It the same thing on others browsers (Edge, Firefox, Google Chrome, ...) but on other's browsers I can say "no" and the map is still showed (no localized).

On IE (11) I can't choose "no". I must close the popup if I don't want to be localized but In this case the map is not showed !!!
I would still like to display the map if I close the popup.

Have you got a solution please ?

答:
My code (It may be able to help someone) :</p>

```<code>// Var GoogleMap
var googleMap = {};
googleMap.map = {};

// Init Dom map
var domMAP = document.getElementById(config.CSS.IDs.map.google);

// Google map instance
googleMap.map = new google.maps.Map(domMAP, {
    center: config.settings.map.defaultPosition,
    zoom: config.settings.map.defaultZoom,
    mapTypeId: config.settings.map.typeId,
    fullscreenControl: config.settings.map.fullscreenControl
});

// Geolocation
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {
        var pos = {
            lat: position.coords.latitude,
            lng: position.coords.longitude
        };
        googleMap.map.setCenter(pos);
        _initMap();
    }, function () {
        _setPositionWithSearch(config.settings.map.defaultName, function () {
            _initMap();
        });
    });
} else {
    // Browser doesn't support Geolocation
    _setPositionWithSearch(config.settings.map.initialDefaultName, function () {
        _initMap();
    });
}
</code>```

Body:
My code (It may be able to help someone) :

// Var GoogleMap
var googleMap = {};
googleMap.map = {};

// Init Dom map
var domMAP = document.getElementById(config.CSS.IDs.map.google);

// Google map instance
googleMap.map = new google.maps.Map(domMAP, {
    center: config.settings.map.defaultPosition,
    zoom: config.settings.map.defaultZoom,
    mapTypeId: config.settings.map.typeId,
    fullscreenControl: config.settings.map.fullscreenControl
});

// Geolocation
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {
        var pos = {
            lat: position.coords.latitude,
            lng: position.coords.longitude
        };
        googleMap.map.setCenter(pos);
        _initMap();
    }, function () {
        _setPositionWithSearch(config.settings.map.defaultName, function () {
            _initMap();
        });
    });
} else {
    // Browser doesn't support Geolocation
    _setPositionWithSearch(config.settings.map.initialDefaultName, function () {
        _initMap();
    });
}


问:
Image over an image using a class (CSS)
The problem I have here is because we use a theme (wordpress) for our clients that makes it easy for them to change an image and this is a simple version of the code it produces:

```<code><div class="row">
   <div class="column">
      <img class="image" src="image user can change">
   </div>
</div>
</code>```

What I need to try and achieve is a layer over the top of the image to put a logo on the image without changing the core HTML that the theme produces and only using CSS.

My thought was adding a background image to the class column and somehow bringing it in front. I tried z-index on the column with no luck. Any ideas?

答:
Add new class .overlay add the img logo path, give the parent position:absolute;

.image {
height: 200px;
max-width: 100%;
}

.overlay{
position:absolute;
/*positioning here*/
}

.overlay img{
height: 30px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="row">
   <div class="column">
   <div class="overlay"><img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a"></div>
      <img class="image" src="https://d4n5pyzr6ibrc.cloudfront.net/media/27FB7F0C-9885-42A6-9E0C19C35242B5AC/4785B1C2-8734-405D-96DC23A6A32F256B/thul-90efb785-97af-5e51-94cf-503fc81b6940.jpg?response-content-disposition=inline">
   </div>
</div>  </code>```

Title: Image over an image using a class (CSS)

Body:
The problem I have here is because we use a theme (wordpress) for our clients that makes it easy for them to change an image and this is a simple version of the code it produces:

What I need to try and achieve is a layer over the top of the image to put a logo on the image without changing the core HTML that the theme produces and only using CSS.

My thought was adding a background image to the class column and somehow bringing it in front. I tried z-index on the column with no luck. Any ideas?

Body:
Add new class .overlay add the img logo path, give the parent position:absolute;

.image {
height: 200px;
max-width: 100%;
}

.overlay{
position:absolute;
/*positioning here*/
}

.overlay img{
height: 30px;
}

<div class="row">
   <div class="column">
   <div class="overlay"><img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a"></div>
      <img class="image" src="https://d4n5pyzr6ibrc.cloudfront.net/media/27FB7F0C-9885-42A6-9E0C19C35242B5AC/4785B1C2-8734-405D-96DC23A6A32F256B/thul-90efb785-97af-5e51-94cf-503fc81b6940.jpg?response-content-disposition=inline">
   </div>
</div>


问:
trouble with two locations in nginx config
I have 2 links: myserver.org and myserver.org/support
I need first link follow to /var/www/myserver.org and second to /var/www/support
My config now:
first file & link

```<code>server {
    listen 80 default_server;

    server_name groupmanager.org;
    charset utf-8;

    root /var/www/groupmanager.org;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    access_log /var/log/nginx/groupmanager.org_access.log;
    error_log /var/log/nginx/groupmanager.org_error.log;

    include /etc/nginx/templates/php-fpm.conf;
}

server {
  listen 80;

  server_name www.groupmanager.org;
  rewrite ^(.*) http://groupmanager.org$1 permanent;
}
</code>```

Second file & link:

```<code>server {
  listen 80;

  server_name 163.172.88.31/support;
  charset utf-8;

  root /var/www/support;
  index index.php;

  access_log /var/log/nginx/support_access.log;
  error_log /var/log/nginx/support_error.log;

  include /etc/nginx/templates/php-fpm.conf;
}

server {

  listen 80;

  server_name www.163.172.88.31/support;
  rewrite ^(.*) http://163.172.88.31/support$1 permanent;
}
</code>```

php-fpm.conf

```<code>location ~ \.php$ {
   try_files $uri =404;
   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

location ~ /\.ht {
   deny all;
}

location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
  expires 168h;
}

location ~* \.(css|js)$ {
  expires 180m;
}
</code>```

First link works fine, second - no. I see '403 Forbidden'
What is not rigth?
Permissions for folders are the same, I think, they are right.

答:
Try like this:

```<code>    include /etc/nginx/default.d/*.conf;
    server {

        listen 80 default_server;

        server_name myserver.org;
        charset utf-8;

        root /var/www/myserver.org;
        index index.php;

        include /etc/nginx/default.d/*.conf;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
</code>```

in /etc/nginx/default.d/ directory , create  a .config file  test.config:

```<code>location myserver.org {
proxy_pass /myserver.org;
}
location myserver.org/support {
proxy_pass /var/www/support;
}
</code>```

Body:
I have 2 links: myserver.org and myserver.org/support
I need first link follow to /var/www/myserver.org and second to /var/www/support
My config now:
first file & link

server {
    listen 80 default_server;

    server_name groupmanager.org;
    charset utf-8;

    root /var/www/groupmanager.org;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    access_log /var/log/nginx/groupmanager.org_access.log;
    error_log /var/log/nginx/groupmanager.org_error.log;

    include /etc/nginx/templates/php-fpm.conf;
}

server {
  listen 80;

  server_name www.groupmanager.org;
  rewrite ^(.*) http://groupmanager.org$1 permanent;
}

Second file & link:

server {
  listen 80;

  server_name 163.172.88.31/support;
  charset utf-8;

  root /var/www/support;
  index index.php;

  access_log /var/log/nginx/support_access.log;
  error_log /var/log/nginx/support_error.log;

  include /etc/nginx/templates/php-fpm.conf;
}

server {

  listen 80;

  server_name www.163.172.88.31/support;
  rewrite ^(.*) http://163.172.88.31/support$1 permanent;
}

php-fpm.conf

location ~ \.php$ {
   try_files $uri =404;
   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

location ~ /\.ht {
   deny all;
}

location ~* \.(gif|jpeg|jpg|txt|png|tif|tiff|ico|jng|bmp|doc|pdf|rtf|xls|ppt|rar|rpm|swf|zip|bin|exe|dll|deb|cur)$ {
  expires 168h;
}

location ~* \.(css|js)$ {
  expires 180m;
}

First link works fine, second - no. I see '403 Forbidden'
What is not rigth?
Permissions for folders are the same, I think, they are right.

Body:
Try like this:

    include /etc/nginx/default.d/*.conf;
    server {

        listen 80 default_server;

        server_name myserver.org;
        charset utf-8;

        root /var/www/myserver.org;
        index index.php;

        include /etc/nginx/default.d/*.conf;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

in /etc/nginx/default.d/ directory , create  a .config file  test.config:

location myserver.org {
proxy_pass /myserver.org;
}
location myserver.org/support {
proxy_pass /var/www/support;
}


问:
Side-by-side stacked barplot with facetting using ggplot2
The majority of information I can find on side-by-side stacked barplots deals with instances in where some variable (number of side-by-side bars) are repeated for each variable along the x-axis - see: 1, 2, 3, 4, 5, 6. In these cases they use ggplot with besides=TRUE.

I have a more complex example which I believe will require faceting like these two examples: 7 & 8.

Quick background (for those interested in the why?):
I'm trying to compare the efficiency of a proteomics protocol that enriches for chromatin by comparing to the proportion of nuclear proteins found in the core/whole proteome experiments for 4 cell lines. to do this I used The Human Protein Atlas to annotate proteins by their subcellular location and compare nuclear proteins from chromatin-enrichment to whole-enrichment. However, the chromatin-enrichment protocol was 1D-shotgun while the whole proteome data was 2D-shotgun with 50 fractions. In layman terms this means the whole/core proteome data is a more expensive experiment done at higher coverage. Therefore, it wouldn't make sense to look at absolute proportion though because the overall amount of found proteins would be higher in the whole proteome pull-downs (see figure: absolute protein comparison sketch). To circumvent this issue I divided by the total number of proteins found in each pull-down to get relative proportion of proteins from each subcellular location.

Using these relative proportions I've produced a stacked barplot of the following data in my gist with the following code:

```<code>df1 <- read.csv("data.csv") # Load data.frame of the data
df2 <- melt(df1,                                # Reshape the data from
            id.vars = "subcellular_location",   # wide format into long format
            variable.name = "cell_line",        # (i.e. tidy data)
            value.name = "relative_proportion")
</code>```

For some reason this didn't change the variable name or value name (headers) - they are called "variable" and "value" still? So I had to rename column headers via the following.

```<code>names(df2) <- c("subcellular_location", "cell_line", "relative_proportion")
</code>```

As there are many subcellular locations I needed to custom add colors, furthermore I grouped them by similar locations (e.g. nuclear in blue).

```<code>p <- ggplot() +
  geom_bar(aes(x = cell_line, y = percentage, fill = subcellular_location),
           data = df2, stat="identity")

p +
  coord_flip() +
  scale_fill_manual(values = c("#bd5db0","#9ae17c", "#be0024", "#7388ff", "#c456b7",
                               "#8ed470", "#7ec361", "#7d7304", "#f87a00", "#d543c7",
                               "#bead47", "#d148c3", "#da8836", "#e28504", "#d93eca",
                               "#c720b9", "#bc07ae", "#a40098", "#9a008e", "#e8d448",
                               "#104ed7", "#2c4ecc", "#00428c", "#393c6d", "#173b8f",
                               "#3f4c96", "#9ba2f5", "#727bcc", "#e59c5f", "#790000",
                               "#045d00", "#f9ad6f"))
</code>```

See image here: stacked barplot

The core proteome pull-downs are highlighted in yellow. Ideally what I would like to do is facet this barplot into 4 sections - one for each cell line. I followed the instructions from reference 7 for faceting but am getting an error.

First I split my dataframe into 4 separate tidy dataframes (e.g. below):

```<code>K562 <- read.csv("K562-relative.csv")
K562 <- melt(K562, id.vars = "subcellular_location") # Reshape the data into tidy form
names(K562) <- c("subcellular_location", "cell_line", "relative_proportion")
</code>```

etc.

Than I created a vector for cell line:

```<code>cell <- sample(c("HAP1","K562","A673","MDS"))
</code>```

When I try the following code I get an error:

```<code>ref_by_cell <- data.frame(HAP1 = HAP1, K562 = K562, A673 = A673, MDS = MDS, cell = cell)
</code>```

Error in data.frame(HAP1 = HAP1, K562 = K562, A673 = A673, MDS = MDS,
  arguments imply differing number of rows: 576, 544, 64, 4

I would appreciate any help with faceting or alternative ideas for displaying this information.

Thank you!

答:
I'm not entirely sure what you want, but if you want to facet by the first part of each cell_line value...

```<code># add faceting variable to df2
df2 <- df2 %>%
  mutate(cell = stringi::stri_extract_first_regex(cell_line, "^[^\\.|_]+"))

# facet by cell, specifying free scales / space on the y-axis
ggplot(data = df2,
       aes(x = cell_line, y = relative_proportion, fill = subcellular_location)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  facet_grid(cell~., scales = "free_y", space = "free_y") +
  scale_fill_manual(values = c("#bd5db0","#9ae17c", "#be0024", "#7388ff", "#c456b7",
                               "#8ed470", "#7ec361", "#7d7304", "#f87a00", "#d543c7",
                               "#bead47", "#d148c3", "#da8836", "#e28504", "#d93eca",
                               "#c720b9", "#bc07ae", "#a40098", "#9a008e", "#e8d448",
                               "#104ed7", "#2c4ecc", "#00428c", "#393c6d", "#173b8f",
                               "#3f4c96", "#9ba2f5", "#727bcc", "#e59c5f", "#790000",
                               "#045d00", "#f9ad6f")) +
  theme_bw() +
  theme(strip.text.y = element_text(angle = 0))
</code>```

Data (copied from your gist link; next time please use dput so that others can reproduce your example more easily):

```<code>> dput(df1)
structure(list(subcellular_location = c("actinFilaments", "aggresome",
"cellJunctions", "centrosome", "cytokineticBridge", "cytoplasmicBodies",
"cytosol", "endoplasmicReticulum", "endosome", "focalAdhesion",
"golgiApparatus", "intermediateFilaments", "lipidDroplets", "lysosomes",
"microtubuleEnds", "microtubuleOrganizingCenter", "microtubules",
"midbodyRing", "midbody", "mitochondria", "mitoticSpindle", "nuclearBodies",
"nuclearMembrane", "nuclearSpeckles", "nucleliFibrallar", "nucleoli",
"nucleoplasm", "nucleus", "peroxisomes", "plasmaMembrane", "rodsAndRings",
"vesicles"), HAP1_P5242 = c(0.009581882, 0.000338753, 0.011033682,
0.015824623, 0.003774681, 0.00232288, 0.227013163, 0.024535424,
0.001258227, 0.005807201, 0.04229578, 0.008710801, 0.0014518,
0.001064654, 0.00029036, 0.006484708, 0.013646922, 0.000483933,
0.001064654, 0.063637244, 0.00087108, 0.02303523, 0.013646922,
0.024535424, 0.013259775, 0.054587689, 0.195509098, 0.101480836,
0.00174216, 0.058072009, 0.000822687, 0.071815718), HAP1.wt_P8255.1 = c(0.0176,
0, 0.0032, 0.0096, 0, 0.0032, 0.3664, 0.0912, 0.008, 0.0032,
0.0128, 0, 0, 0.0064, 0, 0.0032, 0.0288, 0, 0, 0.0528, 0, 0.0128,
0.0048, 0.0096, 0, 0.0496, 0.1552, 0.0576, 0, 0.064, 0.0016,
0.0384), HAP1.wt_P8255.2 = c(0.013179572, 0, 0, 0.008237232,
0, 0.004942339, 0.36738056, 0.098846788, 0.003294893, 0.003294893,
0.016474465, 0.001647446, 0, 0.004942339, 0, 0.003294893, 0.029654036,
0, 0, 0.05107084, 0, 0.009884679, 0.004942339, 0.011532125, 0,
0.044481054, 0.154859967, 0.05601318, 0, 0.064250412, 0.001647446,
0.046128501), HAP1.wt_P8254.1 = c(0.012841091, 0, 0, 0.006420546,
0.001605136, 0.004815409, 0.362760835, 0.08988764, 0.001605136,
0.004815409, 0.017656501, 0.003210273, 0, 0.003210273, 0, 0.004815409,
0.032102729, 0, 0, 0.04975923, 0, 0.011235955, 0.003210273, 0.011235955,
0, 0.04975923, 0.160513644, 0.060995185, 0, 0.069020867, 0.001605136,
0.036918138), HAP1.wt_P8254.2 = c(0.015873016, 0, 0, 0.00952381,
0.001587302, 0.004761905, 0.357142857, 0.103174603, 0.003174603,
0.003174603, 0.014285714, 0.001587302, 0.001587302, 0.003174603,
0, 0.003174603, 0.03015873, 0, 0, 0.055555556, 0, 0.012698413,
0.006349206, 0.012698413, 0, 0.050793651, 0.152380952, 0.063492063,
0, 0.057142857, 0.001587302, 0.034920635), HAP1.kd_P8253.1 = c(0,
0, 0, 0, 0, 0, 0.270270271, 0.027027028, 0, 0, 0.027027028, 0,
0, 0, 0, 0, 0.054054053, 0, 0, 0, 0, 0, 0, 0.054054053, 0, 0.054054053,
0.405405405, 0.027027028, 0, 0, 0, 0.081081081), HAP1.kd_P8253.2 = c(0.021381579,
0, 0.003289474, 0.013157895, 0, 0.003289474, 0.368421053, 0.100328947,
0.004934211, 0.003289474, 0.013157895, 0.003289474, 0, 0.006578947,
0, 0.001644737, 0.027960526, 0, 0, 0.046052632, 0, 0.011513158,
0.004934211, 0.009868421, 0, 0.050986842, 0.15131579, 0.050986842,
0, 0.065789474, 0.001644737, 0.036184211), HAP1.kd_P8252.1 = c(0.018518518,
0, 0.00308642, 0.010802469, 0, 0.00462963, 0.354938272, 0.092592593,
0.00617284, 0.00462963, 0.018518518, 0, 0.00154321, 0.00462963,
0, 0.00617284, 0.026234568, 0, 0, 0.043209877, 0, 0.015432099,
0.00308642, 0.015432099, 0, 0.049382716, 0.154320988, 0.061728395,
0, 0.063271605, 0.00154321, 0.040123457), HAP1.kd_P8252.2 = c(0.012965964,
0, 0, 0.011345219, 0.001620746, 0.003241491, 0.367909238, 0.095623987,
0.003241491, 0.004862237, 0.017828201, 0.003241491, 0, 0.004862237,
0, 0.003241491, 0.030794165, 0, 0, 0.051863857, 0, 0.016207455,
0.003241491, 0.009724473, 0, 0.04376013, 0.1636953, 0.055105348,
0, 0.064829822, 0.001620746, 0.02917342), HAP1.kd_P8249.1 = c(0.010309278,
0.001718213, 0, 0.006872852, 0, 0.005154639, 0.197594502, 0.091065292,
0.001718213, 0, 0.013745704, 0.005154639, 0.001718213, 0.001718213,
0, 0, 0.027491409, 0, 0, 0.054982818, 0, 0.017182131, 0.013745704,
0.060137457, 0, 0.082474227, 0.240549828, 0.094501718, 0, 0.04467354,
0, 0.027491409), HAP1.kd_P8249.2 = c(0.010752688, 0, 0, 0.007168459,
0, 0.003584229, 0.20609319, 0.084229391, 0.001792115, 0, 0.007168459,
0.005376344, 0, 0.001792115, 0, 0, 0.03046595, 0, 0, 0.069892473,
0, 0.019713262, 0.014336918, 0.064516129, 0, 0.08781362, 0.224014337,
0.096774194, 0, 0.039426523, 0, 0.025089606), HAP1.kd_P8248.1 = c(0.007207207,
0, 0.001801802, 0.007207207, 0, 0.003603604, 0.198198198, 0.099099099,
0, 0, 0.009009009, 0.007207207, 0, 0, 0, 0.001801802, 0.025225225,
0, 0, 0.061261261, 0, 0.021621622, 0.016216216, 0.068468468,
0, 0.079279279, 0.234234234, 0.093693694, 0.001801802, 0.028828829,
0, 0.034234234), HAP1.kd_P8248.2 = c(0.005272408, 0.001757469,
0, 0.008787346, 0, 0.005272408, 0.202108963, 0.09314587, 0, 0,
0.014059754, 0.005272408, 0, 0, 0, 0.001757469, 0.029876977,
0, 0, 0.056239016, 0, 0.021089631, 0.014059754, 0.065026362,
0, 0.086115993, 0.228471002, 0.094903339, 0.001757469, 0.036906854,
0, 0.028119508), HAP1.wt_P8247.1 = c(0.016333938, 0, 0, 0.001814882,
0, 0.005444646, 0.197822141, 0.09800363, 0.001814882, 0, 0.007259528,
0.005444646, 0, 0.001814882, 0, 0.001814882, 0.030852995, 0,
0, 0.061705989, 0, 0.021778584, 0.012704174, 0.065335753, 0,
0.087114338, 0.234119782, 0.096188748, 0, 0.029038113, 0, 0.023593466
), HAP1.wt_P8247.2 = c(0.011173184, 0, 0, 0.003724395, 0, 0.003724395,
0.197392924, 0.098696462, 0.001862197, 0, 0.009310987, 0.005586592,
0, 0.001862197, 0, 0.001862197, 0.029795158, 0, 0, 0.059590317,
0, 0.018621974, 0.013035382, 0.067039106, 0, 0.08566108, 0.240223464,
0.096834264, 0, 0.029795158, 0, 0.024208566), HAP1.wt_P8246.1 = c(0.008880995,
0, 0, 0.005328597, 0.003552398, 0.003552398, 0.195381883, 0.090586146,
0, 0, 0.005328597, 0.008880995, 0, 0, 0, 0.001776199, 0.030195382,
0, 0, 0.051509769, 0, 0.023090586, 0.01598579, 0.063943162, 0,
0.097690941, 0.245115453, 0.097690941, 0, 0.026642984, 0, 0.024866785
), HAP1.wt_P8246.2 = c(0.009025271, 0, 0.001805054, 0.005415162,
0, 0.003610108, 0.19133574, 0.088447653, 0, 0.001805054, 0.012635379,
0.007220217, 0, 0, 0, 0, 0.028880866, 0, 0, 0.048736462, 0, 0.019855596,
0.027075812, 0.066787004, 0, 0.084837545, 0.241877256, 0.09566787,
0, 0.028880866, 0, 0.036101083), HAP1_P7964.1 = c(0.010040907,
0, 0.007437709, 0.017106731, 0.002975084, 0.003346969, 0.211230941,
0.040535515, 0.002603198, 0.005950167, 0.023056898, 0.00818148,
0.001115656, 0.002231313, 0.000743771, 0.005950167, 0.014503533,
0, 0.000743771, 0.065451841, 0.001115656, 0.023056898, 0.018966158,
0.031610264, 0, 0.065451841, 0.223875046, 0.105243585, 0.002603198,
0.051692079, 0.001487542, 0.051692079), MDS_P7246 = c(0.008080031,
0.000384763, 0.005386687, 0.012889573, 0.002885725, 0.002500962,
0.204116968, 0.035013467, 0.002116199, 0.00461716, 0.030973451,
0.008272412, 0.001539053, 0.001539053, 0.000192382, 0.003270489,
0.01250481, 0.000192382, 0.000961908, 0.082724125, 0.000577145,
0.025971528, 0.018661023, 0.030011543, 0.013851481, 0.065217391,
0.214313197, 0.108310889, 0.002116199, 0.048095421, 0.000577145,
0.052135437), MDS.L_P7246.1 = c(0.008308003, 0.000202634, 0.006079027,
0.013373858, 0.003039513, 0.002228976, 0.207294805, 0.036068891,
0.002026342, 0.004660587, 0.030800401, 0.008308003, 0.001621074,
0.001621074, 0.000202634, 0.003039513, 0.012563322, 0.000202634,
0.001013171, 0.081458956, 0.000405268, 0.026950351, 0.018034445,
0.030395133, 1.34e-07, 0.065450852, 0.218642321, 0.109017209,
0.002228976, 0.050050652, 0.000810537, 0.053900702), A673_P6591 = c(0.01081944,
0.000354736, 0.008158922, 0.013125222, 0.003015254, 0.003015254,
0.202554097, 0.035118836, 0.002128414, 0.006207875, 0.036183044,
0.006917347, 0.000886839, 0.001596311, 0.000709471, 0.004788932,
0.013657325, 0.000177368, 0.001064207, 0.069882937, 0.000709471,
0.025186236, 0.015253636, 0.029265697, 0.013125222, 0.06385243,
0.207875133, 0.106598084, 0.002305782, 0.056580348, 0.000354736,
0.058531394), A673_P6591.1 = c(0.011204482, 0.000186741, 0.008403361,
0.01363212, 0.003174603, 0.002614379, 0.203361345, 0.036414566,
0.002054155, 0.006162465, 0.036788049, 0.006722689, 0.000933707,
0.001680672, 0.000746965, 0.004668534, 0.01363212, 0.000186741,
0.001120448, 0.069467787, 0.000560224, 0.025957049, 0.014752568,
0.029505135, 0, 0.064239029, 0.212885154, 0.108496732, 0.002427638,
0.05751634, 0.000373483, 0.060130719), K562_P535 = c(0.008616975,
0.000143616, 0.007755278, 0.011202068, 0.002441476, 0.003303174,
0.278471923, 0.038776389, 0.00229786, 0.006031883, 0.033031739,
0.00689358, 0.003159558, 0.00229786, 0.000287233, 0.004164871,
0.012638231, 0.000287233, 0.000574465, 0.090621858, 0.000574465,
0.015941405, 0.009478673, 0.021255206, 0.009909522, 0.047536981,
0.181243717, 0.083871894, 0.002441476, 0.055292259, 0.00114893,
0.0583082), K562_P5494.1 = c(0.008692853, 0.000321957, 0.008692853,
0.012395364, 0.002736639, 0.002736639, 0.212813909, 0.032356729,
0.001448809, 0.004990341, 0.033000644, 0.007405023, 0.001448809,
0.001448809, 0.000160979, 0.004990341, 0.013039279, 0, 0.001126851,
0.074050225, 0.000643915, 0.027849324, 0.01545396, 0.029459111,
0, 0.065035415, 0.216355441, 0.111719253, 0.002092724, 0.051996137,
0.000804894, 0.054732775), K562_P5464.1 = c(0.009412153, 0.000495376,
0.008256275, 0.013705416, 0.002476882, 0.002476882, 0.20673712,
0.032529723, 0.001486129, 0.004788639, 0.034180978, 0.007595773,
0.001155878, 0.001321004, 0.000330251, 0.005284016, 0.012714663,
0.000330251, 0.000990753, 0.073811096, 0.000660502, 0.02823646,
0.016017173, 0.029722589, 0, 0.06489432, 0.217635403, 0.110634082,
0.002146631, 0.052179657, 0.000825627, 0.056968296), K562_P5359.1 = c(0.00740349,
0, 0.005288207, 0.005288207, 0.001057641, 0.003172924, 0.225806452,
0.063987308, 0.003172924, 0.004230566, 0.022739291, 0.005817028,
0.002644104, 0.002644104, 0, 0.003701745, 0.013749339, 0, 0.000528821,
0.099947118, 0, 0.015864622, 0.020095188, 0.037546272, 0, 0.080909572,
0.196192491, 0.090957166, 0.002115283, 0.040719196, 0.000528821,
0.043892121), K562_P5359.2 = c(0.007903056, 0, 0.004741834, 0.006322445,
0.001580611, 0.002107482, 0.223393045, 0.062170706, 0.002634352,
0.004741834, 0.023709168, 0.005795574, 0.002634352, 0.002634352,
0, 0.003688093, 0.014752371, 0, 0, 0.103266596, 0, 0.017386723,
0.021601686, 0.036354057, 0, 0.079030558, 0.192834563, 0.090621707,
0.002107482, 0.042676502, 0.00052687, 0.044783983), K562_P5358.1 = c(0.007462687,
0, 0.00533049, 0.005863539, 0.001599147, 0.003731343, 0.229744136,
0.064498934, 0.003198294, 0.004264392, 0.024520256, 0.005863539,
0.003198294, 0.002132196, 0, 0.003731343, 0.015458422, 0, 0,
0.101812367, 0, 0.015991471, 0.019189765, 0.036247335, 0, 0.077292111,
0.191364606, 0.087953092, 0.002132196, 0.041577825, 0.000533049,
0.045309168), K562_P5358.2 = c(0.006546645, 0, 0.005455537, 0.007637752,
0.001636661, 0.003273322, 0.225859247, 0.063829787, 0.003273322,
0.003818876, 0.024549918, 0.007092199, 0.002182215, 0.002727769,
0, 0.003818876, 0.015275505, 0, 0, 0.106382979, 0, 0.016912166,
0.01745772, 0.038188762, 0, 0.074195308, 0.195853792, 0.089470813,
0.001636661, 0.040370977, 0.000545554, 0.042007638), K562_P5357.1 = c(0.007057546,
0, 0.004885993, 0.00597177, 0.001085776, 0.003257329, 0.231813246,
0.06514658, 0.003257329, 0.004343105, 0.024972856, 0.00597177,
0.003257329, 0.002171553, 0, 0.003800217, 0.014115092, 0, 0,
0.118892508, 0, 0.01194354, 0.016829533, 0.030944625, 0, 0.07383279,
0.184039088, 0.086862106, 0.002171553, 0.049402823, 0.000542888,
0.043431053), K562_P5357.2 = c(0.008086253, 0, 0.003773585, 0.006469003,
0.001617251, 0.003234501, 0.23180593, 0.063072776, 0.003773585,
0.003234501, 0.023180593, 0.005929919, 0.003234501, 0.002695418,
0, 0.003773585, 0.014555256, 0, 0, 0.116442049, 0, 0.01509434,
0.017789757, 0.035579515, 0, 0.071698113, 0.189757412, 0.085714286,
0.002156334, 0.044743935, 0.000539084, 0.042048518), K562_P5356.1 = c(0.006292906,
0, 0.005148741, 0.004576659, 0.001716247, 0.002860412, 0.215675057,
0.070366133, 0.003432494, 0.003432494, 0.025743707, 0.005720824,
0.003432494, 0.002860412, 0, 0.004576659, 0.016018307, 0, 0,
0.127002288, 0, 0.01201373, 0.016590389, 0.03375286, 0, 0.076659039,
0.183638444, 0.086956522, 0.001716247, 0.044622426, 0.000572082,
0.044622426), K562_P5356.2 = c(0.00755814, 0, 0.004069767, 0.004651163,
0.001744186, 0.002325581, 0.21627907, 0.070930233, 0.002906977,
0.004069767, 0.025, 0.005813953, 0.003488372, 0.002906977, 0,
0.004069767, 0.015697674, 0, 0, 0.125581395, 0, 0.013953488,
0.015697674, 0.035465116, 0, 0.073837209, 0.190697674, 0.08372093,
0.001744186, 0.045348837, 0.000581395, 0.041860465), K562_P5355.1 = c(0.009320175,
0, 0.003289474, 0.007675439, 0.001096491, 0.002741228, 0.285087719,
0.059210526, 0.003837719, 0.006030702, 0.023026316, 0.003837719,
0.003837719, 0.003289474, 0, 0.003289474, 0.016995614, 0.000548246,
0, 0.094298246, 0, 0.014254386, 0.012061404, 0.026315789, 0,
0.052631579, 0.175438596, 0.08497807, 0.001096491, 0.057017544,
0.000548246, 0.048245614), K562_P5355.2 = c(0.008210181, 0, 0.004378763,
0.009304871, 0.001094691, 0.002189382, 0.280788177, 0.056376574,
0.003284072, 0.005473454, 0.024630542, 0.004378763, 0.003284072,
0.003284072, 0, 0.004378763, 0.016967707, 0, 0, 0.100164204,
0, 0.014778325, 0.012588944, 0.028461959, 0, 0.053639847, 0.172961138,
0.084838533, 0.001642036, 0.054187192, 0.000547345, 0.048166393
), K562_P5269.1 = c(0.007308161, 0, 0.003045067, 0.007917174,
0.001218027, 0.00365408, 0.228989038, 0.071863581, 0.00365408,
0.004263094, 0.017661389, 0.007308161, 0.002436054, 0.003045067,
0, 0.002436054, 0.017052375, 0, 0, 0.107186358, 0, 0.015834348,
0.020097442, 0.033495737, 0, 0.085261876, 0.18453106, 0.091961023,
0.002436054, 0.040194884, 0.001218027, 0.03593179), K562_P5269.2 = c(0.006234414,
0, 0.00436409, 0.006234414, 0.002493766, 0.002493766, 0.224438903,
0.073566085, 0.003117207, 0.002493766, 0.018703242, 0.006857855,
0.002493766, 0.003117207, 0, 0.001246883, 0.015586035, 0, 0,
0.109725686, 0, 0.015586035, 0.018703242, 0.034289277, 0, 0.082294264,
0.195760598, 0.092892768, 0.003117207, 0.039276808, 0.000623441,
0.034289277), K562_P5268.1 = c(0.004635762, 0, 0.00397351, 0.007284768,
0.001986755, 0.002649007, 0.214569536, 0.071523179, 0.00397351,
0.002649007, 0.01986755, 0.007284768, 0.003311258, 0.003311258,
0, 0.003311258, 0.016556291, 0, 0, 0.104635762, 0, 0.017880795,
0.018543046, 0.039735099, 0, 0.090066225, 0.195364238, 0.091390728,
0.001986755, 0.039735099, 0.000662252, 0.033112583), K562_P5268.2 = c(0.005242464,
0, 0.002621232, 0.00655308, 0.002621232, 0.00327654, 0.216251638,
0.070117955, 0.00327654, 0.00327654, 0.020969856, 0.008519004,
0.002621232, 0.001965924, 0, 0.002621232, 0.018348624, 0, 0,
0.108781127, 0, 0.015727392, 0.020314548, 0.040629096, 0, 0.087811271,
0.190039319, 0.090432503, 0.001965924, 0.040629096, 0.000655308,
0.034731324)), .Names = c("subcellular_location", "HAP1_P5242",
"HAP1.wt_P8255.1", "HAP1.wt_P8255.2", "HAP1.wt_P8254.1", "HAP1.wt_P8254.2",
"HAP1.kd_P8253.1", "HAP1.kd_P8253.2", "HAP1.kd_P8252.1", "HAP1.kd_P8252.2",
"HAP1.kd_P8249.1", "HAP1.kd_P8249.2", "HAP1.kd_P8248.1", "HAP1.kd_P8248.2",
"HAP1.wt_P8247.1", "HAP1.wt_P8247.2", "HAP1.wt_P8246.1", "HAP1.wt_P8246.2",
"HAP1_P7964.1", "MDS_P7246", "MDS.L_P7246.1", "A673_P6591", "A673_P6591.1",
"K562_P535", "K562_P5494.1", "K562_P5464.1", "K562_P5359.1",
"K562_P5359.2", "K562_P5358.1", "K562_P5358.2", "K562_P5357.1",
"K562_P5357.2", "K562_P5356.1", "K562_P5356.2", "K562_P5355.1",
"K562_P5355.2", "K562_P5269.1", "K562_P5269.2", "K562_P5268.1",
"K562_P5268.2"), class = "data.frame", row.names = c(NA, -32L
))
</code>```

Body:
The majority of information I can find on side-by-side stacked barplots deals with instances in where some variable (number of side-by-side bars) are repeated for each variable along the x-axis - see: 1, 2, 3, 4, 5, 6. In these cases they use ggplot with besides=TRUE.

I have a more complex example which I believe will require faceting like these two examples: 7 & 8.

Quick background (for those interested in the why?):
I'm trying to compare the efficiency of a proteomics protocol that enriches for chromatin by comparing to the proportion of nuclear proteins found in the core/whole proteome experiments for 4 cell lines. to do this I used The Human Protein Atlas to annotate proteins by their subcellular location and compare nuclear proteins from chromatin-enrichment to whole-enrichment. However, the chromatin-enrichment protocol was 1D-shotgun while the whole proteome data was 2D-shotgun with 50 fractions. In layman terms this means the whole/core proteome data is a more expensive experiment done at higher coverage. Therefore, it wouldn't make sense to look at absolute proportion though because the overall amount of found proteins would be higher in the whole proteome pull-downs (see figure: absolute protein comparison sketch). To circumvent this issue I divided by the total number of proteins found in each pull-down to get relative proportion of proteins from each subcellular location.

Using these relative proportions I've produced a stacked barplot of the following data in my gist with the following code:

df1 <- read.csv("data.csv") # Load data.frame of the data
df2 <- melt(df1,                                # Reshape the data from
            id.vars = "subcellular_location",   # wide format into long format
            variable.name = "cell_line",        # (i.e. tidy data)
            value.name = "relative_proportion")

For some reason this didn't change the variable name or value name (headers) - they are called "variable" and "value" still? So I had to rename column headers via the following.

names(df2) <- c("subcellular_location", "cell_line", "relative_proportion")

As there are many subcellular locations I needed to custom add colors, furthermore I grouped them by similar locations (e.g. nuclear in blue).

p <- ggplot() +
  geom_bar(aes(x = cell_line, y = percentage, fill = subcellular_location),
           data = df2, stat="identity")

p +
  coord_flip() +
  scale_fill_manual(values = c("#bd5db0","#9ae17c", "#be0024", "#7388ff", "#c456b7",
                               "#8ed470", "#7ec361", "#7d7304", "#f87a00", "#d543c7",
                               "#bead47", "#d148c3", "#da8836", "#e28504", "#d93eca",
                               "#c720b9", "#bc07ae", "#a40098", "#9a008e", "#e8d448",
                               "#104ed7", "#2c4ecc", "#00428c", "#393c6d", "#173b8f",
                               "#3f4c96", "#9ba2f5", "#727bcc", "#e59c5f", "#790000",
                               "#045d00", "#f9ad6f"))

See image here: stacked barplot

The core proteome pull-downs are highlighted in yellow. Ideally what I would like to do is facet this barplot into 4 sections - one for each cell line. I followed the instructions from reference 7 for faceting but am getting an error.

First I split my dataframe into 4 separate tidy dataframes (e.g. below):

K562 <- read.csv("K562-relative.csv")
K562 <- melt(K562, id.vars = "subcellular_location") # Reshape the data into tidy form
names(K562) <- c("subcellular_location", "cell_line", "relative_proportion")

etc.

Than I created a vector for cell line:

cell <- sample(c("HAP1","K562","A673","MDS"))

When I try the following code I get an error:

ref_by_cell <- data.frame(HAP1 = HAP1, K562 = K562, A673 = A673, MDS = MDS, cell = cell)

Error in data.frame(HAP1 = HAP1, K562 = K562, A673 = A673, MDS = MDS,
  arguments imply differing number of rows: 576, 544, 64, 4

I would appreciate any help with faceting or alternative ideas for displaying this information.

Thank you!

Body:
I'm not entirely sure what you want, but if you want to facet by the first part of each cell_line value...

# add faceting variable to df2
df2 <- df2 %>%
  mutate(cell = stringi::stri_extract_first_regex(cell_line, "^[^\\.|_]+"))

# facet by cell, specifying free scales / space on the y-axis
ggplot(data = df2,
       aes(x = cell_line, y = relative_proportion, fill = subcellular_location)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  facet_grid(cell~., scales = "free_y", space = "free_y") +
  scale_fill_manual(values = c("#bd5db0","#9ae17c", "#be0024", "#7388ff", "#c456b7",
                               "#8ed470", "#7ec361", "#7d7304", "#f87a00", "#d543c7",
                               "#bead47", "#d148c3", "#da8836", "#e28504", "#d93eca",
                               "#c720b9", "#bc07ae", "#a40098", "#9a008e", "#e8d448",
                               "#104ed7", "#2c4ecc", "#00428c", "#393c6d", "#173b8f",
                               "#3f4c96", "#9ba2f5", "#727bcc", "#e59c5f", "#790000",
                               "#045d00", "#f9ad6f")) +
  theme_bw() +
  theme(strip.text.y = element_text(angle = 0))

Data (copied from your gist link; next time please use dput so that others can reproduce your example more easily):

> dput(df1)
structure(list(subcellular_location = c("actinFilaments", "aggresome",
"cellJunctions", "centrosome", "cytokineticBridge", "cytoplasmicBodies",
"cytosol", "endoplasmicReticulum", "endosome", "focalAdhesion",
"golgiApparatus", "intermediateFilaments", "lipidDroplets", "lysosomes",
"microtubuleEnds", "microtubuleOrganizingCenter", "microtubules",
"midbodyRing", "midbody", "mitochondria", "mitoticSpindle", "nuclearBodies",
"nuclearMembrane", "nuclearSpeckles", "nucleliFibrallar", "nucleoli",
"nucleoplasm", "nucleus", "peroxisomes", "plasmaMembrane", "rodsAndRings",
"vesicles"), HAP1_P5242 = c(0.009581882, 0.000338753, 0.011033682,
0.015824623, 0.003774681, 0.00232288, 0.227013163, 0.024535424,
0.001258227, 0.005807201, 0.04229578, 0.008710801, 0.0014518,
0.001064654, 0.00029036, 0.006484708, 0.013646922, 0.000483933,
0.001064654, 0.063637244, 0.00087108, 0.02303523, 0.013646922,
0.024535424, 0.013259775, 0.054587689, 0.195509098, 0.101480836,
0.00174216, 0.058072009, 0.000822687, 0.071815718), HAP1.wt_P8255.1 = c(0.0176,
0, 0.0032, 0.0096, 0, 0.0032, 0.3664, 0.0912, 0.008, 0.0032,
0.0128, 0, 0, 0.0064, 0, 0.0032, 0.0288, 0, 0, 0.0528, 0, 0.0128,
0.0048, 0.0096, 0, 0.0496, 0.1552, 0.0576, 0, 0.064, 0.0016,
0.0384), HAP1.wt_P8255.2 = c(0.013179572, 0, 0, 0.008237232,
0, 0.004942339, 0.36738056, 0.098846788, 0.003294893, 0.003294893,
0.016474465, 0.001647446, 0, 0.004942339, 0, 0.003294893, 0.029654036,
0, 0, 0.05107084, 0, 0.009884679, 0.004942339, 0.011532125, 0,
0.044481054, 0.154859967, 0.05601318, 0, 0.064250412, 0.001647446,
0.046128501), HAP1.wt_P8254.1 = c(0.012841091, 0, 0, 0.006420546,
0.001605136, 0.004815409, 0.362760835, 0.08988764, 0.001605136,
0.004815409, 0.017656501, 0.003210273, 0, 0.003210273, 0, 0.004815409,
0.032102729, 0, 0, 0.04975923, 0, 0.011235955, 0.003210273, 0.011235955,
0, 0.04975923, 0.160513644, 0.060995185, 0, 0.069020867, 0.001605136,
0.036918138), HAP1.wt_P8254.2 = c(0.015873016, 0, 0, 0.00952381,
0.001587302, 0.004761905, 0.357142857, 0.103174603, 0.003174603,
0.003174603, 0.014285714, 0.001587302, 0.001587302, 0.003174603,
0, 0.003174603, 0.03015873, 0, 0, 0.055555556, 0, 0.012698413,
0.006349206, 0.012698413, 0, 0.050793651, 0.152380952, 0.063492063,
0, 0.057142857, 0.001587302, 0.034920635), HAP1.kd_P8253.1 = c(0,
0, 0, 0, 0, 0, 0.270270271, 0.027027028, 0, 0, 0.027027028, 0,
0, 0, 0, 0, 0.054054053, 0, 0, 0, 0, 0, 0, 0.054054053, 0, 0.054054053,
0.405405405, 0.027027028, 0, 0, 0, 0.081081081), HAP1.kd_P8253.2 = c(0.021381579,
0, 0.003289474, 0.013157895, 0, 0.003289474, 0.368421053, 0.100328947,
0.004934211, 0.003289474, 0.013157895, 0.003289474, 0, 0.006578947,
0, 0.001644737, 0.027960526, 0, 0, 0.046052632, 0, 0.011513158,
0.004934211, 0.009868421, 0, 0.050986842, 0.15131579, 0.050986842,
0, 0.065789474, 0.001644737, 0.036184211), HAP1.kd_P8252.1 = c(0.018518518,
0, 0.00308642, 0.010802469, 0, 0.00462963, 0.354938272, 0.092592593,
0.00617284, 0.00462963, 0.018518518, 0, 0.00154321, 0.00462963,
0, 0.00617284, 0.026234568, 0, 0, 0.043209877, 0, 0.015432099,
0.00308642, 0.015432099, 0, 0.049382716, 0.154320988, 0.061728395,
0, 0.063271605, 0.00154321, 0.040123457), HAP1.kd_P8252.2 = c(0.012965964,
0, 0, 0.011345219, 0.001620746, 0.003241491, 0.367909238, 0.095623987,
0.003241491, 0.004862237, 0.017828201, 0.003241491, 0, 0.004862237,
0, 0.003241491, 0.030794165, 0, 0, 0.051863857, 0, 0.016207455,
0.003241491, 0.009724473, 0, 0.04376013, 0.1636953, 0.055105348,
0, 0.064829822, 0.001620746, 0.02917342), HAP1.kd_P8249.1 = c(0.010309278,
0.001718213, 0, 0.006872852, 0, 0.005154639, 0.197594502, 0.091065292,
0.001718213, 0, 0.013745704, 0.005154639, 0.001718213, 0.001718213,
0, 0, 0.027491409, 0, 0, 0.054982818, 0, 0.017182131, 0.013745704,
0.060137457, 0, 0.082474227, 0.240549828, 0.094501718, 0, 0.04467354,
0, 0.027491409), HAP1.kd_P8249.2 = c(0.010752688, 0, 0, 0.007168459,
0, 0.003584229, 0.20609319, 0.084229391, 0.001792115, 0, 0.007168459,
0.005376344, 0, 0.001792115, 0, 0, 0.03046595, 0, 0, 0.069892473,
0, 0.019713262, 0.014336918, 0.064516129, 0, 0.08781362, 0.224014337,
0.096774194, 0, 0.039426523, 0, 0.025089606), HAP1.kd_P8248.1 = c(0.007207207,
0, 0.001801802, 0.007207207, 0, 0.003603604, 0.198198198, 0.099099099,
0, 0, 0.009009009, 0.007207207, 0, 0, 0, 0.001801802, 0.025225225,
0, 0, 0.061261261, 0, 0.021621622, 0.016216216, 0.068468468,
0, 0.079279279, 0.234234234, 0.093693694, 0.001801802, 0.028828829,
0, 0.034234234), HAP1.kd_P8248.2 = c(0.005272408, 0.001757469,
0, 0.008787346, 0, 0.005272408, 0.202108963, 0.09314587, 0, 0,
0.014059754, 0.005272408, 0, 0, 0, 0.001757469, 0.029876977,
0, 0, 0.056239016, 0, 0.021089631, 0.014059754, 0.065026362,
0, 0.086115993, 0.228471002, 0.094903339, 0.001757469, 0.036906854,
0, 0.028119508), HAP1.wt_P8247.1 = c(0.016333938, 0, 0, 0.001814882,
0, 0.005444646, 0.197822141, 0.09800363, 0.001814882, 0, 0.007259528,
0.005444646, 0, 0.001814882, 0, 0.001814882, 0.030852995, 0,
0, 0.061705989, 0, 0.021778584, 0.012704174, 0.065335753, 0,
0.087114338, 0.234119782, 0.096188748, 0, 0.029038113, 0, 0.023593466
), HAP1.wt_P8247.2 = c(0.011173184, 0, 0, 0.003724395, 0, 0.003724395,
0.197392924, 0.098696462, 0.001862197, 0, 0.009310987, 0.005586592,
0, 0.001862197, 0, 0.001862197, 0.029795158, 0, 0, 0.059590317,
0, 0.018621974, 0.013035382, 0.067039106, 0, 0.08566108, 0.240223464,
0.096834264, 0, 0.029795158, 0, 0.024208566), HAP1.wt_P8246.1 = c(0.008880995,
0, 0, 0.005328597, 0.003552398, 0.003552398, 0.195381883, 0.090586146,
0, 0, 0.005328597, 0.008880995, 0, 0, 0, 0.001776199, 0.030195382,
0, 0, 0.051509769, 0, 0.023090586, 0.01598579, 0.063943162, 0,
0.097690941, 0.245115453, 0.097690941, 0, 0.026642984, 0, 0.024866785
), HAP1.wt_P8246.2 = c(0.009025271, 0, 0.001805054, 0.005415162,
0, 0.003610108, 0.19133574, 0.088447653, 0, 0.001805054, 0.012635379,
0.007220217, 0, 0, 0, 0, 0.028880866, 0, 0, 0.048736462, 0, 0.019855596,
0.027075812, 0.066787004, 0, 0.084837545, 0.241877256, 0.09566787,
0, 0.028880866, 0, 0.036101083), HAP1_P7964.1 = c(0.010040907,
0, 0.007437709, 0.017106731, 0.002975084, 0.003346969, 0.211230941,
0.040535515, 0.002603198, 0.005950167, 0.023056898, 0.00818148,
0.001115656, 0.002231313, 0.000743771, 0.005950167, 0.014503533,
0, 0.000743771, 0.065451841, 0.001115656, 0.023056898, 0.018966158,
0.031610264, 0, 0.065451841, 0.223875046, 0.105243585, 0.002603198,
0.051692079, 0.001487542, 0.051692079), MDS_P7246 = c(0.008080031,
0.000384763, 0.005386687, 0.012889573, 0.002885725, 0.002500962,
0.204116968, 0.035013467, 0.002116199, 0.00461716, 0.030973451,
0.008272412, 0.001539053, 0.001539053, 0.000192382, 0.003270489,
0.01250481, 0.000192382, 0.000961908, 0.082724125, 0.000577145,
0.025971528, 0.018661023, 0.030011543, 0.013851481, 0.065217391,
0.214313197, 0.108310889, 0.002116199, 0.048095421, 0.000577145,
0.052135437), MDS.L_P7246.1 = c(0.008308003, 0.000202634, 0.006079027,
0.013373858, 0.003039513, 0.002228976, 0.207294805, 0.036068891,
0.002026342, 0.004660587, 0.030800401, 0.008308003, 0.001621074,
0.001621074, 0.000202634, 0.003039513, 0.012563322, 0.000202634,
0.001013171, 0.081458956, 0.000405268, 0.026950351, 0.018034445,
0.030395133, 1.34e-07, 0.065450852, 0.218642321, 0.109017209,
0.002228976, 0.050050652, 0.000810537, 0.053900702), A673_P6591 = c(0.01081944,
0.000354736, 0.008158922, 0.013125222, 0.003015254, 0.003015254,
0.202554097, 0.035118836, 0.002128414, 0.006207875, 0.036183044,
0.006917347, 0.000886839, 0.001596311, 0.000709471, 0.004788932,
0.013657325, 0.000177368, 0.001064207, 0.069882937, 0.000709471,
0.025186236, 0.015253636, 0.029265697, 0.013125222, 0.06385243,
0.207875133, 0.106598084, 0.002305782, 0.056580348, 0.000354736,
0.058531394), A673_P6591.1 = c(0.011204482, 0.000186741, 0.008403361,
0.01363212, 0.003174603, 0.002614379, 0.203361345, 0.036414566,
0.002054155, 0.006162465, 0.036788049, 0.006722689, 0.000933707,
0.001680672, 0.000746965, 0.004668534, 0.01363212, 0.000186741,
0.001120448, 0.069467787, 0.000560224, 0.025957049, 0.014752568,
0.029505135, 0, 0.064239029, 0.212885154, 0.108496732, 0.002427638,
0.05751634, 0.000373483, 0.060130719), K562_P535 = c(0.008616975,
0.000143616, 0.007755278, 0.011202068, 0.002441476, 0.003303174,
0.278471923, 0.038776389, 0.00229786, 0.006031883, 0.033031739,
0.00689358, 0.003159558, 0.00229786, 0.000287233, 0.004164871,
0.012638231, 0.000287233, 0.000574465, 0.090621858, 0.000574465,
0.015941405, 0.009478673, 0.021255206, 0.009909522, 0.047536981,
0.181243717, 0.083871894, 0.002441476, 0.055292259, 0.00114893,
0.0583082), K562_P5494.1 = c(0.008692853, 0.000321957, 0.008692853,
0.012395364, 0.002736639, 0.002736639, 0.212813909, 0.032356729,
0.001448809, 0.004990341, 0.033000644, 0.007405023, 0.001448809,
0.001448809, 0.000160979, 0.004990341, 0.013039279, 0, 0.001126851,
0.074050225, 0.000643915, 0.027849324, 0.01545396, 0.029459111,
0, 0.065035415, 0.216355441, 0.111719253, 0.002092724, 0.051996137,
0.000804894, 0.054732775), K562_P5464.1 = c(0.009412153, 0.000495376,
0.008256275, 0.013705416, 0.002476882, 0.002476882, 0.20673712,
0.032529723, 0.001486129, 0.004788639, 0.034180978, 0.007595773,
0.001155878, 0.001321004, 0.000330251, 0.005284016, 0.012714663,
0.000330251, 0.000990753, 0.073811096, 0.000660502, 0.02823646,
0.016017173, 0.029722589, 0, 0.06489432, 0.217635403, 0.110634082,
0.002146631, 0.052179657, 0.000825627, 0.056968296), K562_P5359.1 = c(0.00740349,
0, 0.005288207, 0.005288207, 0.001057641, 0.003172924, 0.225806452,
0.063987308, 0.003172924, 0.004230566, 0.022739291, 0.005817028,
0.002644104, 0.002644104, 0, 0.003701745, 0.013749339, 0, 0.000528821,
0.099947118, 0, 0.015864622, 0.020095188, 0.037546272, 0, 0.080909572,
0.196192491, 0.090957166, 0.002115283, 0.040719196, 0.000528821,
0.043892121), K562_P5359.2 = c(0.007903056, 0, 0.004741834, 0.006322445,
0.001580611, 0.002107482, 0.223393045, 0.062170706, 0.002634352,
0.004741834, 0.023709168, 0.005795574, 0.002634352, 0.002634352,
0, 0.003688093, 0.014752371, 0, 0, 0.103266596, 0, 0.017386723,
0.021601686, 0.036354057, 0, 0.079030558, 0.192834563, 0.090621707,
0.002107482, 0.042676502, 0.00052687, 0.044783983), K562_P5358.1 = c(0.007462687,
0, 0.00533049, 0.005863539, 0.001599147, 0.003731343, 0.229744136,
0.064498934, 0.003198294, 0.004264392, 0.024520256, 0.005863539,
0.003198294, 0.002132196, 0, 0.003731343, 0.015458422, 0, 0,
0.101812367, 0, 0.015991471, 0.019189765, 0.036247335, 0, 0.077292111,
0.191364606, 0.087953092, 0.002132196, 0.041577825, 0.000533049,
0.045309168), K562_P5358.2 = c(0.006546645, 0, 0.005455537, 0.007637752,
0.001636661, 0.003273322, 0.225859247, 0.063829787, 0.003273322,
0.003818876, 0.024549918, 0.007092199, 0.002182215, 0.002727769,
0, 0.003818876, 0.015275505, 0, 0, 0.106382979, 0, 0.016912166,
0.01745772, 0.038188762, 0, 0.074195308, 0.195853792, 0.089470813,
0.001636661, 0.040370977, 0.000545554, 0.042007638), K562_P5357.1 = c(0.007057546,
0, 0.004885993, 0.00597177, 0.001085776, 0.003257329, 0.231813246,
0.06514658, 0.003257329, 0.004343105, 0.024972856, 0.00597177,
0.003257329, 0.002171553, 0, 0.003800217, 0.014115092, 0, 0,
0.118892508, 0, 0.01194354, 0.016829533, 0.030944625, 0, 0.07383279,
0.184039088, 0.086862106, 0.002171553, 0.049402823, 0.000542888,
0.043431053), K562_P5357.2 = c(0.008086253, 0, 0.003773585, 0.006469003,
0.001617251, 0.003234501, 0.23180593, 0.063072776, 0.003773585,
0.003234501, 0.023180593, 0.005929919, 0.003234501, 0.002695418,
0, 0.003773585, 0.014555256, 0, 0, 0.116442049, 0, 0.01509434,
0.017789757, 0.035579515, 0, 0.071698113, 0.189757412, 0.085714286,
0.002156334, 0.044743935, 0.000539084, 0.042048518), K562_P5356.1 = c(0.006292906,
0, 0.005148741, 0.004576659, 0.001716247, 0.002860412, 0.215675057,
0.070366133, 0.003432494, 0.003432494, 0.025743707, 0.005720824,
0.003432494, 0.002860412, 0, 0.004576659, 0.016018307, 0, 0,
0.127002288, 0, 0.01201373, 0.016590389, 0.03375286, 0, 0.076659039,
0.183638444, 0.086956522, 0.001716247, 0.044622426, 0.000572082,
0.044622426), K562_P5356.2 = c(0.00755814, 0, 0.004069767, 0.004651163,
0.001744186, 0.002325581, 0.21627907, 0.070930233, 0.002906977,
0.004069767, 0.025, 0.005813953, 0.003488372, 0.002906977, 0,
0.004069767, 0.015697674, 0, 0, 0.125581395, 0, 0.013953488,
0.015697674, 0.035465116, 0, 0.073837209, 0.190697674, 0.08372093,
0.001744186, 0.045348837, 0.000581395, 0.041860465), K562_P5355.1 = c(0.009320175,
0, 0.003289474, 0.007675439, 0.001096491, 0.002741228, 0.285087719,
0.059210526, 0.003837719, 0.006030702, 0.023026316, 0.003837719,
0.003837719, 0.003289474, 0, 0.003289474, 0.016995614, 0.000548246,
0, 0.094298246, 0, 0.014254386, 0.012061404, 0.026315789, 0,
0.052631579, 0.175438596, 0.08497807, 0.001096491, 0.057017544,
0.000548246, 0.048245614), K562_P5355.2 = c(0.008210181, 0, 0.004378763,
0.009304871, 0.001094691, 0.002189382, 0.280788177, 0.056376574,
0.003284072, 0.005473454, 0.024630542, 0.004378763, 0.003284072,
0.003284072, 0, 0.004378763, 0.016967707, 0, 0, 0.100164204,
0, 0.014778325, 0.012588944, 0.028461959, 0, 0.053639847, 0.172961138,
0.084838533, 0.001642036, 0.054187192, 0.000547345, 0.048166393
), K562_P5269.1 = c(0.007308161, 0, 0.003045067, 0.007917174,
0.001218027, 0.00365408, 0.228989038, 0.071863581, 0.00365408,
0.004263094, 0.017661389, 0.007308161, 0.002436054, 0.003045067,
0, 0.002436054, 0.017052375, 0, 0, 0.107186358, 0, 0.015834348,
0.020097442, 0.033495737, 0, 0.085261876, 0.18453106, 0.091961023,
0.002436054, 0.040194884, 0.001218027, 0.03593179), K562_P5269.2 = c(0.006234414,
0, 0.00436409, 0.006234414, 0.002493766, 0.002493766, 0.224438903,
0.073566085, 0.003117207, 0.002493766, 0.018703242, 0.006857855,
0.002493766, 0.003117207, 0, 0.001246883, 0.015586035, 0, 0,
0.109725686, 0, 0.015586035, 0.018703242, 0.034289277, 0, 0.082294264,
0.195760598, 0.092892768, 0.003117207, 0.039276808, 0.000623441,
0.034289277), K562_P5268.1 = c(0.004635762, 0, 0.00397351, 0.007284768,
0.001986755, 0.002649007, 0.214569536, 0.071523179, 0.00397351,
0.002649007, 0.01986755, 0.007284768, 0.003311258, 0.003311258,
0, 0.003311258, 0.016556291, 0, 0, 0.104635762, 0, 0.017880795,
0.018543046, 0.039735099, 0, 0.090066225, 0.195364238, 0.091390728,
0.001986755, 0.039735099, 0.000662252, 0.033112583), K562_P5268.2 = c(0.005242464,
0, 0.002621232, 0.00655308, 0.002621232, 0.00327654, 0.216251638,
0.070117955, 0.00327654, 0.00327654, 0.020969856, 0.008519004,
0.002621232, 0.001965924, 0, 0.002621232, 0.018348624, 0, 0,
0.108781127, 0, 0.015727392, 0.020314548, 0.040629096, 0, 0.087811271,
0.190039319, 0.090432503, 0.001965924, 0.040629096, 0.000655308,
0.034731324)), .Names = c("subcellular_location", "HAP1_P5242",
"HAP1.wt_P8255.1", "HAP1.wt_P8255.2", "HAP1.wt_P8254.1", "HAP1.wt_P8254.2",
"HAP1.kd_P8253.1", "HAP1.kd_P8253.2", "HAP1.kd_P8252.1", "HAP1.kd_P8252.2",
"HAP1.kd_P8249.1", "HAP1.kd_P8249.2", "HAP1.kd_P8248.1", "HAP1.kd_P8248.2",
"HAP1.wt_P8247.1", "HAP1.wt_P8247.2", "HAP1.wt_P8246.1", "HAP1.wt_P8246.2",
"HAP1_P7964.1", "MDS_P7246", "MDS.L_P7246.1", "A673_P6591", "A673_P6591.1",
"K562_P535", "K562_P5494.1", "K562_P5464.1", "K562_P5359.1",
"K562_P5359.2", "K562_P5358.1", "K562_P5358.2", "K562_P5357.1",
"K562_P5357.2", "K562_P5356.1", "K562_P5356.2", "K562_P5355.1",
"K562_P5355.2", "K562_P5269.1", "K562_P5269.2", "K562_P5268.1",
"K562_P5268.2"), class = "data.frame", row.names = c(NA, -32L
))


问:
Add style from external scss file to SVG.js element
I create a svg and add a path to it with SVG.js as follow.

```<code>this.roomPlan = SVG('roomPlan').attr('id','roomPlanSvg').size(1024,
768);
this.roomPlan.path(room.area.d);
</code>```

I have a external .scss file and I have some style as follow;

```<code>.room-bg {
  fill: nb-theme(card-bg);
  stroke: transparent;
  cursor: pointer;
  stroke-width: 4px;
}
</code>```

I want to add .room-bg selector to my path element as class like other html.
for example ;

```<code><path class="room-bg" />
</code>```

Note: I'm developing Angular2-Typescript app and I add SVG.js to project as npm package.

Thanks for helps.

答:
You should just be able to do:

```<code>this.roomPlan.path(room.area.d).addClass("room-bg");
</code>```

See: [http://svgjs.dev/manipulating/#addclass]

Body:
I create a svg and add a path to it with SVG.js as follow.

this.roomPlan = SVG('roomPlan').attr('id','roomPlanSvg').size(1024,
768);
this.roomPlan.path(room.area.d);

I have a external .scss file and I have some style as follow;

.room-bg {
  fill: nb-theme(card-bg);
  stroke: transparent;
  cursor: pointer;
  stroke-width: 4px;
}

I want to add .room-bg selector to my path element as class like other html.
for example ;

<path class="room-bg" />

Note: I'm developing Angular2-Typescript app and I add SVG.js to project as npm package.

Thanks for helps.

Body:
You should just be able to do:

this.roomPlan.path(room.area.d).addClass("room-bg");

See: [http://svgjs.dev/manipulating/#addclass]

ContentLicense: CC BY-SA 4.0


问:
Multi step transaction in hibernate
Am facing few issues with multi step transction in hibernate. This is what I am doing.

One of my DAO methods

Creates a new record in Table A and retrieves the Oracle generated Primary key.

Updates a row in Table B with the Primary key retrieved in step 1

The code looks something like this:

```<code>@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public Object myDAOMethos(...){
    ....
    getHibernateTemplate().execute(
new HibernateCallback<Long>() {
 public Long doInHibernate(Session session)
   throws HibernateException, SQLException {
  // Create a new record in table A
  session.save(objA);

  final long pKey = objA.getId();

  // Update the row in table B
  org.hibernate.Query query = session
      .getNamedQuery("updateBQuery").setLong("idB",pKey...
   query.executeUpdate();
   }
  }
  return true;
 }
});
}
</code>```

The method is bound under a transction.

My issue:
Everything works fine when I run this code on tomcat. But when i try to exeute a junit test case for this, the update on table B never takes place. Although I can see the update SQL on the console output (hibernate.show_sql=true). No exceptions either! just the insert takes place and thats it.

Not sure what is happening here! any ideas!?

regards,
-J

答:
thanks for the reply. you are right.

While you would be posting this answer, I realized wht the problem was and tried that, worked!!

It is the point 2 in your post. Basicallly the junit test case itself uses "AbstractTransactionalJUnit4SpringContextTests" and manages the DB commit/rollback after the test via @Rollback. So basically, the data which I was trying to update was not created in the first place. Am still surprized that I didnt not see any errors on the console!!

Am accepting your answer as the right one. Thanks a ton!

-J

ContentLicense: CC BY-SA 2.5

Title: Multi step transaction in hibernate

Body:
Am facing few issues with multi step transction in hibernate. This is what I am doing.

One of my DAO methods

Creates a new record in Table A and retrieves the Oracle generated Primary key.

Updates a row in Table B with the Primary key retrieved in step 1

The code looks something like this:

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public Object myDAOMethos(...){
    ....
    getHibernateTemplate().execute(
new HibernateCallback<Long>() {
 public Long doInHibernate(Session session)
   throws HibernateException, SQLException {
  // Create a new record in table A
  session.save(objA);

  final long pKey = objA.getId();

  // Update the row in table B
  org.hibernate.Query query = session
      .getNamedQuery("updateBQuery").setLong("idB",pKey...
   query.executeUpdate();
   }
  }
  return true;
 }
});
}

The method is bound under a transction.

My issue:
Everything works fine when I run this code on tomcat. But when i try to exeute a junit test case for this, the update on table B never takes place. Although I can see the update SQL on the console output (hibernate.show_sql=true). No exceptions either! just the insert takes place and thats it.

Not sure what is happening here! any ideas!?

regards,
-J


问:
MathNet.Filtering Bandpass parameters
I'm trying to use MathNet filters to apply a band pass filter to a signal; I'm using the MathNet.Filtering.OnlineFiter.CreateBandpass(..) method, to be precise.

The problem is, I'm not getting the expected results and I'm getting confused by the method's parameters. I've got a signal sampled at 1Khz, and I want to remove everything outside the 4 to 6 Hz range. What is the correct way to call the method CreateBandpass(..)?

Edit

This is the code, as requested in a comment:

```<code>OnlineFilter bandPass = CreateBandpass(ImpulseResponse.Finite, samplingRate, 3, 7);
postProcessedData = bandPass.ProcessSamples(preProcessedData);
</code>```

The source is a sinewave at exactly 5 Hz with some relatively high frequency noise (like 30-70 hz); the amplitude of the signal is around 20 peak-peak, centred at 0 (so -10 to +10). The filtered signal is a sinewave at 5 Hz with no noise and an amplitude, peak-peak, of 2.1

P.S.

This happens too with a test wave, by the way. If a generate a pure sinewave (whatever the frequency) and filter it around its frequency, I obtain a sinewave of the same frequency and a totally unrelated amplitude. On the other hand if I FFT (still using MathNet) the wave and remove the components I'm not interested into, I can then rebuild the wave at the expected amplitude and totally clean from noise.

答:
If your signal is at 5Hz and your noise at 30-70Hz, you don't really need a bandpass filter, a lowpass will do it. Also, some attenuation is expected, although in your case is a little excessive, and the reason is... your filter is too narrow. Either use a lowpass with cutoff frequency of, let's say 10Hz, or a bandpass with low/high cutoff of 0-10Hz. The sample below shows a comparison between these options. Notice that, not surprisingly, the lowpass and bandpass filter results, with the same 10Hz bandwidth, are an exact match, as expected.

```<code>    //signal + noise
    double fs = 1000; //sampling rate
    double fw = 5; //signal frequency
    double fn = 50; //noise frequency
    double n = 5; //number of periods to show
    double A = 10; //signal amplitude
    double N = 1; //noise amplitude
    int size = (int)(n * fs / fw); //sample size

    var t = Enumerable.Range(1, size).Select(p => p * 1 / fs).ToArray();
    var y = t.Select(p => (A * Math.Sin(2 * pi * fw * p)) + (N * Math.Sin(2 * pi * fn * p))).ToArray(); //Original

    //lowpass filter
    double fc = 10; //cutoff frequency
    var lowpass = OnlineFirFilter.CreateLowpass(ImpulseResponse.Finite, fs, fc);

    //bandpass filter
    double fc1 = 0; //low cutoff frequency
    double fc2 = 10; //high cutoff frequency
    var bandpass = OnlineFirFilter.CreateBandpass(ImpulseResponse.Finite, fs, fc1, fc2);

    //narrow bandpass filter
    fc1 = 3; //low cutoff frequency
    fc2 = 7; //high cutoff frequency
    var bandpassnarrow = OnlineFirFilter.CreateBandpass(ImpulseResponse.Finite, fs, fc1, fc2);

    double[] yf1 = lowpass.ProcessSamples(y); //Lowpass
    double[] yf2 = bandpass.ProcessSamples(y); //Bandpass
    double[] yf3 = bandpassnarrow.ProcessSamples(y); //Bandpass Narrow
</code>```

Title: MathNet.Filtering Bandpass parameters

Body:
I'm trying to use MathNet filters to apply a band pass filter to a signal; I'm using the MathNet.Filtering.OnlineFiter.CreateBandpass(..) method, to be precise.

The problem is, I'm not getting the expected results and I'm getting confused by the method's parameters. I've got a signal sampled at 1Khz, and I want to remove everything outside the 4 to 6 Hz range. What is the correct way to call the method CreateBandpass(..)?

Edit

This is the code, as requested in a comment:

OnlineFilter bandPass = CreateBandpass(ImpulseResponse.Finite, samplingRate, 3, 7);
postProcessedData = bandPass.ProcessSamples(preProcessedData);

The source is a sinewave at exactly 5 Hz with some relatively high frequency noise (like 30-70 hz); the amplitude of the signal is around 20 peak-peak, centred at 0 (so -10 to +10). The filtered signal is a sinewave at 5 Hz with no noise and an amplitude, peak-peak, of 2.1

P.S.

This happens too with a test wave, by the way. If a generate a pure sinewave (whatever the frequency) and filter it around its frequency, I obtain a sinewave of the same frequency and a totally unrelated amplitude. On the other hand if I FFT (still using MathNet) the wave and remove the components I'm not interested into, I can then rebuild the wave at the expected amplitude and totally clean from noise.

Body:
If your signal is at 5Hz and your noise at 30-70Hz, you don't really need a bandpass filter, a lowpass will do it. Also, some attenuation is expected, although in your case is a little excessive, and the reason is... your filter is too narrow. Either use a lowpass with cutoff frequency of, let's say 10Hz, or a bandpass with low/high cutoff of 0-10Hz. The sample below shows a comparison between these options. Notice that, not surprisingly, the lowpass and bandpass filter results, with the same 10Hz bandwidth, are an exact match, as expected.

    //signal + noise
    double fs = 1000; //sampling rate
    double fw = 5; //signal frequency
    double fn = 50; //noise frequency
    double n = 5; //number of periods to show
    double A = 10; //signal amplitude
    double N = 1; //noise amplitude
    int size = (int)(n * fs / fw); //sample size

    var t = Enumerable.Range(1, size).Select(p => p * 1 / fs).ToArray();
    var y = t.Select(p => (A * Math.Sin(2 * pi * fw * p)) + (N * Math.Sin(2 * pi * fn * p))).ToArray(); //Original

    //lowpass filter
    double fc = 10; //cutoff frequency
    var lowpass = OnlineFirFilter.CreateLowpass(ImpulseResponse.Finite, fs, fc);

    //bandpass filter
    double fc1 = 0; //low cutoff frequency
    double fc2 = 10; //high cutoff frequency
    var bandpass = OnlineFirFilter.CreateBandpass(ImpulseResponse.Finite, fs, fc1, fc2);

    //narrow bandpass filter
    fc1 = 3; //low cutoff frequency
    fc2 = 7; //high cutoff frequency
    var bandpassnarrow = OnlineFirFilter.CreateBandpass(ImpulseResponse.Finite, fs, fc1, fc2);

    double[] yf1 = lowpass.ProcessSamples(y); //Lowpass
    double[] yf2 = bandpass.ProcessSamples(y); //Bandpass
    double[] yf3 = bandpassnarrow.ProcessSamples(y); //Bandpass Narrow


问:
insert data in dynamic table
i am usginf this but getting error can u provide a solution.</p>

```<code>DECLARE @TableName VARCHAR(500);
SET @TableName = N'CREATE TABLE businessmaster_'+
                 CONVERT(VARCHAR(10),GetDate()-1,112)+
                 N' ( contentid int,Businessname varchar(50) )';
print @TableName

  declare  @sql varchar(100)

  SET @sql = 'INSERT INTO'+ @TableName+' (contentid,Businessname) SELECT top 10 contentid,Businessname FROM businessmaster';
EXEC (@sql);
</code>```

答:
You did not create your table, how can you insert data to table not exist:

```<code>DECLARE @TableName VARCHAR(MAX);
DECLARE @SQL NVARCHAR(MAX);
SET @TableName = N'businessmaster_'+
                 CONVERT(VARCHAR(10),GetDate()-1,112);

SET @SQL = N' CREATE TABLE '+@TableName + N' ( contentid int,Businessname varchar(50) )';

EXECUTE (@SQL);

SET @SQL = 'INSERT INTO '+ @TableName+' (contentid,Businessname) SELECT top 10 contentid,Businessname FROM businessmaster';

EXECUTE (@SQL);
</code>```

Demo.

Title: insert data in dynamic table

Body:
i am usginf this but getting error can u provide a solution.

DECLARE @TableName VARCHAR(500);
SET @TableName = N'CREATE TABLE businessmaster_'+
                 CONVERT(VARCHAR(10),GetDate()-1,112)+
                 N' ( contentid int,Businessname varchar(50) )';
print @TableName

  declare  @sql varchar(100)

  SET @sql = 'INSERT INTO'+ @TableName+' (contentid,Businessname) SELECT top 10 contentid,Businessname FROM businessmaster';
EXEC (@sql);

Body:
You did not create your table, how can you insert data to table not exist:

DECLARE @TableName VARCHAR(MAX);
DECLARE @SQL NVARCHAR(MAX);
SET @TableName = N'businessmaster_'+
                 CONVERT(VARCHAR(10),GetDate()-1,112);

SET @SQL = N' CREATE TABLE '+@TableName + N' ( contentid int,Businessname varchar(50) )';

EXECUTE (@SQL);

SET @SQL = 'INSERT INTO '+ @TableName+' (contentid,Businessname) SELECT top 10 contentid,Businessname FROM businessmaster';

EXECUTE (@SQL);

Demo.


问:
Visual Studio 2008 unit testing using the same file resource
I am using the built-in unit testing framework of Visual Studio 2008 to get my feet wet with TDD of a C# WinForms application. The application works with proprietary image data formats and I've broken up sample files into their component sections (header, metadata, single frames, all frames, etc) to allow for testing. Several of my test methods use the same data chunk and when I choose the 'Run All Tests in Solution' option, the tests using the same data chunk fail with "System.IO.IOException: The process cannot access the file 'datachunk.dat' because it is being used by another process." These tests pass when they are run individually. Is there a way I can tell Visual Studio not to try and run these tests at the same time or am I going about this the wrong way?</p>

答:
Use the intialize method to load the "chunk" before the tests need it. You can then reuse the same "chunk" over and over, across tests.

You can also encapsulate the logic into its own method and ensure you destroy the reader between hits on the method.

Peace and Grace,
Gregory A. Beamer


问:
Separating Android.mk file for each flavor
I’m using Android Studio and Gradle.

There are some flavors that having a little differrent views and features.

So, for each flavor, I want to switch Android.mk1 file.

ex)

flavorA -> Android_flavorA.mk

flavorB -> Android_flavorB.mk

but, in externalNativeBuild and ndkBuild block, couldn’t dynamically change a path of Android.mk.

Anybody know about this?

答:
Rather than having separate makefiles you could pass the product flavor to your makefile:

In app/build.gradle:

```<code>productFlavors {
    flavor1 {
        externalNativeBuild {
            ndkBuild {
                arguments "PRODUCT_FLAVOR=flavor1"
            }
        }
    }
    # etc...
}
</code>```

In Android.mk:

```<code>ifeq (flavor1,$(PRODUCT_FLAVOR))
    # Do flavor-specific stuff
endif
</code>```

I suppose the Do flavor-specific stuff-part could be an include if your flavor-specific parts are very large.

Body:
Rather than having separate makefiles you could pass the product flavor to your makefile:

In app/build.gradle:

productFlavors {
    flavor1 {
        externalNativeBuild {
            ndkBuild {
                arguments "PRODUCT_FLAVOR=flavor1"
            }
        }
    }
    # etc...
}

In Android.mk:

ifeq (flavor1,$(PRODUCT_FLAVOR))
    # Do flavor-specific stuff
endif

I suppose the Do flavor-specific stuff-part could be an include if your flavor-specific parts are very large.


问:
Make change for n dollars with m coins
I'm trying to implement a solution to the following problem:

Given a number of dollars, n, and a list of dollar values for m
distinct coins, find and print the number of different ways you can
make change for n dollars if each coin is available in an infinite
quantity.

The complete problem statement is here

Before presenting my solution, I should say that I know dynamic programming is probably the optimal way to solve this problem. The solution I've come up with does not use dynamic programming, and I know it is far from the most efficient solution out there. However, as far as I can tell it is correct.

The problem is that my solution underestimates the number of ways to make change. For example given n = 75 and {25 10 11 29 49 31 33 39 12 36 40 22 21 16 37 8 18 4 27 17 26 32 6 38 2 30 34} as coin values, the solution returns 182 when it should return 16694. It seems to work for smaller test cases, though.

```<code>def make_change(coins, n):
    solns = 0
    num_coins = len(coins)
    for i in range(num_coins):
        solns = solns + make_change_rec(coins, n-coins[0], coins[0])

        # We've found all solutions involving coin. Remove it
        # from consideration
        coins.pop(0)

    return solns

def make_change_rec(coins, n, parent):
    # If n == 0 we've found a solution
    if n == 0:
        return 1

    solns = 0
    # For each coin
    for coin in coins:
        # If coin > n, can't make change using coin
        if coin > n or coin < parent: # coin < parent rule ensures we don't count same solution twice
            continue

        # Use the coin to make change
        solns = solns + make_change_rec(coins, n-coin, coin)

    return solns
</code>```

Can someone help me understand what I'm doing wrong? I'm using Python 3.

答:
You need to sort your coins before you input them.  If your recursion runs slow for larger values (which it will) you can add memoization like this:</p>

```<code>from functools import lru_cache

#leave your function as it is, but add this:
@lru_cache(maxsize=None)
def make_change_rec(coins, n, parent):
</code>```

Title: Make change for n dollars with m coins

Body:
I'm trying to implement a solution to the following problem:

Given a number of dollars, n, and a list of dollar values for m
distinct coins, find and print the number of different ways you can
make change for n dollars if each coin is available in an infinite
quantity.

The complete problem statement is here

Before presenting my solution, I should say that I know dynamic programming is probably the optimal way to solve this problem. The solution I've come up with does not use dynamic programming, and I know it is far from the most efficient solution out there. However, as far as I can tell it is correct.

The problem is that my solution underestimates the number of ways to make change. For example given n = 75 and {25 10 11 29 49 31 33 39 12 36 40 22 21 16 37 8 18 4 27 17 26 32 6 38 2 30 34} as coin values, the solution returns 182 when it should return 16694. It seems to work for smaller test cases, though.

def make_change(coins, n):
    solns = 0
    num_coins = len(coins)
    for i in range(num_coins):
        solns = solns + make_change_rec(coins, n-coins[0], coins[0])

        # We've found all solutions involving coin. Remove it
        # from consideration
        coins.pop(0)

    return solns

def make_change_rec(coins, n, parent):
    # If n == 0 we've found a solution
    if n == 0:
        return 1

    solns = 0
    # For each coin
    for coin in coins:
        # If coin > n, can't make change using coin
        if coin > n or coin < parent: # coin < parent rule ensures we don't count same solution twice
            continue

        # Use the coin to make change
        solns = solns + make_change_rec(coins, n-coin, coin)

    return solns

Can someone help me understand what I'm doing wrong? I'm using Python 3.

Body:
You need to sort your coins before you input them.  If your recursion runs slow for larger values (which it will) you can add memoization like this:

from functools import lru_cache

#leave your function as it is, but add this:
@lru_cache(maxsize=None)
def make_change_rec(coins, n, parent):


问:
Azure Automation or Azure Function when creating an Azure SQL database
We are creating a SaaS application, where each client has it's own database.  I would like to automate the creation of the clients environment, which will be triggered from our website.

I am investigating using either Azure Automation or Azure Functions to create our client databases.

If anyone has some experience with these tools, I would appreciate your input.

Regards
Remeez

答:
If the databases will have the same schema for all customers, you can have an empty database that works as a template, and then issue a CREATE DATABASE AS COPY specifying the tier of the new database.

```<code>CREATE DATABASE db_copy
    AS COPY OF ozabzw7545.db_original ( SERVICE_OBJECTIVE = 'P2' )  ;
</code>```

Consider using elastic pools which have elastic jobs than can later help you automate common tasks on all customer databases. With elastic pools you can create copies of databases also.

```<code>CREATE DATABASE db_copy
    AS COPY OF ozabzw7545.db_original
    (SERVICE_OBJECTIVE = ELASTIC_POOL( name = ep1 ) ) ;
</code>```

You can also create a database or a copy of a database using REST API as explained here.

Body:
If the databases will have the same schema for all customers, you can have an empty database that works as a template, and then issue a CREATE DATABASE AS COPY specifying the tier of the new database.

CREATE DATABASE db_copy
    AS COPY OF ozabzw7545.db_original ( SERVICE_OBJECTIVE = 'P2' )  ;

Consider using elastic pools which have elastic jobs than can later help you automate common tasks on all customer databases. With elastic pools you can create copies of databases also.

CREATE DATABASE db_copy
    AS COPY OF ozabzw7545.db_original
    (SERVICE_OBJECTIVE = ELASTIC_POOL( name = ep1 ) ) ;

You can also create a database or a copy of a database using REST API as explained here.


问:
How to set same EditText length (width) for all languages on all devices?
In my app, I set the maximum length for an EditText as 30. This is fine when I input English. However, when I type Chinese, I can type 30 characters as well. The Chinese character doubles the width of an English character. The width of the EditText also doubles in comparison to when I type English. This is not what I want.

How can I set 30 English characters as the maximum? When user types in a different language, the width of the EditText can't go beyond when it has 30 English characters. Thanks

答:
try this code:

```<code>String language = Locale.getDefault().getDisplayLanguage().toString();

 if(language.equals(en) {

 // use set filter to limit input length in the edit text for english.
 int maxLength = 30;
 editText.setFilters(new InputFilter[] {new
 InputFilter.LengthFilter(maxLength)});

 } else {

// put the limit for other languages

}
</code>```

hope it helps you .

Body:
try this code:

String language = Locale.getDefault().getDisplayLanguage().toString();

 if(language.equals(en) {

 // use set filter to limit input length in the edit text for english.
 int maxLength = 30;
 editText.setFilters(new InputFilter[] {new
 InputFilter.LengthFilter(maxLength)});

 } else {

// put the limit for other languages

}

hope it helps you .


问:
How to interpolate variables into Perl 6 regex character class?

I want to make all the consonants in a word uppercase:

> my $word = 'camelia'
camelia
> $word ~~ s:g/<-[aeiou]>/{$/.uc}/
(｢c｣ ｢m｣ ｢l｣)
> $word
CaMeLia
```

<p>To make the code more general, I store the list of all the consonants in a string variable</p>

<pre class="lang-perl6 prettyprint-override"><code>my $vowels = 'aeiou';
</code>```

or in an array

my @vowels = $vowels.comb;
```

How to solve the original problem with $vowels or @vowels variables?

答:
With the help of moritz's explanation, here is the solution:

my constant $vowels = 'aeiou';
my regex consonants {
    <{
       "<-[$vowels]>"
     }>
}

my $word = 'camelia';
$word ~~ s:g/<consonants>/{$/.uc}/;
say $word;  # CaMeLia
```

Body:
I want to make all the consonants in a word uppercase:

> my $word = 'camelia'
camelia
> $word ~~ s:g/<-[aeiou]>/{$/.uc}/
(｢c｣ ｢m｣ ｢l｣)
> $word
CaMeLia

To make the code more general, I store the list of all the consonants in a string variable

my $vowels = 'aeiou';

or in an array

my @vowels = $vowels.comb;

How to solve the original problem with $vowels or @vowels variables?


问:
Clause group by if two lines return the maximum
My query is:

```<code>SELECT ID,B,C,D, SUM(X), SUM(Y)
FROM TABLE
GROUP BY A,B,C,D
</code>```

But if the query returns 2 lines with the same id, I want take only one line which have the max of column D.

For example if the query returns:

```<code>+----+---+---+---+--------+--------+
| ID | B | C | D | SUM(X) | SUM(Y) |
+----+---+---+---+--------+--------+
| 2  | 1 | 1 | 1 | 70     | 100    |
| 2  | 1 | 1 | 3 | 100    | 150    |
+----+---+---+---+--------+--------+
</code>```

Then drop the line with D=1, and keep only the line with D=3

答:
Put your query inside of a CTE and then filter the result:

```<code>;WITH CTE AS (
SELECT ID,B,C,D, SUM(X) AS X, SUM(Y) AS Y
FROM TABLE
GROUP BY ID,B,C,D
)
SELECT * FROM CTE T
WHERE [D] = (SELECT MAX(D) FROM CTE where id = t.id)
</code>```

Body:
My query is:

SELECT ID,B,C,D, SUM(X), SUM(Y)
FROM TABLE
GROUP BY A,B,C,D

But if the query returns 2 lines with the same id, I want take only one line which have the max of column D.

For example if the query returns:

+----+---+---+---+--------+--------+
| ID | B | C | D | SUM(X) | SUM(Y) |
+----+---+---+---+--------+--------+
| 2  | 1 | 1 | 1 | 70     | 100    |
| 2  | 1 | 1 | 3 | 100    | 150    |
+----+---+---+---+--------+--------+

Then drop the line with D=1, and keep only the line with D=3

Body:
Put your query inside of a CTE and then filter the result:

;WITH CTE AS (
SELECT ID,B,C,D, SUM(X) AS X, SUM(Y) AS Y
FROM TABLE
GROUP BY ID,B,C,D
)
SELECT * FROM CTE T
WHERE [D] = (SELECT MAX(D) FROM CTE where id = t.id)


问:
alignment of basket in Shopify Mobile View
I seem to be having an issue with aligning the basket on the top row when viewing my site on a mobile. For some reason, this sometimes appears at the top and sometimes appears at the bottom and I cant work out why this is and where I need to amend the code in order to fix this.

Would really appreciate if somebody could advise. I have attached an image to show this from a mobile and the site itself can be seen at:

[https://defineclothing.co/][]1

答:
I wonder why it even works sometimes ;)

This div
 has a relative positioning and
 an absolute positioning.
Absolute positioned elements are positioned relative to the first positioned parent (which means relative, absolut or fixed). In order to achive the behaviour you want simply reset the relative positioning of
 to position: static

```<code><div class="col-xs-12 col-sm-12">
    <div class="top-header ">
        ....
    </div> <!-- End Top Header -->
 </div>
</code>```

Body:
I wonder why it even works sometimes ;)

This div <div class="col-xs-12 col-sm-12"> has a relative positioning and <div class="top-header "> an absolute positioning.
Absolute positioned elements are positioned relative to the first positioned parent (which means relative, absolut or fixed). In order to achive the behaviour you want simply reset the relative positioning of <div class="col-xs-12 col-sm-12"> to position: static

<div class="col-xs-12 col-sm-12">
    <div class="top-header ">
        ....
    </div> <!-- End Top Header -->
 </div>


问:
Is it possible to use Spring to create a console application?
Currently researching this topic. Is it possible to use the benefits of Spring to form a Console application? I mean, with scopes, autowiring and etc(found a bunch of examples of a basic "Set the context, init and go", but nothing more)?

Can't find any tutorials or helpful information on this topic.

答:
I recommend you to use Dropwizard framework, it provides so many required librairies in-build & can setup project within few minutes. Refer below link to know more about the dropwizard framework:
http://www.dropwizard.io/1.2.0/docs/

Also you can get the sample project of dropwizard framework at below link:

https://github.com/lawakush9292/DropwizardProject


问:
IIS gives 400 Bad Request for some links
I'm using ASP.NET Identity for generating activation urls in format

```<code>https://example.com/activate/token
</code>```

Where token is generated by Asp Identity and looks like this

```<code>Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAADds1gNf52iBX54Z6V%2bY5ZJEZmCmhgPetK2mEuu5pEiLwAAAAAOgAAAAAIAACAAAADjqFZ3Qrk6o22AHQDtoo%2bUNO4NZZ9RubxnuFBPTwyX/3AAAAATHRJIHkbDX2PmNxDYV0e2P5uAohDpMlpaP1C/KjV1mz5z06X7YaehipzlgLa4IxcAT8AQK%2bW4Qxq4Y3No0kaVNQRpSIzdB6cv%2bjn47IY5hburRgSPbZ6L7xvmWoreBZCCBn4SHMxbcdfAKEnkDELpQAAAAIwoV4hLdqQyV5g6WAQM/kiO3/FKyauZKsWBI/tA/M7uq7CDiQRdZxqdO0SUO9xW851luaKDP6bi/daxEhAemzk%3d
</code>```

Problem is sometimes ~1 in 10 times I get generic 400 error

```<code>Bad Request - Invalid URL

HTTP Error 400. The request URL is invalid.
</code>```

Example bad link

```<code>http://example.org/activate/AQAAANCMnd8BFdERjHoAwE/Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAACrbeGsadAFQETqBTsIuxf%2bJZqK0JOQvGC6M250gHsTEQAAAAAOgAAAAAIAACAAAACo6YtEGtjrvRO74X2G2VAQ1pAlBWksjnLo0zGxwrVrSXAAAAA%2bFfiwK3sL%2bbzK9wbM0r7Hoy4tueNmh4CNLD%2b2HeP7IldrAq40XbeLW0zlZo3CC2qWBfaGb5Z4HjziVYVT2Fvpg6dtm9UAmI4h5BPjzIBcJo8ZpiE4Z%2bQedRpAijhMHfsV2IDNptzCREWe3Wefi9aoQAAAAPzg9TNEhsqf76Qir%2bIyMxuuPsQkVykZVYFJ9/aI3EAAWK2de2VTUsXQBgdS4OGSI4AaAUEN%2b0Akdohw3Jd8zFo%3d
</code>```

I think the problem is somewhere in IIS request is not hitting my application anywhere and, that's very strange, same error is showing on other websites like microsoft.com.

Eg.this makes 400 error

```<code>https://microsoft.com/en-us/AQAAANCMnd8BFdERjHoAwE/Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAACrbeGsadAFQETqBTsIuxf%2bJZqK0JOQvGC6M250gHsTEQAAAAAOgAAAAAIAACAAAACo6YtEGtjrvRO74X2G2VAQ1pAlBWksjnLo0zGxwrVrSXAAAAA%2bFfiwK3sL%2bbzK9wbM0r7Hoy4tueNmh4CNLD%2b2HeP7IldrAq40XbeLW0zlZo3CC2qWBfaGb5Z4HjziVYVT2Fvpg6dtm9UAmI4h5Bhsqf76Qir%2bIyMxuuPsQkVykZVYFJ9/aI3EAAWK2de2VTUsXQBgdS4OGSI4AaAUEN%2b0Akdohw3Jd8zFo%3d
</code>```

but this 404 error

```<code>https://www.microsoft.com/en-us/AQAAANCMnd8BFdERjHoAwE/Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAAAbr0DBVHVcY2tO3Rvvk15d5%2bIuV3usPJmD2FTF15vpbwAAAAAOgAAAAAIAACAAAAAXddKnTogsgCGRRhIzbXbk14fsjcLJ5L0q5C/dRfsYlHAAAAAlAw9iARuxhShyGfzE6ZF193fX7zvxLnOfjgh74G5oLc5RPIVdQ7O8sJdj5H0BnysPxrCMk965izZRqjBKGZFNl6smYdmaGy5aPqxI1kTez%2bhHQH1GMW3GUmF%2bRoYdRqcmJLErgcb4sgMa7UGA16X1QAAAAJTk6s6OzBuA2B8whkUdwQnrCS2xgf7QR%2blA%2bm7UqUdXuhQfiFkL/oCINhyrJt%2bWJsjxvGhOcsW15DtzyqKvlWY%3d
</code>```

It looks like length sometimes have meaning but not really?
Similar question but caused by known characters - %09 in a URL causes IIS (HTTP.SYS?) to return HTTP 400 immediately

PS. Url in format http://example.com/activate?token=token work fine

答:
I think it is caused by the max length for Url segment (UrlSegmentMaxLength).

Source: https://support.microsoft.com/it-it/help/820129/http-sys-registry-settings-for-windows

Body:
I'm using ASP.NET Identity for generating activation urls in format

https://example.com/activate/token

Where token is generated by Asp Identity and looks like this

Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAADds1gNf52iBX54Z6V%2bY5ZJEZmCmhgPetK2mEuu5pEiLwAAAAAOgAAAAAIAACAAAADjqFZ3Qrk6o22AHQDtoo%2bUNO4NZZ9RubxnuFBPTwyX/3AAAAATHRJIHkbDX2PmNxDYV0e2P5uAohDpMlpaP1C/KjV1mz5z06X7YaehipzlgLa4IxcAT8AQK%2bW4Qxq4Y3No0kaVNQRpSIzdB6cv%2bjn47IY5hburRgSPbZ6L7xvmWoreBZCCBn4SHMxbcdfAKEnkDELpQAAAAIwoV4hLdqQyV5g6WAQM/kiO3/FKyauZKsWBI/tA/M7uq7CDiQRdZxqdO0SUO9xW851luaKDP6bi/daxEhAemzk%3d

Problem is sometimes ~1 in 10 times I get generic 400 error

Bad Request - Invalid URL

HTTP Error 400. The request URL is invalid.

Example bad link

http://example.org/activate/AQAAANCMnd8BFdERjHoAwE/Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAACrbeGsadAFQETqBTsIuxf%2bJZqK0JOQvGC6M250gHsTEQAAAAAOgAAAAAIAACAAAACo6YtEGtjrvRO74X2G2VAQ1pAlBWksjnLo0zGxwrVrSXAAAAA%2bFfiwK3sL%2bbzK9wbM0r7Hoy4tueNmh4CNLD%2b2HeP7IldrAq40XbeLW0zlZo3CC2qWBfaGb5Z4HjziVYVT2Fvpg6dtm9UAmI4h5BPjzIBcJo8ZpiE4Z%2bQedRpAijhMHfsV2IDNptzCREWe3Wefi9aoQAAAAPzg9TNEhsqf76Qir%2bIyMxuuPsQkVykZVYFJ9/aI3EAAWK2de2VTUsXQBgdS4OGSI4AaAUEN%2b0Akdohw3Jd8zFo%3d

I think the problem is somewhere in IIS request is not hitting my application anywhere and, that's very strange, same error is showing on other websites like microsoft.com.

Eg.this makes 400 error

https://microsoft.com/en-us/AQAAANCMnd8BFdERjHoAwE/Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAACrbeGsadAFQETqBTsIuxf%2bJZqK0JOQvGC6M250gHsTEQAAAAAOgAAAAAIAACAAAACo6YtEGtjrvRO74X2G2VAQ1pAlBWksjnLo0zGxwrVrSXAAAAA%2bFfiwK3sL%2bbzK9wbM0r7Hoy4tueNmh4CNLD%2b2HeP7IldrAq40XbeLW0zlZo3CC2qWBfaGb5Z4HjziVYVT2Fvpg6dtm9UAmI4h5Bhsqf76Qir%2bIyMxuuPsQkVykZVYFJ9/aI3EAAWK2de2VTUsXQBgdS4OGSI4AaAUEN%2b0Akdohw3Jd8zFo%3d

but this 404 error

https://www.microsoft.com/en-us/AQAAANCMnd8BFdERjHoAwE/Cl%2bsBAAAA2qxQHU9GHUuBNXILrSEDWgAAAAACAAAAAAAQZgAAAAEAACAAAAAbr0DBVHVcY2tO3Rvvk15d5%2bIuV3usPJmD2FTF15vpbwAAAAAOgAAAAAIAACAAAAAXddKnTogsgCGRRhIzbXbk14fsjcLJ5L0q5C/dRfsYlHAAAAAlAw9iARuxhShyGfzE6ZF193fX7zvxLnOfjgh74G5oLc5RPIVdQ7O8sJdj5H0BnysPxrCMk965izZRqjBKGZFNl6smYdmaGy5aPqxI1kTez%2bhHQH1GMW3GUmF%2bRoYdRqcmJLErgcb4sgMa7UGA16X1QAAAAJTk6s6OzBuA2B8whkUdwQnrCS2xgf7QR%2blA%2bm7UqUdXuhQfiFkL/oCINhyrJt%2bWJsjxvGhOcsW15DtzyqKvlWY%3d

It looks like length sometimes have meaning but not really?
Similar question but caused by known characters - %09 in a URL causes IIS (HTTP.SYS?) to return HTTP 400 immediately

PS. Url in format http://example.com/activate?token=token work fine


问:
Deleting Row by Primary Key - SQLite Android
I have ran into a bit of a problem regarding deleting a row by primary key in my android application that has a background database of SQLite.

At the minute I have 6 line types. e.g. S1, S2, S3 etc. I can only have 6 lines at one time and therefore I only have 6 rows in my database. Beside each button on my application I have an "X" button and when they click on say the X button beside S1 I want the database to delete the row with primary key "S1".

I think there is a quick solution but ive tried to manipulate my query many different ways and cant get the correct answer.

Here is some code I have:

DB Helper:

```<code> public void deleteProgressBar4() {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_NAME, COL_2 + "=", new String[]{"S1"});
    return;
}
</code>```

COL_2 is the LineType by the way..

X button code :

```<code>builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                               @Override
                                               public void onClick(DialogInterface dialog, int which) {
                                                   myDb.deleteProgressBar4();
                                                   Toast.makeText(Dashboard.this, "Line S1 Cleared!", Toast.LENGTH_SHORT).show();
                                               }
                                           });
</code>```

Can anyone see the mistake that I am making in the delete function? here is the error I am getting when I run this:

android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: DELETE FROM pharma_tracker_table WHERE LINETYPE=
                        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                        at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
                        at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
                        at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1499)
                        at com.almac.tracker.DatabaseHelper.deleteProgressBar4(DatabaseHelper.java:141)
                        at com.almac.tracker.Dashboard$6$1.onClick(Dashboard.java:219)
                        at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
                        at android.os.Handler.dispatchMessage(Handler.java:102)
                        at android.os.Looper.loop(Looper.java:154)
                        at android.app.ActivityThread.main(ActivityThread.java:6077)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
  Application terminated.

Thanks!

答:
Just Replace with you table name and column name</p>

```<code>SQLiteDatabase db = this.getWritableDatabase();
    long i =db.delete("tableName", "column Name = ?", new String[]{String.valueof(Id)});
</code>```

Body:
I have ran into a bit of a problem regarding deleting a row by primary key in my android application that has a background database of SQLite.

At the minute I have 6 line types. e.g. S1, S2, S3 etc. I can only have 6 lines at one time and therefore I only have 6 rows in my database. Beside each button on my application I have an "X" button and when they click on say the X button beside S1 I want the database to delete the row with primary key "S1".

I think there is a quick solution but ive tried to manipulate my query many different ways and cant get the correct answer.

Here is some code I have:

DB Helper:

 public void deleteProgressBar4() {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_NAME, COL_2 + "=", new String[]{"S1"});
    return;
}

COL_2 is the LineType by the way..

X button code :

builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                               @Override
                                               public void onClick(DialogInterface dialog, int which) {
                                                   myDb.deleteProgressBar4();
                                                   Toast.makeText(Dashboard.this, "Line S1 Cleared!", Toast.LENGTH_SHORT).show();
                                               }
                                           });

Can anyone see the mistake that I am making in the delete function? here is the error I am getting when I run this:

android.database.sqlite.SQLiteException: near "=": syntax error (code 1): , while compiling: DELETE FROM pharma_tracker_table WHERE LINETYPE=
                        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                        at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
                        at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
                        at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1499)
                        at com.almac.tracker.DatabaseHelper.deleteProgressBar4(DatabaseHelper.java:141)
                        at com.almac.tracker.Dashboard$6$1.onClick(Dashboard.java:219)
                        at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
                        at android.os.Handler.dispatchMessage(Handler.java:102)
                        at android.os.Looper.loop(Looper.java:154)
                        at android.app.ActivityThread.main(ActivityThread.java:6077)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
  Application terminated.

Thanks!

Body:
Just Replace with you table name and column name

SQLiteDatabase db = this.getWritableDatabase();
    long i =db.delete("tableName", "column Name = ?", new String[]{String.valueof(Id)});