Are these special (one production) Context-Free Grammars always unambiguous?

Consider the following (Context-Free) Grammars with only one production rule (not including the epsilon production):

  • $ S \rightarrow aSb\;|\;\epsilon$
  • $ S \rightarrow aSbS\;|\;\epsilon$
  • $ S \rightarrow aSaSb\;|\;\epsilon$
  • $ S \rightarrow aaSaaSbb\;|\;\epsilon$
  • $ S \rightarrow aSbScSdSeSf\;|\;\epsilon$
  • etc…

Grammars like these uphold 4 basic rules:

  1. The non-terminal symbol $ S$ can never appear next to itself.
    • e.g. $ [\;S \rightarrow aSSb\;|\;\epsilon\;]$ would not be allowed.
  2. The non-terminal symbol $ S$ can appear at the beginning or end of a production but not on both sides at the same time.
    • e.g. $ [\;S \rightarrow SabaS\;|\;\epsilon\;]$ would not be allowed.
    • e.g. $ [\;S \rightarrow Saba\;|\;\epsilon\;]$ or $ [\;S \rightarrow abaS\;|\;\epsilon\;]$ would be allowed.
  3. The sequence of terminal symbols that exist between each non-terminal $ S$ cannot all match.
    • e.g. $ [\;S \rightarrow aSaSa\;|\;\epsilon\;]$ , $ [\;S \rightarrow abSabSab\;|\;\epsilon\;]$ , etc. would not be allowed.
    • e.g. $ [\;S \rightarrow aSaSb\;|\;\epsilon\;]$ , $ [\;S \rightarrow abSabSaf\;|\;\epsilon\;]$ , etc. would be allowed.
  4. The sequence of terminal symbols at the beginning and end cannot match.
    (i.e. $ [\;S \rightarrow ☐_1SaS☐_2\;|\;\epsilon\;]$ s.t. $ ☐_1 \neq ☐_2$ where $ ☐_1$ and $ ☐_2$ are a sequence of terminal symbols)
    • e.g. $ [\;S \rightarrow aSbSa\;|\;\epsilon\;]$ , $ [\;S \rightarrow aaSbSaaS\;|\;\epsilon\;]$ , etc. would not be allowed.
    • e.g. $ [\;S \rightarrow aSbSb\;|\;\epsilon\;]$ , $ [\;S \rightarrow aaSbSaxS\;|\;\epsilon\;]$ , etc. would be allowed.

Are (Context-Free) Grammars, that follow these 4 rules, always unambiguous? It would seem so. I really don’t see any conceivable way that such Grammars could be ambiguous.

(Note: To show why Rule 4 is necessary consider the grammar $ S \rightarrow aSbSa\;|\;\epsilon$ with the string $ aababaababaa$ . A visual derivation can be found here.)

I’ve spent a lot of time thinking about this question and have had a hard time finding any way of either proving or disproving it. I’ve tried showing that Grammars like these are $ LL(1)$ . However, it seems only Grammars of the form $ S \rightarrow aSb\;|\;\epsilon$ are $ LL(1)$ . Grammars like $ S \rightarrow aSaSb\;|\;\epsilon$ are not $ LL(1)$ . Maybe I need to use a higher $ k$ for $ LL(k)$ ?

(This question is a follow-up/reformulation of a previous question.)

I would really appreciate any help I could get here.

Are Context-Free Grammars with only one Production Rule always Unambiguous?

Consider the following (Context-Free) Grammars with only one production rule (not including the epsilon production):

  • $ S \rightarrow aSb\space|\space\epsilon$
  • $ S \rightarrow aSSb\space|\space\epsilon$
  • $ S \rightarrow aSbS\space|\space\epsilon$
  • $ S \rightarrow aSaSb\space|\space\epsilon$
  • $ S \rightarrow aaSaaSbb\space|\space\epsilon$
  • $ S \rightarrow aSbScSdSeSf\space|\space\epsilon$
  • $ S \rightarrow aSSbcSd\space|\space\epsilon$
  • etc…

Are all these Grammars unambiguous? Will every Grammar with only one production rule (not including the epsilon production) always be unambiguous? It would seem so, but I’m not totally sure.

Grammars that only contain one unique terminal symbol could be ambiguous. (ex. $ S\rightarrow aSaSa\space|\space\epsilon$ ) However, Grammars with at least two distinct terminal symbols seem like they should always be unambiguous.

I’ve tried showing that Grammars like these are $ LL(1)$ . However, it seems only Grammars of the form $ S \rightarrow aSb\space|\space\epsilon$ are $ LL(1)$ . Grammars like $ S \rightarrow aSaSb\space|\space\epsilon$ are not $ LL(1)$ . (Illustrated in the parse table below.)

enter image description here

Despite the example Grammar above not being $ LL(1)$ , it still seems to be unambiguous. Maybe it’s simply a matter of using a higher $ k$ for $ LL(k)$ ?

In short, are (Context-Free) Grammars with only one production rule (not including the epsilon production) and at least two unique terminal symbols always unambiguous?

I would really love some help, any at all would be greatly appreciated.

Rewrite rule to load images from production makes no difference

I’m trying to adapt the rewrite rule given in Develop Locally, Use Images from Production to do the very same thing on my local dev site (which runs on XAMPP).

This is how the development site’s .htaccess looks, with the snippet added towards the end of it (URL replaced with equivalent, obviously):

<IfModule mod_php.c> php_value upload_max_filesize 64M php_value post_max_size 64M php_value max_execution_time 300 php_value max_input_time 300 </IfModule>  #START WORDPRESS  <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /wordpress/  # Redirect About and Library to first sub page  RewriteRule ^about/?$   /wordpress/about/history/ [L,NC,R=301] RewriteRule ^the-library/?$   /wordpress/the-library/gallery/ [L,NC,R=301]  RewriteRule ^index\.php$   - [L]  RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L]  # If images not found on development site, load from production  RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$   RewriteRule ^(.*)$$  1 [QSA,L] </IfModule>  #END WORDPRESS 

The rewrite rule doesn’t seem to be making a difference, whether with the HTTPS or HTTP version of the URL. Images unavailable for the dev site simply don’t display, even when the same images load fine for the production site.

I also had no luck trying to adapt the rewrite rule found in this slightly different question applying to WordPress Multisite.

Additionally, I previously added a filter to stop WordPress from modifying the .htaccess file, so am pretty sure that this isn’t the cause of the problem.

What, if anything, is wrong with my rewrite rule here that’s causing it to fail?

Move site collection to production making dev. Content DB as Production DB

We have a SharePoint 2013 farm, development environment where one site collection alone is residing in a separate DB server.

Now we plan to move this site collection to production with the existing database server as production database server.

We are not planning to keep Dev environment for this site collection now .(this will be taken care later).

Can someone suggest the best suitable approach?

P.S : Publishing feature is enabled for this site collection.

Extending the root with another partition (website’s server, on production)

I work for a media whose website gets around 300k views/day, installed on an OVH server.

When we’ve got the server, it was said to have 2x 500 GB of SSD storage, so we went with it and installed everything without checking which partition has space in it. After months in production, we’re now unable to backup the website because the server runs out of space. After some quick check…

df -h gives this:

Filesystem      Size  Used Avail Use% Mounted on udev             32G     0   32G   0% /dev tmpfs           6.3G  1.3M  6.3G   1% /run /dev/md3         20G   13G  6.1G  67% / tmpfs            32G     0   32G   0% /dev/shm tmpfs           5.0M     0  5.0M   0% /run/lock tmpfs            32G     0   32G   0% /sys/fs/cgroup /dev/md2        487M  213M  246M  47% /boot /dev/md4        449G   70M  426G   1% /home /dev/nvme0n1p1  510M  6.1M  504M   2% /boot/efi tmpfs           6.3G     0  6.3G   0% /run/user/0 

First thing I notice is that / has only 20 GB mounted to it. Since the website is under /var/www/, it appears that it falls under that partition.

Second thing, 450 GB are mounted on /home, which is pretty weird for a server distribution of Ubuntu. It isn’t supposed to host users and their desktop, downloads, etc., or is it?

What is needed now is a way to extend / or /var/www/ with /dev/md4 without losing data, and preferably without downtime (or much downtime, otherwise there might be SEO repercussions).

I have thought about copying /var/www to /home/www/ and then creating a sym-link between them, but I prefer to get some advice and suggestions prior of doing anything. I’m not the assigned dev (but an Editorial assistant, and there is no dev actually), so the duty falls on me and I don’t want to screw things up; especially that there is no backup at the current time.

Another thing that I wonder about is where the 2nd 500 GB SSD storage is gone. I’ll ask if it’s been put as RAID-0 but I have some doubts.

Thank you.

Copy package in Production DB to Test DB with dependencies?

This is my first question here, so please let me know if this isn’t the right place to ask.

I’m a new programmer, fresh out of school. Primarily I develop in Python/C#, with a dash of SQL when needed.

At my job, I’ve been assigned a task in PL/SQL, which involves modifying some existing procedures. All well and good, some new syntax to learn, but no serious roadblocks.

My problem is, I have no idea how to migrate the existing package/views/tables to our test database, which is basically an un-maintained sandbox environment.

I only need to copy two stored procedures in a package, two views, and 3 tables, so that I can modify the procedures and verify that the output is as-expected. However, I feel like there must be a better way to move this data than “crtl+c, crtl+v” in the editor window, or downloading and uploading table export files via my local machine.

I’m working in Oracle SQL Developer, and really only need to move enough data to execute these procedures and test my work. My job is really the development here, and the more time I spend trying to set up this test environment, the less time I spend coding.

Is there some sort of way to easily copy a package and all its data dependencies from one database to another? Bonus points if it’s in Oracle SQL Developer, and easy for a non-DB admin to do. Thanks!

How to speed up the production of this plot?

This is a followup question to this question. From this two answers I can build the function sol[r][[1]][t0] as follows:

ClearAll["Global`*"] Md = 10^(-9); P = 10; R = 10^4; α = 10^(-2); ϵ = 10^(-4); γ = 10^(-2); ke = 0.02*(1 + 0.6625); k0 = 5*10^20; σ = 5.67*10^-8; Rg = 8315; c = 3*10^8; G = 6.67/10^11; M = 2.8*10^30;  Ωk[r_] := Sqrt[(G*M)/r^3]; μ = Md/(3*Pi); κ = (27*ke)/(2*σ) Rg/μ; ic = {Co[0] == 1, β[0] ==      0, Σ[      0] == (μ^(3/5)*Ωk[          r]^(2/5)) (κ^(-1/5)*α^(-4/5)*Co[0]^(-1/5)),    h[0] == (κ*α*Σ[0]^2*        Co[0]/Ωk[r]^5)^(1/6),    T[0] == (1/2)*(Ωk[r]*h[0])^2*(μ/        Rg)*(1/(1 + β[0])),    Kkr[0] == (k0*(Σ[0]*h[0]))/T[0]^(7/2)};  eq = {Σ'[      t] == -Σ[        t] + κ^(-1/5) α^(-4/5) μ^(3/          5) Ωk[r]^(2/5)*Co[t]^(-1/5),    h'[t] == -h[        t] + (κ α Σ[t]^2 Ωk[           r]^(-5) Co[t])^(1/6),    T'[t] == -T[t] +       1/2 μ/Rg (Ωk[r]^2 h[t]^2)/(1 + β[t]),    Kkr'[t] == -Kkr[t] + k0 Σ[t]/h[t]*T[t]^(-7/2),    β'[      t] == -β[t] + μ/        Rg (4 σ)/(3 c) T[t]^3/Σ[t] h[t],    Co'[t] == -Co[t] + (1 + β[t])^4*(1 + Kkr[t]/ke)};    t0 = 20; sol =   ParametricNDSolveValue[{eq, ic}, {Σ, h,     T}, {t, 0, t0}, {r}] 

Now I need to perform the following integral for a plot:

int[r_?NumericQ, t_?NumericQ] := sol[r][[1]][t0] r^3 Cos[2 CapitalOmega]k[r] t] F1[t_?NumericQ] := NIntegrate[int[r, t], {r, 10^6, 10^8}] Plot[F1[t], {t, 0, 3*10^3}] 

In a whole night this code has not produced the plot. I tried with memoization for the function int:

 int[r_?NumericQ, t_?NumericQ] := int[r,t]=sol[r][[1]][t0] r^3 Cos[2 CapitalOmega]k[r] t] 

but nothing has changed. I tried with with ParallelTable, but Mathematica says it cannot communicate with the kernels (or something like that) and a simple Table[F1[t],{t,0,1000,100}] still has not produced an output.

How can I produce the desired plot?

How To Set Up a Node.js Application for Production on a Debian 9 VPS

In this tutorial, we will create a simple Node.js application and put it into a production ready environment on Debian 9, “Stretch”.

  • To make the app accessible from your browser, we’ll use Nginx as a reverse proxy. Nginx is a fast and versatile web server, and can also be used as a Load Balancer.
  • To make the access to the app secure, we’ll use Certbot to install Let’s Encrypt certificates. Then, we’ll be able to use HTTPS requests instead of unsecure HTTP requests.
  • Finally, we will make sure that the app is running continually, by turning it into a service with a special NPM package called PM2. PM2 will daemonize the Node.js app and run it in the background, even after system crashes or reboots.


What We Are Going To Cover

  • Install Nginx
  • First install firewall-cmd, then change its rules to enable Nginx
  • Install the latest version of Node.js
  • Add NPM packages for the app that we are making
  • Create the example app to show all characters in upper case
  • Configure Nginx as a reverse proxy
  • Install Let’s Encrypt certificates to serve HTTPS requests
  • Access the app from the browser
  • Install PM2, which is a production process manager for Node.js applications with a built-in traffic Load Balancer
  • Use PM2 to restart the Node.js app on every restart or reboot of the system


We use Debian 9:

  • Starting with a clean VPS with
  • At least 512Mb of RAM and
  • 15Gb of free disk space.
  • You will need root user access via SSH
  • A domain name pointed to your server’s IP address (it can also be a subdomain) using A records at your DNS service provider
  • We use nano as our editor of choice, and you can install it with this command:
sudo apt install nano 

Step 1: Install Nginx From a Repository

After you have logged in as a root user, install Nginx. Let’s refresh the cache and start the installation:

sudo apt update sudo apt upgrade -y 

Now install Nginx:

sudo apt install nginx -y 

In the browser, go to address


and verify that Nginx is running:

Step 2: Change Firewall Rules to Enable Nginx

On Debian, the iptables firewall is installed by default, but we prefer ufw, the uncomplicated firewall. First install it:

sudo apt install ufw 

List all the port profiles ufw already knows about:

sudo ufw app list 

That is quite a list:

There are three options fo Nginx:

  • Nginx Full: Opens ports 80 and 443 for normal, unencrypted web traffic and TLS/SSL for encrypted traffic, respectively.
  • Nginx HTTP: Only port 80 (normal, unencrypted web traffic)
  • Nginx HTTPS: Only port 443 (TLS/SSL encrypted traffic)

In theory, we should use the most restrictive type of access. However, there is a possibility that someone will use a HTTP request instead of a HTTPS, so we enable the full option:

sudo ufw allow 'Nginx Full' 

Node.js apps require a port that is not used by the system, but is dedicated to that one app only. In our examples, we might use ports such as 3000, 8080 and so on, so we need to declare them explicitly, otherwise your app won’t run.

Here is a list of ports and feel free to add any other that your host requires for the normal functioning of the system:

sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw allow 20/tcp sudo ufw allow 21/tcp sudo ufw allow 3000 sudo ufw allow 8080 sudo ufw allow 'Nginx Full' sudo ufw enable 


Always execute ufw commands with ssh, http, https and so on, otherwise you will NOT be able to log back into your VPS server!

To see the changes, run:

sudo ufw status 

Step 3: Install Latest Node.js

Execute this series of commands to install node.js:

cd /tmp sudo apt install curl -y sudo curl -sLO sudo bash setup_12.x sudo apt-get install gcc g++ make apt install nodejs sudo nodejs -v 

The script sets up the proper Debian package repositories and also installs gcc, g++ and make. They may be required by some Node.js packages during their installation to compile their parts written in C or C++. Finally, it inspects the Node.js version:

Node.js version

It shows v12.3.1, which was the actual version of at the time of this writing. If it shows an error, double check the commands you entered against the ones shown above.

Step 4: Adding NPM Packages

We of course know what packages our Node.js app will need, so we install the required npm packages in advance. First we install prerequisite packages for NPM:

sudo apt install build-essential libssl-dev 

With that, we will be able to install all other packages out there.

Since our app will turn any input into uppercase letters, we install a package for that:

npm install upper-case 

Most Node.js apps will now use Express.js, so let’s install that as well:

npm install --save express 

Execute this command as well:

npm install -g nginx-generator 

It will globally install an NPM package to generate the reverse proxy config for Nginx. We will apply it after the app is running on port 8080.

Step 5: Creating The App

Open a file named uppercase-http.js for editing:

nano uppercase-http.js 

Add the following lines:

var http = require('http'); var uc = require('upper-case'); console.log('starting...'); http.createServer(function (req, res) {   console.log('received request for url: ' + req.url);   res.writeHead(200, {'Content-Type': 'text/html'});   res.write(uc(req.url + '\n'));   res.end(); }).listen(8080); 

Save and close the file.

The HTTP server will listen to port 8080. You can specify any other port that you like, provided that it will be free when the app is running (and that you have previously opened access to it in ufw).

Run the app:

node uppercase-http.js 

You will see the following message:


Node.js app starting

To test it, fire up another terminal, connect to your VPS as root via SSH and curl localhost:8080:

curl localhost:8080 curl localhost:8080/test 

The program correctly converted the path to uppercase. If you look at the server app itself, it showed a status message for both requests:

received request for url: / received request for url: /test 

App server messages

Now you have two windows, one with an active app and the other with the curl statement. From now on, enter commands only into the second window, otherwise you would have to stop the app and then the rest of the procedure would make no sense.

Step 6: Configure Nginx as Reverse Proxy

Let’s now access this app from your web browser. Empty the default file in folder /etc/nginx/sites-available/ with the following two commands:

rm /etc/nginx/sites-available/default sudo nano /etc/nginx/sites-available/default 

That file has to be empty in order for Nginx to read files in the /etc/nginx/sites-enabled/ folder. Enter one space into this otherwise empty file, save and close it.

Now, we will use the NPM package nginx-generator that we have installed earlier in this tutorial, to generate files that will tell Nginx to act as a reverse proxy. In the command line, execute the following:

nginx-generator \       --name site_nginx \       --domain YOUR_DOMAIN \       --type proxy \       --var host=localhost \       --var port=8080 \       /etc/nginx/sites-enabled/site_nginx 

Replace YOUR_DOMAIN with your domain before running this command.

That command creates a file called site_nginx and puts it into the directory /etc/nginx/sites-enabled/. (We could have used any other file name instead of site_nginx.)

We can see it with this command:

sudo nano /etc/nginx/sites-enabled/site_nginx 

Test the configuration:

sudo nginx -t 

and if everything is OK, restart Nginx:

systemctl restart nginx 

In your browser, go to address


and the result should be


Step 7: Securing Your Site To Serve Only HTTPS

Our goal is to run a production version of a Node.js app, which means we must serve it for HTTPS requests. If you have a domain name and DNS records properly set up to point to your VPS, you can use certbot to generate Let’s Encrypt certificates. This means that you will always access the app as well as the rest of your domain, via HTTPS.

We will folow the original documentation to install Let’s Encrypt. Choose Nginx for software and Debian 9 (stretch) for System – it should look like this:

Certbot Certbot Site

Certbot for Debian comes from the Backports repo so let us open the sources list

nano /etc/apt/sources.list.d/nginx.list 

and enter the following line into that file:

deb stretch-backports main 


apt-get update 

and install backports:

sudo apt-get install certbot python-certbot-nginx -t stretch-backports 

Finally, activate it with:

sudo certbot --nginx 

What certbot will ask you will depend on the previous events. If you are installing it for the fist time, it will ask for an emergency email address, then several less important questions and finally – do you want to redirect all HTTP traffic to HTTPS? Select 2 to confirm this redirection, and you’re all set!

Test the configuration:

sudo nginx -t 

and if everything is OK, restart Nginx again:

systemctl restart nginx 

In your browser, go to address


and the result should be


Note that this address started with HTTP, but that it ended up as HTTPS.

Step 8: Install PM2

PM2 is a production process manager for Node.js applications. With PM2, we can monitor applications, their memory and CPU usage. It also provides easy commands to stop/start/restart all apps or individual apps.

Once the app is started through PM2, it will always be restarted after system crashes or restarts. In effect, it will “always be there”.

We use NPM to install PM2:

sudo npm install pm2@latest -g 

Option -g tells it install pm2 globally, meaning that we shall be able to run it from all paths in the system.

Let’s now run our application under PM2:

cd ~ pm2 start uppercase-http.js 

The output of PM2 can be spectacular when run for the first time, but we really need to concentrate on the rows about the app:

PM2 will use app name, and then show the id number of the app, mode, status, CPU usage and memory. If two or more apps are running in the background, they will all be presented in this table.

We can list the processes like this:

sudo pm2 list 

The following command

sudo pm2 show 0 

will show details of the app with ID of 0:

It is also possible to monitor CPU usage in real time:

sudo pm2 monit 

Other useful PM2 commands are stop, restart, delete.

What Can You Do Next

We have shown how to set up a Node.js app for a production environment, as a root user, on a Debian 9 VPS. You can study more about Nginx and add several sites on one VPS server, each with its own non-root user, listening on different ports and so on. As a Node.js programmer, you would also pay attention to debugging processes and other good practices – all of which is, however, out of scope of this article.

Dusko Savic is a technical writer and programmer.

The post How To Set Up a Node.js Application for Production on a Debian 9 VPS appeared first on Low End Box.

Slow query in production, bad plan or stale index?

I’ve just fixed a production performance issue by dropping an index and recreate it. I suspect dropping the index also dropped executions plans that used it and one of them happen to be bad.

Arguments in favor of bad execution plan :

  • Before dropping the indexe, I looked up the last update date for the statistics on the given table and they were up to date.
  • My DBA has put in place Hallengren’s index and statistic maintenance solution
  • The slow query was a select statement executed from sp_executesql with dates parameters. Executing the same select statement without sp_executesql was fast, but also didn’t use the same execution plan.

Arguments against bad execution plan :

  • Before dropping the indexe, we went real wild and runned the forbidden dbcc freeproccache to clear any bad plan, but this didn’t fix or change the performance issue.


  • The slow query happen to be using a table indexed by date. However, there is wide differences in the amount of records for each date. In other word, any given date range from few records to more than 100k and it is pretty random.

  • The database is running under compatibility level 140 (SQL Server 2017)

Was the source of the problem a bad plan or a stale indexe?