Authentication Error in NodeJS Integration SurrealDB - surrealdb

I have recently come across SurrealDB, and installed it.
After adding to path, I started the server using surreal start --log trace --user root --pass root
.d8888b. 888 8888888b. 888888b.
d88P Y88b 888 888 'Y88b 888 '88b
Y88b. 888 888 888 888 .88P
'Y888b. 888 888 888d888 888d888 .d88b. 8888b. 888 888 888 8888888K.
'Y88b. 888 888 888P' 888P' d8P Y8b '88b 888 888 888 888 'Y88b
'888 888 888 888 888 88888888 .d888888 888 888 888 888 888
Y88b d88P Y88b 888 888 888 Y8b. 888 888 888 888 .d88P 888 d88P
'Y8888P' 'Y88888 888 888 'Y8888 'Y888888 888 8888888P' 8888888P'
[2022-09-27 17:37:44] INFO surrealdb::iam Root authentication is enabled
[2022-09-27 17:37:44] INFO surrealdb::iam Root username is 'root'
[2022-09-27 17:37:44] INFO surrealdb::dbs Database strict mode is disabled
[2022-09-27 17:37:44] INFO surrealdb::kvs Starting kvs store in memory
[2022-09-27 17:37:44] INFO surrealdb::kvs Started kvs store in memory
[2022-09-27 17:37:44] INFO surrealdb::net Starting web server on 0.0.0.0:8000
[2022-09-27 17:37:44] INFO surrealdb::net Started web server on 0.0.0.0:8000
In my NodeJS app, I have the following code (adapted from their docs):
import Surreal from 'surrealdb.js';
const db = new Surreal('http://localhost:8000/rpc');
async function main() {
try {
// Signin as a namespace, database, or root user
await db.signin({
user: 'root',
pass: 'root',
NS: 'practice',
DB: 'buybig'
});
console.log('y');
// Select a specific namespace / database
// await db.use('practice', 'buybig');
console.log(await db.select('users'));
} catch (e) {
console.error('ERROR', e);
}
}
main();
I am getting this error:
ERROR AuthenticationError: There was a problem with authentication
at Surreal._Surreal_signin (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/index.js:416:23) at Surreal.<anonymous> (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/index.js:225:111)
at Surreal.f (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:28:18)
at file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:34:22
at Array.forEach (<anonymous>)
at Surreal.emit (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:33:67)
at Socket.<anonymous> (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/index.js:126:29)
at file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:34:22
at Array.forEach (<anonymous>)
at Socket.emit (file:///C:/Users/jaide/OneDrive/Documents/Projects/HTMLProject/buybig/node_modules/surrealdb.js/esm/classes/emitter.js:33:67)
^C
And this in my SurrealDB logs:
[2022-09-27 18:06:04] INFO surreal::web 127.0.0.1:64675 GET /rpc HTTP/1.1 101 "-" 68.7µs
Accessing database through VSCode's Thunder Client and SurrealDB cli tool works flawlessly.
Any help is appreciated.

I tried that as well and got the same error. The following worked for me:
let dataBase = await new Surreal();
await dataBase.connect("http://127.0.0.1:8000/rpc");
await dataBase.signin({
user: "root",
pass: "root",
});
await dataBase.use("test", "test");
let result = await dataBase.create("user:someone", {
name: { first: "someone", last: "else" },
});
console.log(result);

Related

Remove duplicates in each individual column from a text file

I have a text file of 7 tab-delimited columns. Each column has a different number of lines with values that could be duplicated. I want to remove the duplicates so that each column has only unique values for that specific column. As an example:
Input
C1 C2 C3 C4 C5 C6 C7
111 111 222 333 111 222 777
222 111 333 333 222 333 666
222 111 444 111 333 555 555
333 444 555 222 444 666 444
444 666 555 777 555 666 333
444 777 777 555 666 888 333
777 888 999 666 888
999
Output
C1 C2 C3 C4 C5 C6 C7
111 111 222 333 111 222 777
222 444 333 111 222 333 666
333 666 444 222 333 555 555
444 777 555 777 444 666 444
777 888 777 555 555 888 333
999 999 666 666
888
I figure I would need to use awk to print each column and use sort -u separately, and then paste those outputs together. So, is there a way to make a loop that for i number of columns in a text file, would print each column | sort - u, and then paste it all together?
Thanks in advance,
Carlos
Using perl instead for its support of true multidimensional arrays:
perl -lane '
for my $n (0..$#F) {
if (!exists ${$vals[$n]}{$F[$n]}) {
push #{$cols[$n]}, $F[$n];
${$vals[$n]}{$F[$n]} = 1;
}
}
END {
for (1..$.) {
my #row;
for my $n (0..$#cols) {
push #row, shift #{$cols[$n]};
}
print join("\t", #row);
}
}' input.txt
Using any awk in any shell on every Unix box:
$ cat tst.awk
BEGIN { FS=OFS="\t" }
{
for (colNr=1; colNr<=NF; colNr++) {
val = $colNr
if ( !seen[colNr,val]++ ) {
rowNr = ++colRowNrs[colNr]
vals[rowNr,colNr] = val
numRows = (rowNr > numRows ? rowNr : numRows)
}
}
numCols = (NF > numCols ? NF : numCols)
}
END {
for (rowNr=1; rowNr<=numRows; rowNr++) {
for (colNr=1; colNr<=numCols; colNr++) {
val = vals[rowNr,colNr]
printf "%s%s", val, (colNr<numCols ? OFS : ORS)
}
}
}
$ awk -f tst.awk file
C1 C2 C3 C4 C5 C6 C7
111 111 222 333 111 222 777
222 444 333 111 222 333 666
333 666 444 222 333 555 555
444 777 555 777 444 666 444
777 888 777 555 555 888 333
999 999 666 666
888
Assumptions
an (awk) array of the entire output result will fit in memory
variable number of columns and rows
One idea consists of a (sparse) 2-dimensional array of values, where the array structure would look like:
values[<column#>][<row#>]=<unique_cell_value>
One idea using a single awk invocation that a) requires a single pass through the input file and b) does not require any transposing/pasting (in case anyone takes Cyrus' comment/suggestion seriously):
awk '
BEGIN { FS=OFS="\t" }
{ maxNF = (NF > maxNF ? NF : maxNF) # keep track of max number of columns
for (i=1; i<=NF; i++) {
if ( $i == "" ) # ignore empty cell
continue
for (j=1; j<=ndx[i]; j++) { # loop through values already seen for this column
if ( $i == vals[i][j] ) { # and if already seen then
$i = "" # clear the current cell and
break # break out of this for/testing loop
}
}
if ( $i != "" ) { # if we got this var and the cell is not empty then
vals[i][++ndx[i]] = $i # store the new value in our array
}
}
}
END { for (j=1; j<=NR; j++) { # loop through all possible rows
pfx = ""
for (i=1; i<=maxNF; i++) { # loop through all possible columns
printf "%s%s", pfx, vals[i][j] # non-existent array entries default to ""
pfx = OFS
}
printf "\n"
}
}
' input_file
NOTE: The array of arrays structure (arr[i][j]) requires GNU awk otherwise we could convert to a pseudo dual index array structure of arr[i,j]
This generates:
C1 C2 C3 C4 C5 C6 C7
111 111 222 333 111 222 777
222 444 333 111 222 333 666
333 666 444 222 333 555 555
444 777 555 777 444 666 444
777 888 777 555 555 888 333
999 999 666 666
888

zsh: no such file or directory error but file exist

I'm trying to run a compiler but I'm getting an error saying it can not be found, but it looks to exist and the path is good. I even tried a different shell incase zsh was mis-configured, but got the same error. Lost at what to do, any suggestions?
6909077c228a% ls -l toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
-rwxr-xr-x 2 root root 2287465 Sep 11 13:19 toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
6909077c228a% ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
zsh: no such file or directory: ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
#switch to bash
6909077c228a:~$ ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc
bash: ./toolchain/bin/armv7l-timesys-linux-gnueabi-gcc: No such file or directory
Edit:
Update showing suggestion, don't see any odd character inserted.
6909077c228a% ls -l toolchain/bin/armv7l-timesys-linux-gnueabi-gcc | od -xcb
0000000 722d 7877 2d72 7278 782d 3220 7220 6f6f
- r w x r - x r - x 2 r o o
055 162 167 170 162 055 170 162 055 170 040 062 040 162 157 157
0000020 2074 6f72 746f 3220 3832 3437 3536 5320
t r o o t 2 2 8 7 4 6 5 S
164 040 162 157 157 164 040 062 062 070 067 064 066 065 040 123
0000040 7065 3120 2031 3331 313a 2039 6f74 6c6f
e p 1 1 1 3 : 1 9 t o o l
145 160 040 061 061 040 061 063 072 061 071 040 164 157 157 154
0000060 6863 6961 2f6e 6962 2f6e 7261 766d 6c37
c h a i n / b i n / a r m v 7 l
143 150 141 151 156 057 142 151 156 057 141 162 155 166 067 154
0000100 742d 6d69 7365 7379 6c2d 6e69 7875 672d
- t i m e s y s - l i n u x - g
055 164 151 155 145 163 171 163 055 154 151 156 165 170 055 147
0000120 756e 6165 6962 672d 6363 000a
n u e a b i - g c c \n
156 165 145 141 142 151 055 147 143 143 012
Depending on how you typed in your initial ls -l line, there may be funny characters in the file name. If you use auto completion, it may have put those funny characters in for you so, if you subsequently attempt to type in the file name without auto completion, that could result in a file not found situation.
The first thing you should do is to check the filename completely, with something like:
ls -l toolchain/bin/armv7l-timesys-linux-gnueabi-gcc | od -xcb
and check the output to ensure there's no funny characters in the name.
If the file does exist in that for (no funny characters), one other possibility is that you're trying to run a 32-bit ELF program on a system that's not correctly set up to run them (i.e., a 64-bit system without the libraries and support infrastructure for 32-bit).
That results in an unhelpful error message since it really should be complaining about not being able to find the loader for your 32-bit executable, rather than the executable itself.
If this is the case, you will need to identify those missing items and install them.

printf colours not working from .bash_logout

I'm trying to use this lovely script on logout from an Ubuntu box that I'm ssh'd into. If I invoke it manually, the colours are correct. However, whenever it's run from .bash_logout, every line is white and prefixed with the colour code:
\x1B[38;5;160;01m .d8888b. 8888888888 8888888888 Y88b d88P .d88888b. 888 888
\x1B[38;5;196;01m d88P Y88b 888 888 Y88b d88P d88P" "Y88b 888 888
\x1B[38;5;202;01m "Y888b. 8888888 8888888 Y888P 888 888 888 888
\x1B[38;5;208;01m "Y88b. 888 888 888 888 888 888 888
\x1B[38;5;214;01m "888 888 888 888 888 888 888 888
\x1B[38;5;220;01m Y88b d88P 888 888 888 Y88b. .d88P Y88b. .d88P
\x1B[38;5;226;01m "Y8888P" 8888888888 8888888888 888 "Y88888P" "Y88888P"
TERM is set to xterm-256color in both the VM and my host (OS X 10.11). I tried using echo -e, but all it did was prepend the colour string with an -e. Adding the contents of the script directly to .bash_logout works, though that seems messy. Thoughts?
In POSIX shell, you cannot use \xXX escapes in the printf command; you can only use octal notation. Using . or source executes your script by the current bash process instead of using a POSIX shell. bash seeyou would have worked as well.
A POSIX-compliant version of your script would change the first line to:
ESC_SEQ="\033[38;5;"
Of course, there is no particular reason to make code executed only from .bash_logout POSIX-compliant, since the file itself is specific to bash.

Run script on powershell exit

How would I run a powershell script that would run on either, the exit command, or the shell closing. I would want this script to run on every shell close not just for one shell.
Script
Using Register-EngineEvent you can do this:
Register-EngineEvent PowerShell.Exiting –Action { 'Type your Code' }
# Alternatively with hiding the event:
Register-EngineEvent PowerShell.Exiting -SupportEvent –Action { yourExitFunction; }
Get it out of the function and run it in the scriptblock, like this:
Register-EngineEvent PowerShell.Exiting –Action {
$foo = #"
.d8888b. 8888888888 8888888888 Y88b d88P .d88888b. 888 888
d88P Y88b 888 888 Y88b d88P d88P" "Y88b 888 888
"Y888b. 8888888 8888888 Y888P 888 888 888 888
"Y88b. 888 888 888 888 888 888 888
"888 888 888 888 888 888 888 888
Y88b d88P 888 888 888 Y88b. d88P Y88b. .d88P
"Y8888P" 8888888888 8888888888 888 "Y88888P" "Y88888P"
.d8888b. 8888888b. d8888 .d8888b. 8888888888
d88p Y88b 888 Y88b d88888 d88P Y88b 888
"Y888b. 888 d88P d88P 888 888 8888888
"Y88b. 8888888P" d88P 888 888 888
"888 888 d88P 888 888 888 888
Y88b d88P 888 d8888888888 Y88b d88P 888
"Y8888P" 888 d88P 888 "Y8888P" 8888888888
.d8888b. .d88888b. 888 888 888888b. .d88888b. Y88b d88P
d88P Y88b d88P" "Y88b 888 o 888 888 "88b d88P" "Y88b Y88b d88P
888 888 888 888 d888b 888 8888888K. 888 888 Y888P
888 888 888 8888888888888 888 "Y88b 888 888 888
888 888 888 888 88888P Y88888 888 888 888 888 888
Y88b d88P Y88b. .d88P 8888P Y8888 888 d88P Y88b. .d88P 888
"Y8888P" "Y88888P" 888P Y888 8888888P" "Y88888P" 888
"#
$file="c:\.seeyouspacecowboy"
$foo | out-file $file
$colour=("red","yellow","darkyellow","green","cyan","darkcyan","darkmagenta")
[int]$num=-1
$info = (get-content $file)
Write-Host ""
foreach($i in $info)
{
[int]$perspective=($num / 3)
write-host $i -foregroundcolor $colour[$perspective]
$num++
}
Write-Host ""
}
*of course, make sure you are with admin privilege as it write to c:\
Another option is a try-finally block, which will execute the finally block on error or ctrl-c:
try {
# Main code
} finally {
# Code to run on exit
}

bash remove all but one duplicate matches from a file

I have a large file consisting of test failures. A number of these tests have duplicate failures. I want to remove all duplicates, keeping one of each type. Here is an excerpt from the file:
034 [power] 34 of 343 check
056 [drive] 666 of 3345
099 [power] 53 of 4354
103 [power] 60 of 4354
231 [cpu] 2 of 653
437 [drive] 65 of 879
862 [speed] 864 of 4397 fast
In this example I want to remove the duplicates i.e. the additional [power] and [drive] lines
034 [power] 34 of 343 check
056 [drive] 666 of 3345
231 [cpu] 2 of 653
862 [speed] 864 of 4397 fast
I tried it using a combination of grep -m 1 and grep -v but unfortunately that did not work.
like this?
kent$ awk '!a[$2]++' file
034 [power] 34 of 343 check
056 [drive] 666 of 3345
231 [cpu] 2 of 653
862 [speed] 864 of 4397 fast

Resources