Rangeslider ACF in Foreach loop - foreach

I have a range slider in my Advanced custom fields. I want the number to be the amount of list items that it echo's out. In example, i put the range slider on 4 in ACF then it needs to echo out:
Flywheel 1
Flywheel 2
Flywheel 3
Flywheel 4
This is the code i have but it's not working, can someone please fix the code?
<?php
$flywheelnumber = get_field('flywheels');
if( $flywheelnumber ) {
echo '<form class="checklist-list">';
echo '<ul>';
foreach($flywheelnumber) {
echo '<li>';
echo ( $numbers );
echo '</li>';
}
echo '</ul>';
echo '</form>'
}
?>
Thanks!!

you have to use for loop. you can try these codes,
<?php
$flywheelnumber = get_field( 'flywheels' );
if ( $flywheelnumber ) {
echo '<form class="checklist-list">';
echo '<ul>';
for ( $x = 1; $x <= count( $flywheelnumber ); $x ++ ) {
echo '<li>' . $x . '</li>';
}
echo '</ul>';
echo '</form>';
}
?>

Related

how to extent this code to accommodate D and E drives as well

I would like to extent the following code to accommodate all other drives on my machine.
Below code was written only on C drive..i am having difficulty modifying it, tried seperating values for driveletters, but the code is not displaying anything when run..
$ServerListFile = "D:\serverList.txt"
$ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue
$Result = #()
ForEach($c`enter code here`omputername in $ServerList)
{
$AVGProc = Get-WmiObject -computername $computername win32_processor |
Measure-Object -property LoadPercentage -Average | Select Average
$OS = gwmi -Class win32_operatingsystem -computername $computername |
Select-Object #{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize -
$_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }}
$vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" |
Select-object #{Name = "C PercentFree"; Expression = {“{0:N2}” -f (($_.FreeSpace / $_.Capacity)*100)
} }
$result += [PSCustomObject] #{
ServerName = "$computername"
CPULoad = "$($AVGProc.Average)%"
MemLoad = "$($OS.MemoryUsage)%"
CDrive = "$($vol.'C PercentFree')%"
}
$Outputreport = "<HTML><TITLE> Server Health Report </TITLE>
<BODY background-color:peachpuff>
<font color =""#99000"" face=""Microsoft Tai le"">
<H2> Server Health Report </H2></font>
<Table border=1 cellpadding=0 cellspacing=0>
<TR bgcolor=gray align=center>
<TD><B>Server Name</B></TD>
<TD><B>Avrg.CPU Utilization</B></TD>
<TD><B>Memory Utilization</B></TD>
<TD><B>Drive C Free Space</B></TD>
</TR>"
Foreach($Entry in $Result)
{
if(($Entry.CpuLoad) -or ($Entry.memload) -ge "80")
{
$Outputreport += "<TR bgcolor=white>"
}
else
{
$Outputreport += "<TR>"
}
$Outputreport += "<TD>$($Entry.Servername)</TD><TD align=center>$($Entry.CPULoad)</TD><TD
align=center>$($Entry.MemLoad)</TD><TD align=center>$($Entry.CDrive)</TD></TR>"
}
$Outputreport += "</Table></BODY></HTML>"
}
$Outputreport | out-file "D:\Result $(Get-Date -Format yyy-mm-dd-hhmm).htm"

field separator in awk

I have the following "input.file":
10 61694 rs546443136 T G . PASS RefPanelAF=0.0288539;AC=0;AN=1186;INFO=1.24991e-09 GT:DS:GP 0/0:0.1:0.9025,0.095,0.0025 0/0:0.1:0.9025,0.095,0.0025 0/0:0.1:0.9025,0.095,0.0025
My desired output.file is:
0.1, 0.1, 0.1
Using an awk script called "parse.awk":
BEGIN {FS = ":"}
{for (i = 4; i <= NF; i += 2) printf ("%s%c", $i, i +2 <= NF ? "," : "\n ");}
which is invocated with:
awk -f parse.awk <input.file >output.file
my current output.file is as follows:
0.1,0.1,0.1
i.e. no spaces.
Changing pasre.awk to:
BEGIN {FS = ":"}
{for (i = 4; i <= NF; i += 2) printf ("%s%c", $i, i +2 <= NF ? ", " : "\n ");}
did not change the output.file. What change(s) to parse.awk will yield the desired output.file?
You may use this awk:
awk -F: -v OFS=', ' '{
for (i = 4; i <= NF; i += 2) printf "%s%s", $i, (i < NF-1 ? OFS : ORS)}' file
0.1, 0.1, 0.1
Could you please try following. Written and tested it in
https://ideone.com/e26q7u
awk '
BEGIN {FS = ":"}
val!=""{ print val; val=""}
{for (i = 4; i <= NF; i += 2){
val=(val==""?"":val", ")$i
}
}
END{
if(val!=""){
print val
}
}
' Input_file
The problem is when you changed the output separator from a single comma (",") to comma with space (", "); you did not change the format string from %c to %s. So that is how to fix your script:
BEGIN {FS = ":"}
{for (i = 4; i <= NF; i += 2) printf ("%s%s", $i, i +2 <= NF ? ", " : "\n ");}
# ^ Change this

Jenkins pipeline groovy string compare

When I use Jenkins pipeline through with Docker, I want to compare string value with Groovy script, but the compare result was wrong, the follow script is my groovy script and the output result:
Is there anyone can tell me how resolve this problem?
String runningContainerId = sh(script: "docker ps --filter=\"name=${appEnv}-${env.JOB_NAME}-${env.BUILD_NUMBER}\" -q | xargs", returnStdout: true)
//def runningImageId = sh(script: "docker images | grep ${appEnv}-${env.JOB_NAME}:${env.BUILD_NUMBER} | tr -s ' ' | cut -d ' ' -f 3 ", returnStdout: true)
println 'current container:' + runningContainerId
//println runningImageId
try{
def ret = sh(script: "docker ps --filter=\"name=${appEnv}-${env.JOB_NAME}\" -q | xargs", returnStdout: true)
def splitStr = ret.tokenize(" ")
println 'splitStr=>' + splitStr
String containerId = runningContainerId
println 'containerId=>' + containerId
for( String str in splitStr) {
print str == containerId
print 'str=>' + str
if ( str == containerId) {
print 'same string:' + str
} else {
print 'different string:' + str
}
}
Jenkins output result is:
splitStr=>[8abe81071b7f, 40e2292d5099, 4136bbdf9cc5]
[Pipeline] echo
containerId=>8abe81071b7f
[Pipeline] echo
false
[Pipeline] echo
str=>8abe81071b7f
[Pipeline] echo
different string:8abe81071b7f
[Pipeline] echo
false
[Pipeline] echo
str=>40e2292d5099
[Pipeline] echo
different string:40e2292d5099
[Pipeline] echo
false
[Pipeline] echo
str=>4136bbdf9cc5
[Pipeline] echo
different string:4136bbdf9cc5

Youtube video title and duration without api key

How can get the youtube video title and duration without using api key ?
I have checked Youtube Video title with API v3 without API key? link but this only give the title and not the duration.
So how can I get duration also without api key ?
To people looking for an answer to this in 2020. You can do this using the Youtube Iframe API. You don't need a API key!
First you insert the api link into the JS like so:
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
After that you create the player with the desired videoID like this:
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'SIWbjgPYcJY',
playerVars: {
'autoplay': 0,
'controls': 1
},
events: {
'onReady': onPlayerReady
}
});
}
Then you need to get the title and duration by assigning these in a variable to your HTML. We place this in the onPlayerReady.
function onPlayerReady(event) {
time = player.getDuration();
$(".dur").val(time);
title = player.getVideoData().title
$(".title").val(title);
}
Last thing is to put the player, duration and title in the HTML:
<div id="player"></div>
<br>
<span>Titel:</span><input class="title">
<br>
<span>duration:</span><input class="dur">
<br>
JSFIDDLE
You can use youtube-dl:
$ youtube-dl -e "https://www.youtube.com/watch?v=2i2khp_npdE"
Alan Walker - Sing Me To Sleep
$ youtube-dl --get-duration "https://www.youtube.com/watch?v=2i2khp_npdE"
3:12
Alternatively:
$ curl -s "https://www.youtube.com/watch?v=2i2khp_npdE" | tr '<' '\n' | awk -F'"' '/name="title"/ { print $4 }'
Alan Walker - Sing Me To Sleep
$ curl -s "https://www.youtube.com/watch?v=2i2khp_npdE" | awk -F'"' '/itemprop="duration"/ { print $4 }'
PT3M12S
You can use this bash function to convert from the Youtube format to seconds:
duration_calculation ()
{
local total_in_second=0
local hours=0
local minutes=0
local seconds=0
local duration="$1"
if [[ $duration =~ ^PT([0-9]{1,})H([0-9]{1,})M([0-9]{1,})S$ ]]; then
hours=$((hours + BASH_REMATCH[1]))
minutes=$((minutes + BASH_REMATCH[2]))
seconds=$((seconds + BASH_REMATCH[3]))
# PT1H4M H:M:00
elif [[ $duration =~ ^PT([0-9]{1,})H([0-9]{1,})M$ ]];then
hours=$((hours + BASH_REMATCH[1]))
minutes=$((minutes + BASH_REMATCH[2]))
# PT1H29S H:00:S
elif [[ $duration =~ ^PT([0-9]{1,})H([0-9]{1,})S$ ]]; then
hours=$((hours + BASH_REMATCH[1]))
seconds=$((seconds + BASH_REMATCH[2]))
# PT4M29S M:S
elif [[ $duration =~ ^PT([0-9]{1,})M([0-9]{1,})S$ ]]; then
minutes=$((minutes + BASH_REMATCH[1]))
seconds=$((seconds + BASH_REMATCH[2]))
# PT1H H:00:00
elif [[ $duration =~ ^PT([0-9]{1,})H$ ]]; then
hours=$((hours + BASH_REMATCH[1]))
# PT4M 00:M:00
elif [[ $duration =~ ^PT([0-9]{1,})M$ ]]; then
minutes=$((minutes + BASH_REMATCH[1]))
# PT29S S
elif [[ $duration =~ ^PT([0-9]{1,})S$ ]]; then
seconds=$((seconds + BASH_REMATCH[1]))
fi
total_in_seconds=$(( (hours * 3600) + (minutes * 60) + seconds ))
echo "$total_in_seconds"
}

Parsing robocopy log file to PSCustomObject

I'm trying to create a PSCustomObject from a robocopy log file. The first piece is pretty easy but I'm struggling with the $Footer part. I can't seem to find a good way to split up the values.
It would be nice if every entry has it's own Property, so it's possible to use for example $Total.Dirs or $Skipped.Dirs. I was thinking about Import-CSV, because that's just great on how it allows you to have column headers. But this doesn't seem to fit here. There's another solution I found here but it seems a bit of overkill.
Code:
Function ConvertFrom-RobocopyLog {
Param (
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[String]$LogFile
)
Process {
$Header = Get-Content $LogFile | select -First 10
$Footer = Get-Content $LogFile | select -Last 7
$Header | ForEach-Object {
if ($_ -like "*Source*") {$Source = (($_.Split(':'))[1]).trim()}
if ($_ -like "*Dest*") {$Destination = (($_.Split(':'))[1]).trim()}
}
$Footer | ForEach-Object {
if ($_ -like "*Dirs*") {$Dirs = (($_.Split(':'))[1]).trim()}
if ($_ -like "*Files*") {$Files = (($_.Split(':'))[1]).trim()}
if ($_ -like "*Times*") {$Times = (($_.Split(':'))[1]).trim()}
}
$Obj = [PSCustomObject]#{
'Source' = $Source
'Destination' = $Destination
'Dirs' = $Dirs
'Files' = $Files
'Times' = $Times
}
Write-Output $Obj
}
}
Log file:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Wed Apr 01 14:28:11 2015
Source : \\SHARE\Source\
Dest : \\SHARE\Target\
Files : *.*
Options : *.* /S /E /COPY:DAT /PURGE /MIR /Z /NP /R:3 /W:3
------------------------------------------------------------------------------
0 Files...
0 More Folders and files...
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 2 0 2 0 0 0
Files : 203 0 203 0 0 0
Bytes : 0 0 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Wed Apr 01 14:28:12 2015
Thank you for your help.
You can clean this up more but this is the basic approach I would take.
Function ConvertFrom-RobocopyLog {
Param (
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[String]$LogFile
)
Process {
$Header = Get-Content $LogFile | select -First 10
$Footer = Get-Content $LogFile | select -Last 7
$Header | ForEach-Object {
if ($_ -like "*Source*") {$Source = (($_.Split(':'))[1]).trim()}
if ($_ -like "*Dest*") {$Destination = (($_.Split(':'))[1]).trim()}
}
$Footer | ForEach-Object {
if ($_ -like "*Dirs*"){
$lineAsArray = (($_.Split(':')[1]).trim()) -split '\s+'
$Dirs = [pscustomobject][ordered]#{
Total = $lineAsArray[0]
Copied = $lineAsArray[1]
Skipped = $lineAsArray[2]
Mismatch = $lineAsArray[3]
FAILED = $lineAsArray[4]
Extras = $lineAsArray[5]
}
}
if ($_ -like "*Files*"){
$lineAsArray = ($_.Split(':')[1]).trim() -split '\s+'
$Files = [pscustomobject][ordered]#{
Total = $lineAsArray[0]
Copied = $lineAsArray[1]
Skipped = $lineAsArray[2]
Mismatch = $lineAsArray[3]
FAILED = $lineAsArray[4]
Extras = $lineAsArray[5]
}
}
if ($_ -like "*Times*"){
$lineAsArray = ($_.Split(':',2)[1]).trim() -split '\s+'
$Times = [pscustomobject][ordered]#{
Total = $lineAsArray[0]
Copied = $lineAsArray[1]
FAILED = $lineAsArray[2]
Extras = $lineAsArray[3]
}
}
}
$Obj = [PSCustomObject]#{
'Source' = $Source
'Destination' = $Destination
'Dirs' = $Dirs
'Files' = $Files
'Times' = $Times
}
Write-Output $Obj
}
}
I wanted to make a function to parse the footer lines but $Times is a special case since it does not have all the same columns of data.
With $Times the important difference is how we are doing the split. Since the string contains more than one colon we need to account for that. Using the other paramenter in .Split() we specify the number of elements to return.
$_.Split(':',2)[1]
Since these logs always have output and no blanks row elements we can do this assuming that the parsed elements of $lineAsArray will always have 6 elements.
Sample Output
Source : \\SHARE\Source\
Destination : \\SHARE\Target\
Dirs : #{Total=2; Copied=0; Skipped=2; Mismatch=0; FAILED=0; Extras=0}
Files : #{Total=203; Copied=0; Skipped=203; Mismatch=0; FAILED=0; Extras=0}
Times : #{Total=0:00:00; Copied=0:00:00; FAILED=0:00:00; Extras=0:00:00}
So if you wanted the total files copied you can now use dot notation.
(ConvertFrom-RobocopyLog C:\temp\log.log).Files.Total
203
Not that clear what you want to do, but this will go some way to showing you how to get the stats into an array of objects
$statsOut = #()
$stats = Get-Content $LogFile | select -Last 6 | select -first 4
$stats | % {
$s = $_ -split "\s+"
$o = new-object -type pscustomobject -property #{"Name"=$s[0];"Total"=$s[2];"Copied"=$s[3];"Skipped"=$s[4];"mismatch"=$s[5]};
$statsOut += ,$o
}
Gives:
[PS] > $statsOut | ft -Auto
mismatch Name Skipped Total Copied
-------- ---- ------- ----- ------
0 Dirs 2 2 0
0 Files 203 203 0
0 Bytes 0 0 0

Resources