What I need is, I want to save an array of different sentences and let one of them randomly display on every pageload. Would that be possible? If yes, then how?
$a = array("red","green","blue","yellow","brown");
$random = array_rand($a);
echo $a[$random] ;
Related
i'm hoping to use qpdf for this.
I'm printing lots of small files and need to print them double sided, so I merge, say, 20 documents and wind up with a single 200 page pdf. I then can let the printer print, even pages reversed, then flip the stack over and put it back into the printer and print the odd ones, so we're using both sides of the paper.
my question is how i can detect and add a single blank page to the end of any document that has an odd number of pages; that way, when i do double sided printing, each document is completely separate from the others, rather than just printing on the back of a finished document.
If you have an odd number of pages, just call
cpdf -pad-multiple
with the even number one larger than the odd number. For example, for 19 pages, run
cpdf -pad-multiple 20 in.pdf -o out.pdf
You can get the number of pages with cpdf -pages.
Currently using FOSS qpdf 10.6.3 this is possible in windows by something like (note %% is for use in a batch.cmd)
for /f %%N in ('qpdf --show-npages in.pdf') do set VAR=%%N& set /a num=2*(%%N/2)+1& if .%num%.==.%var%. qpdf in.pdf --pages . blankA4P.pdf -- out.pdf
Note the integer maths is rounding odds down so 31 = 30+1 is a match but 32 = 32+1 will not match.
Without checking the dimensions of in.pdf is not easy to know if blankA4P.pdf is required so best to either get last page dimensions for a matching prepared page or batch apply each shape in groups.
using cpdf (as mentioned in previous answer) we could build a blank on demand along the lines of cpdf -create-pdf -create-pdf-pages 1 -o blank.pdf and use a page size, However cpdf has the even better option for OP case so simplest is cpdf -pad-multiple 2 in.pdf -o out.pdf as 1st hinted by johnwhittington
So now we have a perfect short one line solution. however cpdf is not FOSS
I have queried with qpdf if there may be a simpler way with just qpdf so watch this space https://github.com/qpdf/qpdf/issues/753
I will continue looking for a way to streamline this further because I would love a simpler workflow, but here is what I use to ensure I do not have two articles sharing one sheet of paper.
pacman::p_load(tidyverse, pdftools, qpdf)
# some prep
directory <- "Some/FileFolder/Path"
filelist <- (paste(directory, "/",
list.files(directory,
pattern = "*.pdf"), sep = ""))
# bust apart all pdf to inspect
my_pages <- as.list(lapply(filelist, pdf_split))
page_summ <- cbind.data.frame(filelist,
lengths(my_pages)) %>%
rename(filename = 1,
pages = 2) %>%
mutate(is_odd = pages %%2==1)
# separate into odd and even sets
odd_docs <- page_summ %>%
filter(is_odd == TRUE)
even_docs <- page_summ %>%
filter(is_odd == FALSE)
# I could not find an R process for adding a page to PDFs.
# For now, I will add a buffer page to docs via a PDF program.
# Once you are satisfied with your even_docs subset, pdf_combine
tocombine <- as.data.frame(even_docs$filename)
lapply(tocombine, pdf_combine)
This auto-generates the combo file into the previously defined directory. The new file name is not able to be set using "output = " within lapply(). Look for new file name = "firstnameintocombine_combined.pdf".
I have been struggling to return the count of courses from this XML file that contain "Cross-listed" as their description. The problem I encounter is because I am using for, it iterates and gives me "1 1" instead of "2". When I try using let instead I get 13 which means it counts all without condition even when I point return count($c["Cross-listed"]. What am I doing wrong and how can I fix it? Thanks in advance
for $c in doc("courses.xml")//Department/Course
where some $desc in $c/Description
satisfies contains($desc, "Cross-listed")
return count($c)
The problem I encounter is because I am using for
You are quite correct. You don't need to process items individually in order to count them.
You've made things much too difficult. You want
count(doc("courses.xml")//Department/Course[Description[contains(., "Cross-listed"]])
The key thing here is: you want a count, so call the count() function, and give it an argument which selects the set of things you want to include in the count.
I have 8 images in a directory.
the path is /blabla.com/img.
I need to access this path and choose 3 out of 8 randomly and display those.
If 3 pics are the same, it should echo "yeeey".
Otherwise, "neeey" and record these responses in a text file.
I am not going to do your homework for you!
However I can give you some insight:
store your 8 file names in an array
call $RANDOM % 8 3 times and store the value in 3 index variables
use the 3 index variables to extract your 3 files
use sha256sum, sha512sum or md5sum to compute the signature of your images and store the result in 3 variables
compare the values of the 3 variables if they are the same echo "yeeey" else echo "neeey"
if on top of that you want to display the picture as written in your post you could call eog or other similar tool with the finename as parameter and of course in background, with a & at the end of the command call.
Good luck with your assignment and let me know if you need help!
let's array an array of distinct elements (for example 8):
array=({A..H})
(1) use RANDOM special variable modulo the number of elements to get a random number between 0 and number-1 inclusive
number=$((RANDOM%${#array[#]}))
the first random element is
first=${array[number]}
remove the element from array and reassign the array to reindex without gap (declare -p array to see)
unset array[number]
array=("${array[#]}")
restart from (1)
I need to provide a listing of a website's pages. The only thing to change per line is the page number at the end of the line. So for example, I need to take:
mywebsite.com/things/stuff/?q=content&page=1
And from that generate a sequential listing of pages:
mywebsite.com/things/stuff/?q=content&page=1
mywebsite.com/things/stuff/?q=content&page=2
mywebsite.com/things/stuff/?q=content&page=3
I need to list all pages between 1 - 120.
I have been using bash but any shell that gets the job done is fine. I don't have any code to show because I simply just don't know how to begin. It sounds simple enough but so far I'm completely at a loss as to how I can accomplish this.
With GNU bash 4:
printf '%s\n' 'mywebsite.com/things/stuff/?q=content&page='{1..120}
You can simply use:
for i in $(seq 120); do echo 'mywebsite.com/things/stuff/?q=content&page='"$i"; done > list.txt
I am using ExifTool to change the camera body serial number to be a unique serial number for each image in a group of images numbering several hundred. The camera body serial number is being used as a second place, in addition to where the serial number for the image is in IPTC, to put the serial number as it takes a little more effort to remove.
The serial number is in the format ###-###-####-#### where the last four digits is the number to increment. The first three groups of digits do not change for each batch I run. I only need to increment that last group of digits.
EXAMPLE
I if I have 100 images in my first batch, they would be numbered:
811-010-5469-0001, 811-010-5469-0002, 811-010-5469-0003 ... 811-010-5469-0100
I can successfully drag a group of images onto my ExifTool Shortcut that has the values
exiftool(-SerialNumber='001-001-0001-0001')
and it will change the Exif SerialNumber Tag on the images, but have not been successful in what to add to this to have it increment for each image.
I have tried variations on the below without success:
exiftool(-SerialNumber+=001-001-0001-0001)
exiftool(-SerialNumber+='001-001-0001-0001')
I realize most likely ExifTool is seeing these as numbers being subtracted in the first line and seeing the second line as a string. I have also tried:
exiftool(-SerialNumber+='1')
exiftool(-SerialNumber+=1)
just to see if I can even get it to increment with a basic, single digit number. This also has not worked.
Maybe this cannot be incremented this way and I need to use ExifTool from the command line. If so, I am learning the command line/powershell (Windows), but am still weak in this area and would appreciate some pointers to get started there if this is the route I need to take. I am not afraid to use the command line, just would need a bit more hand holding then normal for a starting point. I also am learning Linux and could do this project from there but again, not afraid to use it, just would need a bit more hand holding to get it done.
I do program in PHP, JavaScript and other languages so code is not foreign to me. Just experience in writing it for the command-line.
If further clarification is needed, please let me know in the comments.
Your help and guidance is appreciated!
You'll probably have to go to the command line rather than rely upon drag and drop as this command relies upon ExifTool's advance formatting.
Exiftool "-SerialNumber<001-001-0001-${filesequence;$_=sprintf('%04d', $_+1 )}" <FILE/DIR>
If you want to be more general purpose and to use the original serial number in the file, you could use
Exiftool "-SerialNumber<${SerialNumber}-${filesequence;$_=sprintf('%04d', $_+1 )}" <FILE/DIR>
This will just add the file count to the end of the current serial number in the image, though if you have images from multiple cameras in the same directory, that could get messy.
As for using the command line, you just need to rename to remove the commands in the parens and then either move it to someplace in the command line's path or use the full path to ExifTool.
As for clarification on your previous attempts, the += option is used with numbers and with lists. The SerialNumber tag is usually a string, though that could depend upon where it's being written to.
If I understand your question correctly, something like this should work:
1..100 | % {
$sn = '811-010-5469-{0:D4}' -f $_
# apply $sn
}
or like this (if you iterate over files):
$i = 1
Get-ChildItem 'C:\some\folder' -File | % {
$sn = '811-010-5469-{0:D4}' -f $i
# update EXIF data of current file with $sn
$i++
}