How to I pass a list to cl-mustache? - common-lisp

I am trying to use CL-MUSTACHE. Rendering atomic variables works fine, following the examples in the README file:
> (mustache:mustache-render-to-string "{{year}}-{{month}}-{{day}}"
'((:year . "2012")
(:month . "07")
(:day . "02")))
"2012-07-02"
However, I am unable to figure out how to pass a list to render a section multiple times. The README file does not have an example, and the ways I have tried don't work. For example:
(mustache:mustache-render-to-string "{{#dates}}{{year}}-{{month}}-{{day}}
{{/dates}}"
'((:dates . (((:year . "2012")
(:month . "07")
(:day . "02"))
((:year . "2013")
(:month . "08")
(:day . "03"))))))
"--
"

I don't have it to check, but from the documentation, it seems that arrays are treated as CL arrays, so you can try this to see if it works:
(mustache:mustache-render-to-string "{{#dates}}{{year}}-{{month}}-{{day}}{{/dates}}"
'((:dates . #( ((:year . "2012")
(:month . "07")
(:day . "02"))
((:year . "2013")
(:month . "08")
(:day . "03"))))))
(that is, an array of lists of parameters).

Related

Show last image from directory on website

I have a video camera that uploads via FTP only to preset folders. It uploads to a tree, like this /www/wp-content/uploads/camer/10.121.0.202/2021-01-02/D3. I need to show the last uploaded image on the website. I need to take this folder /www/wp-content/uploads/camer/10.121.0.202/ and find the newest file and show it on the website. My website is running on WordPress.
I don't know whether there is a dedicated plugin for this but the following lets you do basically everything.
Install Insert PHP Code Snippet
Add the following code snippet and save it as e.g. 'getlatestfile'. Adjust the base_path and maybe the relative ../ according to which page you want to display the image OR make it absolute.
<?php
$base_path = 'wp-content/uploads/camera';
$latest_folder = scandir($base_path, SCANDIR_SORT_DESCENDING);
$latest_file = scandir($base_path . "/" . $latest_folder[0], SCANDIR_SORT_DESCENDING);
echo "<img src='../" . $base_path . "/" . $latest_folder[0] . "/" . $latest_file[0] . "' />";
?>
Add [xyz-ips snippet="getlatestfile"] to the page where you want your image.
I assumed that your camera folder only contains folders and that they all have the same date format. Also the files inside the date folder like 'D3' should be ascending in time (hexadecimal). So the next image would be 'D4' etc.
EDIT:
If D3, D4, ... are folders which contain the images add another scandir
<?php
$base_path = 'wp-content/uploads/camera';
$latest_date_folder = scandir($base_path, SCANDIR_SORT_DESCENDING);
$latest_folder = scandir($base_path . "/" . $latest_date_folder[0], SCANDIR_SORT_DESCENDING);
$latest_file = scandir($base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0] , SCANDIR_SORT_DESCENDING);
echo "<img src='../" . $base_path . "/" . $latest_date_folder[0] . "/" . $latest_folder[0] . "/" . $latest_file[0] . "' />";
?>

file_exists(get_template_directory() - what's wrong?

I've got an fatal error: syntax error, unexpected '")) {
' (T_CONSTANT_ENCAPSED_STRING) in these lines:
if (file_exists(get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php")) {
include_once get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php';
}
I tried to check it in IDE and in IDE ".php")) it says 'expected semicolon'. Where is the problem? What I made wrong?
You got your string seperators mixed up. Either use single quotes for everything or double quotes for everything, but make sure you don't mix them up.
That's what happened in line 2 of your code sample:
# your code
include_once [...] . ".php';
# should be
include_once [...] . ".php";
Make sure to use an editor like Visual Studio Code or anything else that helps you find those things through code highlighting or a linter that will check your code while you type.
edit: See how even StackOverflows code highlighting gives you a hint, because lines 3 and 4 in my code block are marked as a string. That's a pretty good clue that something's wrong.
if (file_exists(get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php")) {
include_once get_template_directory() . DIRECTORY_SEPARATOR . "." . basename(get_template_directory()) . ".php';
}
Problem is in last line
basename(get_template_directory()) . ".php’
It should be
basename(get_template_directory()) . ".php";

How to get the network properties in R [duplicate]

Does anyone know of an R function that is able to retrieve one's own IP address (of the PC you're working on)? It would be very helpful! Many thanks in advance.
You can issue a system() command to your operating system:
In Windows you can use ipconfig
In Linux, use ifconfig
For example, on Windows try calling system() with the argument intern=TRUE to return the results to R:
x <- system("ipconfig", intern=TRUE)
This returns:
x
[1] ""
[2] "Windows IP Configuration"
[3] ""
[4] ""
[5] "Wireless LAN adapter Wireless Network Connection:"
[6] ""
[7] " Connection-specific DNS Suffix . : tbglondon.local"
[8] " Link-local IPv6 Address . . . . . : fe80::c0cb:e470:91c7:abb9%14"
[9] " IPv4 Address. . . . . . . . . . . : 10.201.120.184"
[10] " Subnet Mask . . . . . . . . . . . : 255.255.255.0"
[11] " Default Gateway . . . . . . . . . : 10.201.120.253"
[12] ""
[13] "Ethernet adapter Local Area Connection:"
[14] ""
[15] " Connection-specific DNS Suffix . : tbglondon.local"
[16] " Link-local IPv6 Address . . . . . : fe80::9d9b:c44c:fd4d:1c77%11"
[17] " IPv4 Address. . . . . . . . . . . : 10.201.120.157"
[18] " Subnet Mask . . . . . . . . . . . : 255.255.255.0"
[19] " Default Gateway . . . . . . . . . : 10.201.120.253"
[20] ""
[21] "Tunnel adapter Local Area Connection* 13:"
[22] ""
[23] " Media State . . . . . . . . . . . : Media disconnected"
[24] " Connection-specific DNS Suffix . : "
[25] ""
[26] "Tunnel adapter isatap.tbglondon.local:"
[27] ""
[28] " Media State . . . . . . . . . . . : Media disconnected"
[29] " Connection-specific DNS Suffix . : tbglondon.local"
[30] ""
[31] "Tunnel adapter Teredo Tunneling Pseudo-Interface:"
[32] ""
[33] " Media State . . . . . . . . . . . : Media disconnected"
[34] " Connection-specific DNS Suffix . : "
Now you can use grep to find the lines with IPv4:
x[grep("IPv4", x)]
[1] " IPv4 Address. . . . . . . . . . . : 10.201.120.184"
[2] " IPv4 Address. . . . . . . . . . . : 10.201.120.157"
And to extract just the ip address:
z <- x[grep("IPv4", x)]
gsub(".*? ([[:digit:]])", "\\1", z)
"10.201.120.184" "10.201.120.157"
I recently created a minimal package using ipify.org to do this exact thing.
Usage is easy, you can install using devtools and github.
library(devtools)
install_github("gregce/ipify")
once installed, its as easy as loading the library and one function call...
library(ipify)
get_ip()
Though #andrie explained it in very layman language and i am sure it helped us a lot to understand the functionality of it.
So from there only sharing a one liner code without installing any other package.
gsub(".*? ([[:digit:]])", "\\1", system("ipconfig", intern=T)[grep("IPv4", system("ipconfig", intern = T))])
Hope this would be helpful!
This retrieves exactly what you want:
system('ipconfig getifaddr en0')
192.168.1.73

copy a line with specific pattern and paste it below in unix without opening a file

I have a specific requirement.
I have file:
some text
. . . . .
. . . . .
**todo: owner comments . . . .**
... .
sometext
Now I want the output like:
some text
. . . . .
. . . . .
**todo: owner comments . . . .**
**owner: todo comments . . . .**
... .
.
sometext
I want to grep for todo and copy that line and paste it below with above modification.
Can it be possible without opening a file... like sed,awk command ??
Thanks and Regards,
Dharak
I guess what you mean is opening the file in an editor. Here is an awk script you can tailor for your needs.
$ awk '/\*\*todo:/{print; print "**owner: todo ... ";next}1' file
some text
. . . . .
. . . . .
**todo: owner comments . . . .**
**owner: todo ...
... .
sometext
you can save the output to a temp file and move over to your original file.
sed 's/\(**todo: owner comments\)\(.*\)/\1 \2 \
> **owner: todo comments \2/g' filename
Patterns matched and replaced
New line is inserted manually by placing an enter after '\' at end of first line
'>' will come automatically pointing for the next characters to be inserted

Function for retrieving own ip address from within R?

Does anyone know of an R function that is able to retrieve one's own IP address (of the PC you're working on)? It would be very helpful! Many thanks in advance.
You can issue a system() command to your operating system:
In Windows you can use ipconfig
In Linux, use ifconfig
For example, on Windows try calling system() with the argument intern=TRUE to return the results to R:
x <- system("ipconfig", intern=TRUE)
This returns:
x
[1] ""
[2] "Windows IP Configuration"
[3] ""
[4] ""
[5] "Wireless LAN adapter Wireless Network Connection:"
[6] ""
[7] " Connection-specific DNS Suffix . : tbglondon.local"
[8] " Link-local IPv6 Address . . . . . : fe80::c0cb:e470:91c7:abb9%14"
[9] " IPv4 Address. . . . . . . . . . . : 10.201.120.184"
[10] " Subnet Mask . . . . . . . . . . . : 255.255.255.0"
[11] " Default Gateway . . . . . . . . . : 10.201.120.253"
[12] ""
[13] "Ethernet adapter Local Area Connection:"
[14] ""
[15] " Connection-specific DNS Suffix . : tbglondon.local"
[16] " Link-local IPv6 Address . . . . . : fe80::9d9b:c44c:fd4d:1c77%11"
[17] " IPv4 Address. . . . . . . . . . . : 10.201.120.157"
[18] " Subnet Mask . . . . . . . . . . . : 255.255.255.0"
[19] " Default Gateway . . . . . . . . . : 10.201.120.253"
[20] ""
[21] "Tunnel adapter Local Area Connection* 13:"
[22] ""
[23] " Media State . . . . . . . . . . . : Media disconnected"
[24] " Connection-specific DNS Suffix . : "
[25] ""
[26] "Tunnel adapter isatap.tbglondon.local:"
[27] ""
[28] " Media State . . . . . . . . . . . : Media disconnected"
[29] " Connection-specific DNS Suffix . : tbglondon.local"
[30] ""
[31] "Tunnel adapter Teredo Tunneling Pseudo-Interface:"
[32] ""
[33] " Media State . . . . . . . . . . . : Media disconnected"
[34] " Connection-specific DNS Suffix . : "
Now you can use grep to find the lines with IPv4:
x[grep("IPv4", x)]
[1] " IPv4 Address. . . . . . . . . . . : 10.201.120.184"
[2] " IPv4 Address. . . . . . . . . . . : 10.201.120.157"
And to extract just the ip address:
z <- x[grep("IPv4", x)]
gsub(".*? ([[:digit:]])", "\\1", z)
"10.201.120.184" "10.201.120.157"
I recently created a minimal package using ipify.org to do this exact thing.
Usage is easy, you can install using devtools and github.
library(devtools)
install_github("gregce/ipify")
once installed, its as easy as loading the library and one function call...
library(ipify)
get_ip()
Though #andrie explained it in very layman language and i am sure it helped us a lot to understand the functionality of it.
So from there only sharing a one liner code without installing any other package.
gsub(".*? ([[:digit:]])", "\\1", system("ipconfig", intern=T)[grep("IPv4", system("ipconfig", intern = T))])
Hope this would be helpful!
This retrieves exactly what you want:
system('ipconfig getifaddr en0')
192.168.1.73

Resources