OpenLLM-France/wikimedia huggingface dataset:
# PostgreSQL/Parallel Queries

Since version 9.6 PostgreSQL supports parallel processing of queries. Within most of today's servers there are a lot of CPUs. Their concurrent usage can shorten the elapsed time of queries significantly. Therefore the query optimizer tries to create a plan, which leads to more than one executing process per query. At runtime those processes work concurrently and in a coordinated way on diverse parts of the shared buffers.
Parallel execution is initiated by so called gather nodes of the execution plan. When they are reached at runtime, the actual running process requests the planned number of additional processes (background worker processes). The original process plus the additional processes execute the child node of the plan in parallel. The gather node has the additional duty to collect and accumulate the results of its child processes.
The feature is not used in all situations. This results from three different effects: type of query, parameterization of PostgreSQL, and the actual implementation.
* If a query leads to an execution plan, which is highly I/O intensive, it doesn't benefit greatly from parallelization as parallelization is a RAM-access feature. In contrast to this, queries which needs high CPU activities (eg: ... where text like '%xyz%'; without an adequate index) will benefit much more. Therefore it is more likely that parallelization is chosen for the second type of queries.
* The default behaviour of PostgreSQL (in version 9.6) is to use the traditional behaviour by invoking one single process. If one wants to use the parallelization feature, he must set some parameters: max_parallel_workers_per_gather defines the maximum number of processes which are allowed to run in parallel with each gather node. As it defaults to 0 it leads to the traditional behaviour - unless the value is changed. As mentioned above, each process working in parallel to the gather node is realized in a background worker process. The total number of background worker processes per instance is limited by max_worker_processes and defaults to 8. So it may be necessary to increase the value. Additionally, the parameter dynamic_shared_memory_type must be set to a value other than none.
* The actual implementation in version 9.6 contains a lot of limitations which result from the fact that it must be ensured that this basic implementation is stable in all environments. It is likely that in further releases some of them disappear.
   * It is restricted to purely read-only commands: no UPDATE, DELETE, nor the CTE part of any writing command.
   * If there is a lock for any involved row.
   * If the transactions isolation level is serializable.
   * If the query is running inside of another query which is already parallelized. For example, if a function called by a parallel query issues an SQL query itself.

## See also

* PostgreSQL documentation about parallel queries in current version
* Additional PostgreSQL wiki
# PostgreSQL/Security
## Roles

PostgreSQL supports the concept of roles to handle security issues within the database. Roles are independent from operating system user accounts (with the exception of the special case peer authentication which is defined in the pg_hba.conf file).
The concept of roles subsumes the concepts of individual users and groups of users with similar rights. A role can be thought of as either an individual database user, or a group of database users, depending on how the role is set up. Thus the outdated SQL command CREATE USER ... is only an alias for CREATE ROLE ... . Roles have certain privileges on database objects like tables or functions and can assign those privileges to other roles. Roles are global across a cluster - not per individual database.
Often individual users, which shall have identical privileges, are grouped together to a user group and the privileges are granted to that group.
With the CREATE ROLE command you can assign the privileges SUPERUSER, CREATEDB, CREATEROLE, REPLICATION and LOGIN to that role. With the GRANT command you can assign access privileges to database objects like tables. The second purpose of the GRANT command is the definition of the group membership.
In addition to the roles created by the database administrator there is always the special role PUBLIC, which can be thought of as a role which is a member of all other roles. Thus, privileges assigned to PUBLIC are implicitly given to all roles, even if those roles are created at a later stage.

### List existing roles

Roles can be listed with the following commands.
With SQL, this will display an additional set of postgreSQL default roles that group together sets of common access levels:
or the psql command:

## References

* ↑ Concept of roles
# PostgreSQL/Select without elimination

One common problem faced with SQL is using boolean conditionals to narrow down a set without any desire of eliminating all possible results. In this example you seek a best match, if one can be given or NULL. This can be easily and cleanly achieved relationally with a slight abuse of UNION ALL. There are many ways to achieve this procedurally such as fuzzy matching.

## Description

The basic idea is to SELECT * eliminating nothing, UNION ALL against a SELECT on that same set (different instance) such that there is a possibility of tuples being eliminated in the UNION'ed set. Then you are going to count the occurrence of all tuples, each tuple will have an occurrence of at least one (the LHS of the first UNION ALL) this will result in no eliminations. This resulting set you will select the max of the count.

## Synopsis
### Result

The key here, is if the conditional bar = 50 was used, you would still be left with the original dataset.

## Example

A third party data provider has given you a set of data that you wish to select the best match from. You're equipped with an array of things that might help you identify a best match, but you want to always return one tuple, that is to say you don't ever want to eliminate all tuples returned. Your data that is supposed to only trim down the superfluous matches.
Let's use for instance a vin 1GCEC14C57Z590788:
* They call a trim "Work Truck" you call the trim "1WT".
You don't want to eliminate all vehicles because of this. So here using a conditional trim LIKE '%1WT%', will not work, because 1WT is not contained in "Work Truck".
Now let's assume that other information provided would help you better identify what style your vehicle matches up against. As is the case of the "MSRP", if is within a range of 1.00 USD of 18,123 you can successfully eliminate all but one style.
Observe one way we could do this:

## Footnotes

* ^ Fuzzy matching often uses a simple Levenshtein edit distance formula. Using plperl (Perl), you can easily accomplish this using String::Approx module's adist.
# PostgreSQL/Tablespace

The default behaviour of PostgreSQL is, that all data, indices, and management information is stored in subdirectories of a single directory. But this approach is not always suitable. In some situation you may want to change the storage area of one or more tables: data grows and may blow up partition limits, you may want to use fast devices like a ssd for heavily used tables, etc. . Therefore you need a technique to become more flexible.
Tablespaces offers the possibility to push data on arbitrary directories within your file system.
After the tablespace is defined it can be used in DDL statements.
# Puzzles/Arithmetical puzzles/Two 4s Equal 64?/Solution

< Back to Problem
Some answers are ${\sqrt {\sqrt {\sqrt {4^{4!}}}}}$, ${\sqrt {\sqrt {{\sqrt {4}}^{4!}}}}$, $4^{\log {\sqrt {\sqrt {\sqrt {\exp {4!}}}}}}$ and $4^{-\lfloor \tan {4!}\rfloor }$.
# Puzzles/Arithmetical puzzles/Three Daughters/Solution

The answer is 2, 2 and 9.
The product of their ages is 36, leaving the possibilities
{1,1,36}, {1,2,18}, {1,3,12}, {1,4,9}, {1,6,6}, {2,2,9}, {2,3,6} and {3,3,4}.
Knowing the sum of their ages is not sufficient to determine their ages, eliminating {1,1,36} (38), {1,2,18} (21), {1,3,12} (16), {1,4,9} (14), {2,3,6} (11) and {3,3,4} (10), leaving only
{1,6,6} and {2,2,9}.
Knowing that there exists an eldest daughter eliminates {1,6,6}, leaving only {2,2,9}.
How does knowing that there exists an eldest daughter eliminate {1,6,6}? One daughter can be older than another but both have the same age in years.
Hey, questioner, we're going by the same number of years. We are taking that both daughters in the thrown out {1, 6, 6} choice are EXACTLY 6-years-old.
# Puzzles/Chess puzzles/Rook Polynomial
## History

The puzzle first proposed by Henry Ernest Dudeney in his book "Amusements In Mathematics" in the year 1917 with his quote as below:

## Premise

The premise is similar to Puzzle/Chess puzzles/Eight Queens, where as many of the possible placements of eight rooks are placed on the 8X8 chess board so that the rooks wont attack/guard one another.
Rook's legal moves are horizontally or vertically

## Solutions

Here is the animation of the one of the animations of rook polynomials.
Based on that animation aboves, you can see the X represent the rooks area of attack and with each successive rooks, the rooks have lesser and lesser places to be put on the board .
Since the rooks piece can only move in straight lines: It must be in every row and every column.
Starting with the top row, it is clear that we may put our first rook on any one of eight different squares.
Wherever it is placed, we have the option of seven squares for the second rook in the second row.
Then we have six squares from which to select the third row, five in the fourth, and so on.
Therefore the number of our different ways must be 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 = 40,320 (that is 8! / 8 factorial), which is the correct answer.

## Bibliography

* http://www.gutenberg.org/files/16713/16713-h/16713-h.htm#X_295_THE_EIGHT_ROOKS
# Puzzles/Chess puzzles

The first known chess puzzles are dated way back during the Middle Ages (See: Wheat and chessboard problems) and from then on, it has evolved quite substantially since then.
With the arrival of computers, chess puzzle itself are well establish genre itself within few years, however there are always will be some interesting puzzles to be solved as will be shown on the following puzzles.
These chess puzzles provided can be puzzled over a piece of paper and can be enjoyed without the need for a chess set.
Enjoy the collections of the chess puzzle below:

## Chess Puzzles

Below lists are some of the chess puzzles.
In fact many of the chess puzzles below don't require knowledge of the chess rule itself too (except for legal moves of certain chess piece).
Puzzles/Chess puzzles/Knight Tour
Puzzles/Chess puzzles/Eight Queens
Puzzles/Chess puzzles/Rook Polynomial
Puzzles/Chess puzzles/Rook Tour Around Spawns
Puzzles/Chess puzzles/Mutilated chessboard problem
Puzzles/Chess puzzles/Wheat and chessboard problem
Puzzles/Chess puzzles/Knight and 16 pawns
# Puzzles/Bongard problems

Puzzles | Bongard problems
Bongard problems challenge you to find a common property in a series of pictures that is not present in another series. They make up a problem in artificial intelligence (Wikipedia article) but they are entertaining puzzles, too.

## Solutions

Solutions to Bongard Problems

## External links

Compilation of Bongard problems.
# Puzzles/Chess puzzles/Eight Queens
## History

The first known mention of the Eight Queens problems was by writer named Max Bezzel, a German chessplayer in the September 1848 issue of Schachzeitung,a famous chess newspaper.
The problem was proposed again in by Franz Nauck in Illustrirte Zeitung of Leipzig, in the issue of June 1, 1850 . At first, Nauck asserted in the June 29 issue that there are 60 solutions to the main problem. Nauck also included a subproblem, to find all solutions with queens at positions b4 and d5.
In the same year during September, Carl Friedrich Gauss, a German mathematician was aware of the problem upon his reading of the problem in the Illustrirte Zeitung. Gauss remarked that Nauck had declared that there were 60 solutions, but that he found 76 (16 more than the proposer). A few days later, he found that he may make a mistake (4 of his solutions should be removed) leaving 72 solutions. Again, a few days later, he make a crude estimate of possible solutions of between 120 and 168 solutions.
Nauck's correction in the September 21 Illustrirte Zeitung giving 92 as the correct number of solutions

## Problems

The premise for the problems are as followed: Place eight chess queens on an 8x8 chessboard so that none of them lies in the field of attack of any of the others. In other words, no two may lie in the same row, column, or diagonal that are in anyway interferes with one and another.
Here are the queens legal moves illustrated :

## Solutions

There are 92 possible solutions for the eight queens puzzles. But only 12 are considered to be unique solution. The rest of 80 solutions are either inverse, reverse, rotate or mirror images of the solutions
Here are the a few of the solutions as shown:
* Solution A
* Solution B
* Solution C
* Solution D
* Solution E
* Solution F
* Solution G
* Solution H
* Solution I
* Solution J
* Solution K
* Solution L

## Bibliography

* http://www.datagenetics.com/blog/august42012/
# Puzzles/Arithmetical puzzles/Two 4s Equal 64?

Puzzles | Arithmetical puzzles | Two 4's equals 64?
You can use the number 4 twice (but no other numbers) and as many mathematical operators as you wish to write an expression that is equal to 64.
What is the expression?
solution
# Puzzles/Chess puzzles/Knight Tour

Knight tour are considered one of the famous puzzles in the chess puzzles. The first mention of Knight tours during the 1600's appeared in Jacques Ozanam's Récréations Mathématiques et Physiques at year 1612. But however, it will take another century before the puzzles are fully analysed by Leonhard Euler whom write the French paper in 1759 titled: Solution d'une question curieuse qui ne paroit soumise à aucune analyse
The excerpt of paper quotes as followed:
   I found myself one day in company where, on the occasion of a game of chess, someone proposed this question: to traverse with a knight all the cells of the chessboard, without ever arriving twice at the same, and commencing from a given cell.” He describes how the course of the knight was followed by placing counters on the cells and removing them one at a time as the cells were visited by the knight.
To summarize, the premise of the puzzle are usually consists of the following:
Picture below shows at any instances, knight piece are allowed to be placed at one of the locations marked with red colours.

## Solutions

There are many ways of solving the knight tour but however we will shows the Euler method on solving the Knight tour on 8X8 chess board.
* Version 1
* Version 2

## Bibliography

* http://www.mayhematics.com/t/1a.htm
# Puzzles/Chess puzzles/Knight and 16 pawns

Your knights are the remaining last soldier standing in the normal chess board game. These are 16 pawns that are arranged in these two hollow squares formation that aimed to overtake you .
Refer the picture on your right for formations.
How can your knight are able to defeat all of the pawns in just 16 moves. (P.S: Note that your knight need to defeat the pawn in every move that your knight made)
There are 2 rules of the puzzles:
(a) The knights are allowed to start on any squares inhabited by the pawns. (b) The knights allowed move are its legal move (Two move forward and one move to side [left / right])

### Solutions

The first capture may be on any pawn except pawns at c4, d3, d4, e5, e6, and f5.
Here is one of the solutions for the knights starting at pawn c2, b4, d3, b2, c4, d2, b3, d4, e6, g7 ,f5, e7, g6, e5, f7, and g5
# Programming AI with Leaf/Communicating With Outside Programs

Having Leaf exchange data with other programs can be challenging. This author, Thomas Messerschmidt, working with his robot Robot Betty9 (see http://www.myspace.com/robotbetty9), has created a very simple but quite effective way of allowing Leaf to chat with just about any external (external to LISP) program.
The methodology consists of passing text message between Leaf/LISP and the outside world by creating and destroying small text (.txt) files. It was originally written so that Leaf could expand his AI using a standard ALICE-BASED (ProgramD) chatbot.
The first part consists of the function "sendchatout2chatbot". It writes data out to the "in" file "in.txt".
The second part consists of the function "readchatbotfile ". It reads text returned from an application, in this case from a chatbot using a file called "out.txt".

      ## Start of Chatbot Interface Code -----------------------------------------
      ## Start of Chatbot Interface Code -----------------------------------------
      ## Start of Chatbot Interface Code -----------------------------------------
      ## Code by Thomas Messerschmidt (Please credit me. A link back to Betty9 would be nice.)

(defun sendchatout2chatbot
(defun readchatbotfile
(defun getchatin ; tts what came back from chatbot and then delete the file

      ## End of Chatbot Interface Code -------------------------------------------
      ## End of Chatbot Interface Code -------------------------------------------
      ## End of Chatbot Interface Code -------------------------------------------

So to sum it up: 1. A user asks a question of Leaf 2. Leaf sends the question to the chatbot via the sendchatout2chatbot function which writes to "C:/in.txt" 3. The chatbot reads in the question asked in "C:/in.txt" and then deletes the file. 4. The chatbot writes out its response to the question in a file "C:/out.txt" 5. When leaf sees that there exists a C:/out.txt file, he reads it in with the readchatbotfile function which also reads it aloud using Microsoft's standard TTS (Text to Speech) SAPI 5.x. 6. The file "C:/out.txt" is then deleted by Leaf.
# Programming AI with Leaf/Development
## Editing Programming AI with Leaf/Development

Programming AI with Leaf/Development/Leaf and Linux
Programming AI with Leaf/Development/RSS Feeds for Weather, News and Sports
Programming AI with Leaf/Development/How to change Leafs name
Programming AI with Leaf/Development/Installing drivers for Microcontroller
# Programming AI with Leaf

Have you ever wanted to create artificial intelligence software (AI) but did not know where to start? Have you wanted to put this AI into a robot? If so Leaf is for you. Leaf is the AI software that starts you with a working AI framework that you add to and customize as you wish. It was put together by the Leaf Project, a group robot development program whose objective is to develop a robot platform that supports experiments with artificial intelligence, vision, voice recognition, navigation, etc.

## Contents

* Noted contributors
* Development
* Communicating With Outside Programs
* Overview
* Installing
* Creating Your Own Leaf (Customizing Leaf)
* Face Recognition with Eigenfaces
* Adding to Leaf: the SD84 Servo Controller
* Adding to Leaf: the ALICE Chatbot
* Q&A (Ask a question!/)
* Leaf's Creators
* Sources for LEAF Robot Parts
# Programming AI with Leaf/Development/How to change Leafs name
## How to change the name of your Leaf

As always you should back up your files before changing anything.
Open your Leaf.lisp and use the Find function (In LispWorks this is in the Edit menu) and search for "NAME YOUR ROBOT" with the "". In the line below it where it says (defconstant robot "Leaf") is where you change your robots name so go ahead and take your pick, just change "Leaf" to what you want.
Save the file, compile and close it, now open your Speech.xml and add your robots name to the end of the list of names and save the file.
That's it, next time you start up Leaf your robot should respond to its new name.
# Programming AI with Leaf/Development/Leaf and Linux
## Leaf and Linux

Leaf has been built on windows XP and uses LispWorks as the Lisp development environment. This provides a readily available environment for anyone wanting to build a Leaf robot.
A number of people have expressed interest in trying to port Leaf to a Linux environment. These pages record the trials & tribulations of people’s attempts to do the port.

### A message from one of the Linux crowd

A warning to anyone considering a Linux port. The Leaf project is windows based and is a very successful environment for this project. There are a number of features that have been implemented in windows that are going to be VERY challenging to get working under Linux.
Build a standard Leaf before you try to use linux. Please do not expect the Leaf developers to provide any support for Linux. They are doing an excellent job with windows and this is where they will continue to work.
If you are still keen remember you are on your own but not alone.

## Major component

The Leaf environment has several major components that we will need to duplicate to be able to do a port.
1) Speech recognition
2) LISP compiler/interpreter environment
3) Text to Speech
4) Face Animation
5) Micro controller interface software (Nav & control program)
Because of the wide range of environments available in Linux it is important to understand what a person is using when they offer a contribution to the Linux port.
People have asked for recommendations on which distribution to use. The distribution is not as important as the kernel version and the version numbers of any software installed.
Contributors & systems

### Speech Recognition

This is likely to be the hardest part. Speech recognition work on Linux appears to have stopped around 2000 when the ViaVoice package was removed from the market.
The most likely candidate is one of the Sphinx versions. Experimentation is under way with both Sphinx 2 & Sphinx 3. So far recognition rates have been about 10%
Until this is greatly improved there is little point in progressing the other modules.

### Lisp environment

The LISP package is Steel Bank Common LISP (SBCL)
The development environment is SLIME which uses the EMACS editor
LispWorks has a graphical interface, which is only used to set the options at start up, the McCLIM package has been used to get this functionality. McClim is a free software implementation of the CLIM standard
So far the options selection interface has been ported to Linux.

### Text to Speech

There are several TTS engines in the public domain. Festival seems to be the most popular and is the same TTS engine used by Cuanimate.
No work has been done on this yet.

### Face animation

X-Face looks a likely candidate for this part of the application.
No work yet.

### Micro controller program

This is likely to be a re-write of the Nav & control program. This will be done using GCC compiler.
No work yet.