Why Upgrading to Alpinejs 3.2 menu does noes not work? - alpine.js
In Laravel 8 / Alpinejs 2.8 app I had toggle menu like
<!--Toggle button (hidden on large screens)-->
<button
#click="isOpen = !isOpen"
type="button"
class="block lg:hidden px-2 text-gray-500 hover:text-white focus:outline-none focus:text-white"
:class="{ 'transition transform-180': isOpen }"
>
<svg
class="h-6 w-6 fill-current"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
>
<path
x-show="isOpen"
fill-rule="evenodd"
clip-rule="evenodd"
d="M18.278 16.864a1 1 0 0 1-1.414 1.414l-4.829-4.828-4.828 4.828a1 1 0 0 1-1.414-1.414l4.828-4.829-4.828-4.828a1 1 0 0 1 1.414-1.414l4.829 4.828 4.828-4.828a1 1 0 1 1 1.414 1.414l-4.828 4.829 4.828 4.828z"
/>
<path
x-show="!isOpen"
fill-rule="evenodd"
d="M4 5h16a1 1 0 0 1 0 2H4a1 1 0 1 1 0-2zm0 6h16a1 1 0 0 1 0 2H4a1 1 0 0 1 0-2zm0 6h16a1 1 0 0 1 0 2H4a1 1 0 0 1 0-2z"
/>
</svg>
</button>
<!--Menu-->
<div
class="w-full flex-grow lg:flex lg:items-center lg:w-auto"
:class="{ 'block shadow-3xl': isOpen, 'hidden': !isOpen }"
#click.away="isOpen = false"
x-show.transition="true"
>
<ul
class="pt-6 lg:pt-0 list-reset lg:flex justify-end flex-1 items-center"
>
<li class="mr-3">
and it worked ok.
Upgrading to Alpinejs 3.2 modified
#click.away="isOpen = false"
with #click.away="isOpen = false"
with
#click.outside="isOpen = false"
and
x-show.transition="true"
into
x-show="true"
x-transition
but after that drop down menu is not visible at all.
Why so and how it can be fixed?
MODIFIED # 1:
If to change x-show="isOpen" for menu then yes, on small devices menu works as expected, but
on big devices it is not visible at all
I need somehow to set init value to true on big devices. Condition :
x-show="isOpen"
md:x-show="true"
x-transition
does not work
I think I can use package https://github.com/jenssegers/agent to get this value depending on current device.
Are there better decision?
Could you please explain how devtools were usefull in this debugging?
Thanks!
If you check it in devtools it is actually works as expected when you toggle isOpen state. The problem is when you click button it is also considered as click.away out of menu. I'll suggest to set this click on a parent element. Also I change menu settings - x-show set to isOpen like x-show="isOpen" and toggle statement will handle visibility of element with Tailwind's visible class
<div
x-data="{ isOpen: false }"
#click.outside="isOpen = false"
>
<button
#click="isOpen = !isOpen"
type="button"
class="block lg:hidden px-2 text-gray-500 focus:outline-none"
:class="{ 'transition transform-180': isOpen }"
>
<svg
class="w-6 h-6 fill-current"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
>
<path
x-show="isOpen"
fill-rule="evenodd"
clip-rule="evenodd"
d="M18.278 16.864a1 1 0 0 1-1.414 1.414l-4.829-4.828-4.828 4.828a1 1 0 0 1-1.414-1.414l4.828-4.829-4.828-4.828a1 1 0 0 1 1.414-1.414l4.829 4.828 4.828-4.828a1 1 0 1 1 1.414 1.414l-4.828 4.829 4.828 4.828z"
/>
<path
x-show="!isOpen"
fill-rule="evenodd"
d="M4 5h16a1 1 0 0 1 0 2H4a1 1 0 1 1 0-2zm0 6h16a1 1 0 0 1 0 2H4a1 1 0 0 1 0-2zm0 6h16a1 1 0 0 1 0 2H4a1 1 0 0 1 0-2z"
/>
</svg>
</button>
<!--Menu-->
<div
class="flex-grow w-full lg:flex shadow-3xl lg:items-center lg:w-auto"
:class="[ isOpen ? 'visible' : 'unvisible' ]"
x-show="isOpen"
x-transition
>
<ul
class="items-center justify-end flex-1 pt-6 lg:pt-0 list-reset lg:flex"
>
<li class="mr-3">Link 1</li>
<li class="mr-3">Link 2</li>
</ul>
</div>
</div>
Related
perfectly looping svg animation
I am trying to loop an audio wave svg so that it's perfectly looping but I cannot figure it out. I currently have the below, however, as you will see the loop is not perfect. Is there an easy way to do this? Or can someone point me in the right direction? <?xml version="1.0" encoding="utf-8"?> <svg version="1.1" id="waveform" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 220 100" style="enable-background:new 0 0 220 100;" xml:space="preserve"> <g id="waveform"> <path d="M186.4,0c-1.3,0.1-2.2,1.3-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6V2.6C188.6,1.1,187.7,0,186.4,0z"/> <path d="M69.4,20.2c-1.3,0-2.2,1.2-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V22.8C71.6,21.3,70.7,20.2,69.4,20.2z"/> <path d="M58.7,0c-1.2,0.1-2.2,1.3-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6V2.6C60.9,1.1,60,0,58.7,0z"/> <path d="M101.2,11.9c-1.2,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6v-71C103.4,13,102.5,11.9,101.2,11.9z"/> <path d="M48.2,20.2c-1.3,0-2.2,1.2-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6V22.8C50.4,21.3,49.4,20.2,48.2,20.2z"/> <path d="M90.7,35.6c-1.3,0-2.2,1.2-2.2,2.6V62c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V38.2C92.9,36.7,91.9,35.6,90.7,35.6z"/> <path d="M16.2,22.1C15,22.2,14,23.3,14,24.7v50.6c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6V24.7C18.4,23.2,17.4,22.1,16.2,22.1z"/> <path d="M5.7,35.6c-1.3,0-2.2,1.2-2.2,2.6V62c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6V38.2C7.9,36.7,6.9,35.6,5.7,35.6z"/> <path d="M37.4,11.9c-1.2,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C39.7,13,38.7,11.9,37.4,11.9z"/> <path d="M26.9,35.6c-1.3,0-2.2,1.2-2.2,2.6V62c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V38.2C29.1,36.7,28.2,35.6,26.9,35.6z"/> <path d="M80,11.9c-1.2,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C82.2,13,81.2,11.9,80,11.9z"/> <path d="M154.4,35.6c-1.3,0-2.2,1.2-2.2,2.6V62c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V38.2C156.7,36.7,155.7,35.6,154.4,35.6z"/> <path d="M165.2,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C167.4,13,166.4,11.9,165.2,11.9z"/> <path d="M197,20.2c-1.3,0-2.2,1.2-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V22.8C199.2,21.3,198.2,20.2,197,20.2z"/> <path d="M207.7,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C209.9,13,208.9,11.9,207.7,11.9z"/> <path d="M175.7,20.2c-1.3,0-2.2,1.2-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V22.8C177.9,21.3,177,20.2,175.7,20.2z"/> <path d="M122.7,0c-1.4,0.1-2.2,1.3-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V2.6C124.9,1.1,123.9,0,122.7,0z"/> <path d="M111.9,20.2c-1.3,0-2.2,1.2-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V22.8 C114.2,21.3,113.2,20.2,111.9,20.2z"/> <path d="M133.2,20.2c-1.3,0-2.2,1.2-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6V22.8 C135.4,21.3,134.4,20.2,133.2,20.2z"/> <path d="M143.9,11.9c-1.4,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.1,2.2-2.6v-71C146.1,13,145.2,11.9,143.9,11.9z"/> <path d="M-121.9,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C-119.7,21.2-120.6,20.1-121.9,20.1z"/> <path d="M-89.9,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.2,0,2.2-1.1,2.2-2.6v-71C-87.7,13-88.6,11.9-89.9,11.9z"/> <path d="M-111.4,0c-1.3,0-2.2,1.1-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.4-0.1,2.2-1.3,2.2-2.6V2.6C-109.1,1.1-110.1,0-111.4,0z"/> <path d="M-100.6,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C-98.4,21.2-99.4,20.1-100.6,20.1z"/> <path d="M-79.4,35.4c-1.3,0-2.2,1.1-2.2,2.6v23.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V38C-77.2,36.5-78.1,35.4-79.4,35.4z"/> <path d="M-68.6,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.2,0,2.2-1.1,2.2-2.6v-71C-66.4,13-67.4,11.9-68.6,11.9z"/> <path d="M-36.9,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7C-34.6,21.2-35.6,20.1-36.9,20.1z"/> <path d="M-47.4,0c-1.3,0-2.2,1.1-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.2-0.1,2.2-1.3,2.2-2.6V2.6C-45.2,1.1-46.1,0-47.4,0z"/> <path d="M-58.1,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7C-55.9,21.2-56.9,20.1-58.1,20.1z"/> <path d="M-15.6,35.4c-1.3,0-2.2,1.1-2.2,2.6v23.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V38C-13.4,36.5-14.3,35.4-15.6,35.4z"/> <path d="M-4.9,22.1c-1.3,0-2.2,1.1-2.2,2.6v50.6c0,1.5,1,2.6,2.2,2.6c1.2-0.1,2.2-1.2,2.2-2.6V24.7C-2.7,23.2-3.6,22.1-4.9,22.1z"/> <path d="M-185.7,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C-183.4,21.2-184.4,20.1-185.7,20.1z"/> <path d="M-196.4,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C-194.2,13-195.1,11.9-196.4,11.9z"/> <path d="M-26.1,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.2,0,2.2-1.1,2.2-2.6v-71C-23.9,13-24.9,11.9-26.1,11.9z"/> <path d="M-164.4,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C-162.2,21.2-163.1,20.1-164.4,20.1z"/> <path d="M-175.1,0c-1.3,0-2.2,1.1-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.3-0.1,2.2-1.3,2.2-2.6V2.6C-172.9,1.1-173.9,0-175.1,0z"/> <path d="M-143.1,35.4c-1.3,0-2.2,1.1-2.2,2.6v23.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V38 C-140.9,36.5-141.9,35.4-143.1,35.4z"/> <path d="M-153.9,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C-151.6,13-152.6,11.9-153.9,11.9z"/> <path d="M-132.6,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.4,0,2.2-1.1,2.2-2.6v-71C-130.4,13-131.4,11.9-132.6,11.9z"/> <path d="M282.2,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C284.4,21.2,283.4,20.1,282.2,20.1z"/> <path d="M314.2,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.2,0,2.2-1.1,2.2-2.6v-71C316.4,13,315.4,11.9,314.2,11.9z"/> <path d="M292.7,0c-1.3,0-2.2,1.1-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.4-0.1,2.2-1.3,2.2-2.6V2.6C294.9,1.1,294,0,292.7,0z"/> <path d="M303.4,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C305.7,21.2,304.7,20.1,303.4,20.1z"/> <path d="M324.7,35.4c-1.3,0-2.2,1.1-2.2,2.6v23.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V38C326.9,36.5,325.9,35.4,324.7,35.4z"/> <path d="M335.4,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.2,0,2.2-1.1,2.2-2.6v-71C337.6,13,336.7,11.9,335.4,11.9z"/> <path d="M367.2,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C369.4,21.2,368.5,20.1,367.2,20.1z"/> <path d="M356.7,0c-1.3,0-2.2,1.1-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.2-0.1,2.2-1.3,2.2-2.6V2.6C358.9,1.1,357.9,0,356.7,0z"/> <path d="M345.9,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C348.2,21.2,347.2,20.1,345.9,20.1z"/> <path d="M388.5,35.4c-1.3,0-2.2,1.1-2.2,2.6v23.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V38C390.7,36.5,389.7,35.4,388.5,35.4z"/> <path d="M401.4,24.7c0-1.5-1-2.6-2.2-2.6c-1.3,0-2.2,1.1-2.2,2.6v50.6c0,1.5,1,2.6,2.2,2.6c1.2-0.1,2.2-1.2,2.2-2.6"/> <path d="M218.4,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C220.6,21.2,219.7,20.1,218.4,20.1z"/> <path d="M377.9,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.2,0,2.2-1.1,2.2-2.6v-71C380.1,13,379.2,11.9,377.9,11.9z"/> <path d="M239.7,20.1c-1.3,0-2.2,1.1-2.2,2.6v54.5c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V22.7 C241.9,21.2,240.9,20.1,239.7,20.1z"/> <path d="M228.9,0c-1.3,0-2.2,1.1-2.2,2.6v94.8c0,1.5,1,2.6,2.2,2.6c1.3-0.1,2.2-1.3,2.2-2.6V2.6C231.2,1.1,230.2,0,228.9,0z"/> <path d="M260.9,35.4c-1.3,0-2.2,1.1-2.2,2.6v23.8c0,1.5,1,2.6,2.2,2.6c1.3,0,2.2-1.2,2.2-2.6V38C263.1,36.5,262.2,35.4,260.9,35.4z"/> <path d="M250.2,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6s2.2-1.1,2.2-2.6v-71C252.4,13,251.4,11.9,250.2,11.9z"/> <path d="M271.4,11.9c-1.3,0-2.2,1.1-2.2,2.6v71c0,1.5,1,2.6,2.2,2.6c1.4,0,2.2-1.1,2.2-2.6v-71C273.7,13,272.7,11.9,271.4,11.9z"/> <animateTransform attributeName="transform" type="translate" from="0 0" to="-160 0" repeatCount="indefinite" dur="2.5s"/></g> </svg> I also want this to be pure SVG - no JS solutions please
You can use <use/> to make a copy of the wave and render it on the right of the wave. You would have to however, adjust the <animateTransform/> element appropriately: <animateTransform attributeName="transform" type="translate" from="0 0" to="-604.4 0" repeatCount="indefinite" dur="9.375s"/></g> <use href="#waveform" x="604.4"/>
How do i get the Windows PPID of a procces running out of cygwin?
I need to kill a windows procces that were started by the programm called from cygwin. Here's what I do: ${wccoaDirNix}/bin/WCCILpmon.exe -proj ${projName} -user root: & This process creates other windows process: $ ps -W PID PPID PGID WINPID TTY UID STIME COMMAND 1960 1 1960 1960 ? 197609 19:21:57 /usr/bin/mintty 7316 0 0 7316 ? 0 19:21:57 C:\Windows\System32\conhost.exe 1700 1960 1700 1576 pty1 197609 19:21:57 /usr/bin/bash I 10760 9840 10760 7560 pty0 197609 19:25:47 /usr/bin/bash 32 10760 10760 32 pty0 197609 19:26:28 /cygdrive/c/Siemens/Automation/WinCC_OA/3.14/bin/WCCILpmon 6264 0 0 6264 ? 0 19:26:28 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILpmon.exe 8420 0 0 8420 ? 0 19:26:29 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILdata.exe 6336 0 0 6336 ? 0 19:26:29 C:\Windows\System32\conhost.exe 2808 0 0 2808 ? 0 19:26:30 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILevent.exe 6784 0 0 6784 ? 0 19:26:30 C:\Windows\System32\conhost.exe 2972 0 0 2972 ? 0 19:26:30 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCOActrl.exe 11004 0 0 11004 ? 0 19:26:30 C:\Windows\System32\conhost.exe 9536 0 0 9536 ? 0 19:26:31 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILsim.exe 7372 0 0 7372 ? 0 19:26:31 C:\Windows\System32\conhost.exe 9128 0 0 9128 ? 0 19:26:31 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCOAui.exe 3964 0 0 3964 ? 0 19:27:48 C:\Siemens\Automation\WinCC_OA\3.14\bin\WCCILdatabg.exe How can i kill them? I tried to kill them by the following command: ps -W | grep "WCC" | awk '{print $1}' | xargs kill -f; But it does not work as it should, it kills all processes in which name there are letters WCС, and I need to terminate only the child processes of WCCILpmon.exe I also read the question on cygwinlist about same problem And it upset me, is there no way to realize it?
As you need to kill a NOT cygwin process, it is better to use windows specific program. One example is: https://learn.microsoft.com/en-us/sysinternals/downloads/pskill
make zpool status output scriptable
How can I turn the output of zpool status -v into something usable, with data that match by row in a data.oriented format, instead of the silly "visual" output it uses, so that it's something scriptable, using standard unix-like utilities? I had a python script that did something acceptable, but python 3 completely breaks it, and I'm not fixing it just to have some new version of python break it again. (after screwing around getting the script to run with no errors, it returns nothing :) bascially this space-bar alinged mess: pool: data state: ONLINE status: Some supported features are not enabled on the pool. The pool can still be used, but some features are unavailable. action: Enable all features using 'zpool upgrade'. Once this is done, the pool may no longer be accessible by software that does not support the features. See zpool-features(7) for details. scan: scrub repaired 0 in 4h52m with 0 errors on Fri Aug 18 04:52:47 2017 config: NAME STATE READ WRITE CKSUM data ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511 ONLINE 0 0 0 gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0 gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8 ONLINE 0 0 0 mirror-1 ONLINE 0 0 0 gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0 gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0 gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0 mirror-2 ONLINE 0 0 0 gptid/51f3b377-6a20-11e6-be8c-00e04c68f511 ONLINE 0 0 0 gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0 gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0 cache gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0 errors: No known data errors to something with actual columnns like this: NAME STATE READ WRITE CKSUM data ONLINE 0 0 0 data mirror-0 ONLINE 0 0 0 data mirror-0 gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511 ONLINE 0 0 0 data mirror-0 gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0 data mirror-0 gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8 ONLINE 0 0 0 data mirror-1 ONLINE 0 0 0 data mirror-1 gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0 data mirror-1 gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0 data mirror-1 gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0 data mirror-2 ONLINE 0 0 0 data mirror-2 gptid/51f3b377-6a20-11e6-be8c-00e04c68f511 ONLINE 0 0 0 data mirror-2 gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0 data mirror-2 gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0 data cache data cache gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0 I can use perl to remove and rearrange, but I can't work out how to match the rows dynamically, in a way that would work with mirror/raidz123/stripe/cache. datadata ONLINE 0 0 0 data mirror-0 ONLINE 0 0 0 data gptid/6dfb7dbe-68c5-11e6-982d-00e04c68f511 ONLINE 0 0 0 data gptid/27f40ebe-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0 data gptid/9244318f-c1b4-11e6-a31d-0cc47ae2abe8 ONLINE 0 0 0 data mirror-1 ONLINE 0 0 0 data gptid/1993f2d7-8f1b-11e4-94f8-3085a9405b85 ONLINE 0 0 0 data gptid/529e2c88-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0 data gptid/53a09a3e-f1d1-11e6-89c3-0cc47ae2abe8 ONLINE 0 0 0 data mirror-2 ONLINE 0 0 0 data gptid/51f3b377-6a20-11e6-be8c-00e04c68f511 ONLINE 0 0 0 data gptid/9fb54bde-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0 data gptid/9eebde32-1e2d-11e7-a83e-0cc47ae2abe8 ONLINE 0 0 0 datacache data gptid/63db5172-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0 This is the code that generates the above. zpool status -v data | sed '/ data/, $!d' | grep -v errors: > /tmp/diskslistzpoolstatusdata perl -pi -e 's/^\n$//' /tmp/diskslistzpoolstatusdata #remove blank lines perl -pi -e 's/\t$//' /tmp/diskslistzpoolstatusdata perl -p -i -e 's/\t//g' /tmp/diskslistzpoolstatusdata perl -pi -e 's/^/data/' /tmp/diskslistzpoolstatusdata extra: include the scrub summary and error lines per gptid NAME STATE READ WRITE CKSUM misc ONLINE 0 0 0 misc mirror-0 ONLINE 0 0 0 misc mirror-0 gptid/aefbaf6e-e004-11e6-8f42-0cc47ae2abe8 ONLINE 0 0 0 0err/4h52m/0err/Fri Aug 18 04:52:47 2017 No known data errors misc mirror-0 gptid/affc3cac-e004-11e6-8f42-0cc47ae2abe8 ONLINE 0 0 0 0err/4h52m/0err/Fri Aug 18 04:52:47 2017 No known data errors misc cache gptid/3139819b-20bd-11e7-b561-0cc47ae2abe8 ONLINE 0 0 0 0err/4h52m/0err/Fri Aug 18 04:52:47 2017 No known data errors
Unfortunately there is no integrated solution available. You have two options: Parse it yourself in a language of your choice. You already extracted the essential information. The layout is relatively static, as vdevs and pools cannot be nested (pools contain vdevs, never pools themselves), the order is respected (no devices from vdev A come after vdev B), the keywords are few and fixed (mirror-N, raidzX-N, etc), and the output is quite small (less than hundreds of lines usually). This means you just have to go through each row, read the info you need, store it in nested objects or simply arrays and go to the next line. Directly call the appropriate C functions to get the status in non-readable form and convert the output. To do this, have a look at status_callback(zpool_handle_t *zhp, void *data), where all printf-output is generated from the pool data. You could mirror this function to convert the output into a format you like instead of the indented format, and then call your mini-application from your script to give you your data. If you are familiar with C, option 2 would be faster I think. Performance-wise it does not matter much, as the data is small (even on big systems) and the calls will most likely be very infrequent (as pool layouts do not change often).
Generating number circles in SVG - how to centre the text [duplicate]
This question already has an answer here: How to draw a number centered inside a circle with inline svg? (1 answer) Closed 7 years ago. I have written a script to generate SVG files showing 1 numbers in circles. This is for use in a drawing app as clipart. Here is the script: if [ ! -d circleNums ] then mkdir circleNums fi rm circleNums/index.html # Add this line for center guide <line x1="63" y1="0" x2="63" y2="128" style="stroke:rgb(255,127,64);stroke-width:2"/> for I in {1..9} do cat <<EOF > circleNums/$I.svg <svg width='128' height='128' viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg' version='1.1' > <circle cx="64" cy="64" r="62" fill="rgb(0,100,0)" stroke="red" stroke-width="2"/> <text x="35" y="95" font-family="sans-serif" font-size="90px" fill="white">$I</text> </svg> EOF echo "<img src=\"$I.svg\" >" >> circleNums/index.html done for I in {10..99} do cat <<EOF > circleNums/$I.svg <svg width='128' height='128' viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg' version='1.1' > <circle cx="64" cy="64" r="62" fill="rgb(0,100,0)" stroke="red" stroke-width="2"/> <text x="15" y="95" font-family="sans-serif" font-size="90px" fill="white">$I</text> </svg> EOF echo "<img src=\"$I.svg\" >" >> circleNums/index.html done ls circleNums Example of output, 1.svg: <svg width='128' height='128' viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg' version='1.1' > <circle cx="64" cy="64" r="62" fill="rgb(0,100,0)" stroke="red" stroke-width="2"/> <text x="35" y="95" font-family="sans-serif" font-size="90px" fill="white">1</text> </svg> 99.svg: <svg width='128' height='128' viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg' version='1.1' > <circle cx="64" cy="64" r="62" fill="rgb(0,100,0)" stroke="red" stroke-width="2"/> <text x="15" y="95" font-family="sans-serif" font-size="90px" fill="white">99</text> </svg> As you can see the centring is guess work and experimentation based. How can I get the text to centre about a particular point, in this case x=64, y=64?
I made small changes to your script: I merged two loops into one I replaced x and y to 50% like you'd expect from a centered text I used text-anchor="middle" property to make the text render centered (relative to image center) I used dy=".35em" to correct vertical shift - it looks good enough to me. Other fonts might need other values. if [ ! -d circleNums ] then mkdir circleNums fi rm circleNums/index.html # Add this line for center guide <line x1="63" y1="0" x2="63" y2="128" style="stroke:rgb(255,127,64);stroke-width:2"/> for I in {1..99} do cat <<EOF > circleNums/$I.svg <svg width='128' height='128' viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg' version='1.1' > <circle cx="64" cy="64" r="62" fill="rgb(0,100,0)" stroke="red" stroke-width="2"/> <text text-anchor="middle" x="50%" y="50%" dy=".35em" font-family="sans-serif" font-size="90px" fill="white">$I</text> </svg> EOF echo "<img src=\"$I.svg\" >" >> circleNums/index.html done ls circleNums Result:
Batch, How to filter this HTML text to set a bit of vars
i'm in a big problem I use wget to send a post petition to a web, then i receive a html And i need to filter this sample of the html: more code up... <div id="song_html" class="show1"> <div class="left"> <!-- info mp3 here --> 256 kbps<br />3:21<br />6.13 mb </div> <div id="right_song"> <div style="font-size:15px;"><b>Marilyn Manson - Tainted Love ( Manson Remix) mp3</b></div> <div style="clear:both;"></div> <div style="float:left;"> <div style="float:left; height:27px; font-size:13px; padding-top:2px;"> <div style="float:left;">Download</div> <div style="margin-left:8px; float:left; width:27px; text-align:center;">Play</div> <div style="margin-left:8px; float:left;">Embed</div> <div style="margin-left:8px; float:left;">Descarga Tono</div> <div style="clear:both;"></div> </div> <div id="player37119" style="float:left; margin-left:10px;" class="player"></div> </div> <div style="clear:both;"></div> </div> <div style="clear:both;"></div> </div> <div id="song_html" class="show2"> <div class="left"> <!-- info mp3 here --> </div> <div id="right_song"> <div style="font-size:15px;"><b>Spaz Marilyn Manson Metric - grow up and blow the great big dj://spaz, marilyn manson mp3</b></div> <div style="clear:both;"></div> <div style="float:left;"> <div style="float:left; height:27px; font-size:13px; padding-top:2px;"> <div style="float:left;">Download</div> <div style="margin-left:8px; float:left; width:27px; text-align:center;">Play</div> <div style="margin-left:8px; float:left;">Embed</div> <div style="margin-left:8px; float:left;">Descarga Tono</div> <div style="clear:both;"></div> </div> <div id="player668416" style="float:left; margin-left:10px;" class="player"></div> </div> <div style="clear:both;"></div> </div> <div style="clear:both;"></div> </div> <div id="morelink" style="margin:10px; text-align:center;">Show More Results</div> <div id="song_html" class="show3"> <div class="left"> <!-- info mp3 here --> 3:10<br /> </div> <div id="right_song"> <div style="font-size:15px;"><b>Marilyn Manson - MARILYN MANSON - Rock is Dead mp3</b></div> <div style="clear:both;"></div> <div style="float:left;"> <div style="float:left; height:27px; font-size:13px; padding-top:2px;"> <div style="float:left;">Download</div> <div style="margin-left:8px; float:left; width:27px; text-align:center;">Play</div> <div style="margin-left:8px; float:left;">Embed</div> <div style="margin-left:8px; float:left;">Descarga Tono</div> <div style="clear:both;"></div> </div> <div id="player670124" style="float:left; margin-left:10px;" class="player"></div> </div> <div style="clear:both;"></div> </div> <div style="clear:both;"></div> </div> </div> </div> <!-- ================= --> more code down... ...To set a bit of variables like "Name" "Bitrate" "Size" and "Download", To print all this information in Batch, like this: 1st result: [Name] Marilyn Manson - Tainted Love ( Manson Remix) mp3 [Info] Bitrate: 256 kbps. Length: 3:21. Size: 6.13 mb. [Download] http://rockass.free.fr/video/Marilyn Manson - Taited Love.mp3 2nd result: [Name] Spaz Marilyn Manson Metric - grow up and blow the great big dj://spaz, marilyn manson mp3 [Info] NO INFO. [Download] http://spaz.mindstab.net/djspaz_-_grow_up_and_blow_the_great_big_white_nietzche.mp3 3rd result: [Name] Marilyn Manson - MARILYN MANSON - Rock is Dead mp3 [Info] Lenght: 3:10. [Download] http://www.bricbrac.free.fr/Music/01___MARILYN_MANSON___ROCK_.MP3 I've tryed "Findstr","Find","SED","GREP","FART" but i can't find the way (A line and chars delimitators) to do it right... The only i can see to make it possible is this line: <!-- ================= --> I can use it like a END-delimitator cause that line marks the end of mp3's to download and to print their info... Somebody can help me? thankyou
The Batch file below use the fact that the data you want is located at fixed number of lines below "info mp3 here" line. Also, the data is extracted based on its position in the line. If some data not follow this rule, the program will need a modification. #echo off setlocal EnableDelayedExpansion findstr /N /C:"info mp3 here" %1 > "%~N1.tmp" set lastLine=-1 (for /F "usebackq delims=:" %%a in ("%~N1.tmp") do ( set /A skip=%%a-lastLine for /L %%i in (1,1,!skip!) do set /P info= set /P =& set /P name= for /L %%i in (1,1,4) do set /P download= set "name=!name:*<b>=! for /F "delims=<" %%n in ("!name!") do echo [Name] %%n set "info=!info:<br />= !" set "info=!info:</div>=!" set bitrate= set lenght= set size= set value= for %%t in (!info!) do ( if not defined value ( set value=%%t ) else ( if %%t equ kbps ( set "bitrate=Bitrate: !value! kbps. " set value= ) else if %%t equ mb ( set "size=Size: !value! mb." set value= ) else ( set "lenght=Lenght: !value!. " set value=%%t ) ) ) if defined value ( set "lenght=Lenght: !value!. " ) set info=!bitrate!!lenght!!size! if not defined info set info=NO INFO. echo [Info] !info! set "download=!download:"=$!" for /F "tokens=4 delims=$" %%d in ("!download!") do echo [Download] %%d set /A lastline=%%a+6 )) < %1 del "%~N1.tmp" Output: [Name] Marilyn Manson - Tainted Love ( Manson Remix) mp3 [Info] Bitrate: 256 kbps. Lenght: 3:21. Size: 6.13 mb. [Download] http://rockass.free.fr/video/Marilyn Manson - Taited Love.mp3 [Name] Spaz Marilyn Manson Metric - grow up and blow the great big dj://spaz, marilyn manson mp3 [Info] NO INFO. [Download] http://spaz.mindstab.net/djspaz_-_grow_up_and_blow_the_great_big_white_nietzche.mp3 [Name] Marilyn Manson - MARILYN MANSON - Rock is Dead mp3 [Info] Lenght: 3:10. [Download] http://www.bricbrac.free.fr/Music/01___MARILYN_MANSON___ROCK_.MP3
Here's a script that will parse the information you want. The script takes the name of your HTML file as an argument. Output is sent to a file with name derived by appending '.parsed' to the input file name. Comments at the top of the script give a little explanation of the patterns being used to locate the requested information in the HTML file. Replace the two instances of 'TAB' with tab characters and be sure that you retain the single space before each tab. #!/bin/bash # Parse HTML with sed, suppressing all unwanted lines # "Info" lines all start with a number (ignoring whitespace) # Bitrate and file size can be identified by looking for # the unit (kbps, mb) immediately following the numeric data # Length is identified by the colon in the middle of numeric data # File names are delimited by <b> and </b> # Lines with the URL all contain Download</a> # The </a> isn't necessary, but I thought it would be safer to # include it since one could imagine "Download" appearing in a file name # Pipe output to Awk for reordering of the parsed lines # and addition of "NO INFO" lines where necessary sed -n ' /^[ TAB]*[0-9]/ { s/^[ TAB]*/[Info] / s/\([0-9]*:[0-9]*\)[^0-9]*/Length: \1. / s/\([0-9\.]* .bps\)[^0-9L]*/Bitrate: \1. / s/\([0-9\.]* .b\)[^p][^0-9LB]*/Size: \1. / p } /<b>/ { s|</b>.*|| s|.*<b>\(.*\)|[Name] \1| p } \|Download</a>| { s/^.*\(http:[^"]*\).*/[Download] \1/ p }' $1 | awk 'BEGIN { no_info = "[INFO] NO INFO."; info = no_info } { if ($1 == "[Name]") name = $0; else if ($1 == "[Info]") info = $0; else { printf("%s\n%s\n%s\n\n", name, info, $0); info = no_info } }' > $1.parsed exit 0
TXR 65 (Runs on Windows; MinGW-compiled .exe available) #(collect) <div id="song_html" class="show#nil"> <div class="left"> <!-- info mp3 here --> #(gather :vars ((bitrate nil) (length nil) (size nil))) #bitrate kbps#(skip) #(skip)#{length /\d+:\d\d/}#(skip) #(skip)#{size /\d+\.\d\d/} mb#(skip) #(until) <div id="right_song"> #(end) #(bind info #(if (or bitrate length size) (let ((s (make-string-output-stream))) (if bitrate (format s "Bitrate: ~a kbps. " bitrate)) (if length (format s "Length: ~a. " length)) (if size (format s "Size: ~a mb. " size)) (get-string-from-stream s)) "NO INFO.")) <div id="right_song"> <div style="font-size:15px;"><b>#title</b></div> <div style="clear:both;"></div> <div style="float:left;"> <div style="float:left; height:27px; font-size:13px; padding-top:2px;"> <div style="float:left;">Download</div> #(until) <!-- ================= --> #(end) #(output) # (repeat) [Name] #title [Info] #info [Download] #link # (end) #(end) Run: $ txr data.txr data.html [Name] Marilyn Manson - Tainted Love ( Manson Remix) mp3 [Info] Bitrate: 256 kbps. Length: 3:21. Size: 6.13 mb. [Download] http://rockass.free.fr/video/Marilyn Manson - Taited Love.mp3 [Name] Spaz Marilyn Manson Metric - grow up and blow the great big dj://spaz, marilyn manson mp3 [Info] NO INFO. [Download] http://spaz.mindstab.net/djspaz_-_grow_up_and_blow_the_great_big_white_nietzche.mp3 [Name] Marilyn Manson - MARILYN MANSON - Rock is Dead mp3 [Info] Length: 3:10. [Download] http://www.bricbrac.free.fr/Music/01___MARILYN_MANSON___ROCK_.MP3