Parsing xml data into nested list bash - string

I'm working on a Plex Geeklet, and I have a string of recently added TV shows.
SHOW_DATA=$(curl --silent "http://localhost:32400/library/sections/3/recentlyAdded?X-Plex-Container-Start=0&X-Plex-Container-Size=10")
This is an example of my data:
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="10" totalSize="50" allowSync="1" art="/:/resources/show-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="3" librarySectionTitle="TV Shows" librarySectionUUID="600cd0c5-fd4b-460a-846b-e4bad1ecdf4a" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1402960845" mixedParents="1" nocache="1" offset="0" thumb="/:/resources/show.png" title1="TV Shows" title2="Recently Added" viewGroup="episode" viewMode="65592">
<Video ratingKey="588" key="/library/metadata/588" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Pilot" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Fast-talking lawyer Jeff Winger (Joel McHale) enrolls at Greendale Community College after the State Bar discovered his illegitimate degree and threatened to suspend his license. When Jeff pretends to be a Spanish tutor to get close to his classmate Britta (Gillian Jacobs), he winds up with an entire study group of students looking for his help. Pierce (Chevy Chase), Abed (Danny Pudi), Shirley (Yvette Nicole Brown), Annie (Alison Brie), Troy (Donald Glover), and Britta comprise the band of misfits that Jeff never asked for, but may end up needing when he realizes his connection to Greendale professor Ian Duncan (John Oliver) won&apos;t pay off like he hoped." index="1" parentIndex="1" rating="7.4000000953674299" year="2009" thumb="/library/metadata/588/thumb/1403755683" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1525134" originallyAvailableAt="2009-09-17" addedAt="1403755618" updatedAt="1403755683">
<Media videoResolution="480" id="479" duration="1525134" bitrate="2509" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="522" key="/library/parts/522/file.mp4" duration="1525134" file="/Users/joe/Videos/TV Shows/Community/Season 1/01 Pilot.mp4" size="478232014" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Dan Harmon" />
<Director tag="Anthony Russo" />
<Director tag="Joe Russo" />
</Video>
<Video ratingKey="589" key="/library/metadata/589" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Spanish 101" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Jeff&apos;s (Joel McHale) efforts to win over Britta (Gillian Jacobs) backfire, and he finds himself paired up with Pierce (Chevy Chase) for their Spanish class project. The two give teacher Señor Chang (Ken Jeong) the presentation of a lifetime. Meanwhile, inspired by Britta&apos;s awareness of social issues, Annie (Alison Brie) and Shirley (Yvette Nicole Brown) stage a protest on Greendale&apos;s campus." index="2" parentIndex="1" rating="7.4000000953674299" year="2009" thumb="/library/metadata/589/thumb/1403755684" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1278352" originallyAvailableAt="2009-09-24" addedAt="1403755618" updatedAt="1403755684">
<Media videoResolution="480" id="480" duration="1278352" bitrate="2253" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="523" key="/library/parts/523/file.mp4" duration="1278352" file="/Users/joe/Videos/TV Shows/Community/Season 1/02 Spanish 101.mp4" size="359953984" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Dan Harmon" />
<Director tag="Joe Russo" />
</Video>
<Video ratingKey="591" key="/library/metadata/591" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Introduction to Statistics" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="It&apos;s Halloween at Greendale, and Jeff (Joel McHale) has the hots for one of his teachers (Lauren Stamile) and gets dating advice from Señor Chang (Ken Jeong). Meanwhile Annie (Alison Brie) throws a ""Dia de los Muertos" party for extra credit." index="7" parentIndex="1" rating="7.9000000953674299" year="2009" thumb="/library/metadata/591/thumb/1403755686" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1276610" originallyAvailableAt="2009-10-29" addedAt="1403755618" updatedAt="1403755686">
<Media videoResolution="480" id="482" duration="1276610" bitrate="2258" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="525" key="/library/parts/525/file.mp4" duration="1276610" file="/Users/joe/Videos/TV Shows/Community/Season 1/07 Introduction to Statistics.mp4" size="360268838" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Jon Pollack" />
<Writer tag="Tim Hobert" />
<Director tag="Justin Lin" />
</Video>
<Video ratingKey="592" key="/library/metadata/592" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Home Economics" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Britta (Gillian Jacobs) tries to rid Jeff (Joel McHale) of his materialistic ways. Meanwhile Pierce (Chevy Chase) joins a rock band on campus, and Annie (Alison Brie) grudgingly helps Troy (Donald Glover) plan a date with another girl." index="8" parentIndex="1" rating="7.5999999046325701" year="2009" thumb="/library/metadata/592/thumb/1403755686" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1275844" originallyAvailableAt="2009-11-05" addedAt="1403755618" updatedAt="1403755686">
<Media videoResolution="480" id="483" duration="1275844" bitrate="2340" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="526" key="/library/parts/526/file.mp4" duration="1275844" file="/Users/joe/Videos/TV Shows/Community/Season 1/08 Home Economics.mp4" size="373156573" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Lauren Pomerantz" />
<Director tag="Anthony Russo" />
</Video>
<Video ratingKey="593" key="/library/metadata/593" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Comparative Religion" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Shirley (Yvette Nicole Brown) tries to get everyone in the Christmas spirit, but Jeff (Joel McHale) threatens her holiday cheer when he decides to fight the school bully (guest star Anthony Michael Hall)." index="12" parentIndex="1" rating="7.8000001907348597" year="2009" thumb="/library/metadata/593/thumb/1403755688" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1276355" originallyAvailableAt="2009-12-10" addedAt="1403755618" updatedAt="1403755688">
<Media videoResolution="480" id="484" duration="1276355" bitrate="2446" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="527" key="/library/parts/527/file.mp4" duration="1276355" file="/Users/joe/Videos/TV Shows/Community/Season 1/12 Comparative Religion.mp4" size="390216047" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Liz Cackowski" />
<Director tag="Adam Davidson" />
</Video>
<Video ratingKey="594" key="/library/metadata/594" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Investigative Journalism" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Everyone&apos;s vibe is thrown off when an unwanted outsider tries to join the study group. Meanwhile, Jeff (Joel McHale) becomes the new editor of Greendale&apos;s school newspaper and appoints Annie (Alison Brie) as his ace reporter." index="13" parentIndex="1" rating="7.5" year="2010" thumb="/library/metadata/594/thumb/1403755689" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1269923" originallyAvailableAt="2010-01-14" addedAt="1403755618" updatedAt="1403755689">
<Media videoResolution="480" id="485" duration="1269923" bitrate="1998" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="528" key="/library/parts/528/file.mp4" duration="1269923" file="/Users/joe/Videos/TV Shows/Community/Season 1/13 Investigative Journalism.mp4" size="317146865" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Jon Pollack" />
<Writer tag="Tim Hobert" />
<Director tag="Joe Russo" />
</Video>
<Video ratingKey="595" key="/library/metadata/595" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Romantic Expressionism" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Britta (Gillian Jacobs) and Jeff (Joel McHale) stage an intervention when Annie (Alison Brie) gets cozy with Vaughn (Eric Christian Olsen). Meanwhile Pierce (Chevy Chase) struggles to prove his wit when he crashes Abed (Danny Pudi) and Troy’s (Donald Glover) movie night." index="15" parentIndex="1" rating="7.9000000953674299" year="2010" thumb="/library/metadata/595/thumb/1403755689" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1274799" originallyAvailableAt="2010-02-04" addedAt="1403755618" updatedAt="1403755689">
<Media videoResolution="480" id="486" duration="1274799" bitrate="2059" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="529" key="/library/parts/529/file.mp4" duration="1274799" file="/Users/joe/Videos/TV Shows/Community/Season 1/15 Romantic Expressionism.mp4" size="328027632" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Andrew Guest" />
<Director tag="Joe Russo" />
</Video>
<Video ratingKey="596" key="/library/metadata/596" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Communication Studies" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="When Britta (Gillian Jacobs) drunk dials Jeff (Joel McHale) things get awkward between them and Jeff attempts to repair their relationship. Meanwhile, Annie (Alison Brie) and Shirley (Yvette Nicole Brown) conspire to humiliate Señor Chang (Ken Jeong)." index="16" parentIndex="1" rating="7.8000001907348597" year="2010" thumb="/library/metadata/596/thumb/1403755691" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1267206" originallyAvailableAt="2010-02-11" addedAt="1403755618" updatedAt="1403755691">
<Media videoResolution="480" id="487" duration="1267206" bitrate="2278" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="530" key="/library/parts/530/file.mp4" duration="1267206" file="/Users/joe/Videos/TV Shows/Community/Season 1/16 Communication Studies.mp4" size="360777073" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Chris McKenna" />
<Director tag="Adam Davidson" />
</Video>
<Video ratingKey="597" key="/library/metadata/597" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Modern Warfare" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="JEFF AND BRITTA&apos;S SEXUAL TENSION HEATS UP ? The sexual tension between Jeff (Joel McHale) and Britta (Gillian Jacobs) becomes a hot topic among the study group. Meanwhile, what starts out as a simple contest for a chance at early class registration turns the peaceful campus of Greendale Community College into an all-out war zone. Friendships are tested, as only one student can be victorious." index="23" parentIndex="1" rating="8.5" year="2010" thumb="/library/metadata/597/thumb/1403755692" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" duration="1260333" originallyAvailableAt="2010-05-06" addedAt="1403755618" updatedAt="1403755692">
<Media videoResolution="480" id="488" duration="1260333" bitrate="2233" width="854" height="480" aspectRatio="1.78" audioChannels="2" audioCodec="aac" videoCodec="h264" container="mp4" videoFrameRate="24p" optimizedForStreaming="0" has64bitOffsets="0">
<Part id="531" key="/library/parts/531/file.mp4" duration="1260333" file="/Users/joe/Videos/TV Shows/Community/Season 1/23 Modern Warfare.mp4" size="351822199" container="mp4" has64bitOffsets="0" optimizedForStreaming="0" />
</Media>
<Writer tag="Emily Cutler" />
<Director tag="Justin Lin" />
</Video>
<Video ratingKey="590" key="/library/metadata/590" parentRatingKey="587" grandparentRatingKey="586" type="episode" title="Advanced Criminal Law" grandparentKey="/library/metadata/586" parentKey="/library/metadata/587" grandparentTitle="Community" contentRating="TV-PG" summary="Señor Chang (Ken Jeong) invokes an inquisition and trial when one of the gang cheats on an exam. Annie (Alison Brie) enlists Pierce (Chevy Chase) to help her compose Greendale&apos;s new school song, and Troy (Donald Glover) educates Abed (Danny Pudi) on the art of joking." index="5" parentIndex="1" rating="7.8000001907348597" year="2009" thumb="/library/metadata/590/thumb/1403755683" art="/library/metadata/586/art/1403755684" parentThumb="/library/metadata/587/thumb/1403755684" grandparentThumb="/library/metadata/586/thumb/1403755684" grandparentTheme="/library/metadata/586/theme/1403755684" originallyAvailableAt="2009-10-15" addedAt="1403755618" updatedAt="1403755683">
<Media id="481" container="">
<Part id="524" key="/library/parts/524/file.mp4" file="/Users/joe/Videos/TV Shows/Community/Season 1/05 Advanced Criminal Law.mp4" size="48" />
</Media>
<Writer tag="Andrew Guest" />
<Director tag="Joe Russo" />
</Video>
</MediaContainer>
I'm trying to get this into an orders list like this
[ [show_title_1, episode_title_1], [show_title_2, episode_title_2], ... [show_title_10, episode_title_10] ]
so I can eventually print it as (for example)
Community: Pilot
Arrested Development: My Mother, the Car
I've been able to get them into separate newline-delimited strings like so:
SHOW_NAMES=$("$SHOW_DATA" | grep -o 'grandparentTitle="\([^"]*\)"' | sed -e 's/grandparentTitle="//' -e 's/"//' | perl -MHTML::Entities -ne 'print decode_entities($_)'))
SHOW_TITLES=$("$SHOW_DATA" | grep -o 'title="\([^"]*\)"' | sed -e 's/title="//' -e 's/"//' | perl -MHTML::Entities -ne 'print decode_entities($_)'))
So is it possible to convert them both to lists, and use a loop to construct a new list containing nested lists of those values? I've really hit a wall here.

If I were you I would get rid of all the grep and sed, etc.. and just rely on pattern matching. I guessed at which exact fields you wanted, but you can easily update the code as needed. I used your data file to test with, so this will work. The script takes 1 input, that being the filename to the downloaded .xml file:
#!/bin/bash
test -r "$1" || { echo "error: invalid input, usage: ${0//*\//} filename.xml"; exit 1; }
let idx=0
while read line || test -n "$line"; do
if test "${line:0:2}" == '<V'; then
tmp=${line##* title=}
title=${tmp%% grandparentKey*}
tmp=${line##*grandparentTitle=}
gptitle=${tmp%% contentRating*}
if test "$idx" -lt "1" ; then
let idx=1
echo -n "[ [ $title, $gptitle ]"
else
echo -n ", [ $title, $gptitle ]"
fi
fi
done <"$1"
echo " ]"
exit 0
The following will read the values into an array to allow later processing. You can add additional arrays as you like, you can even read the entire file into an array if you like (but re-reading if from disk is simple enough as well) The output is the same as above (it is just for illustration):
let idx=0
declare -a title
declare -a gptitle
declare -a allvideo
while read line || test -n "$line"; do
if test "${line:0:2}" == '<V'; then
allvideo+=( "$line" )
tmp=${line##* title=}
title+=( "${tmp%% grandparentKey*}" )
tmp=${line##*grandparentTitle=}
gptitle+=( "${tmp%% contentRating*}" )
fi
done <"$1"
# output the original 2 variables
for ((i=0; i<${#title[#]}; i++)); do
if test "$i" -eq 0 ; then
echo -n "[ [ ${title[$i]}, ${gptitle[$i]} ]"
else
echo -n ", [ ${title[$i]}, ${gptitle[$i]} ]"
fi
done
echo " ]"
oldifs=$IFS
IFS=$'\n' # set Internal Field Separator to only break on newlines
# output the entire file with the allvideo array
for i in ${allvideo[#]}; do
echo "$i"
done
IFS=$oldifs
output:
[ [ "Pilot", "Community" ], [ "Spanish 101", "Community" ], \
[ "Introduction to Statistics", "Community" ], [ "Home Economics", "Community" ], \
[ "Comparative Religion", "Community" ], [ "Investigative Journalism", "Community" ], \
[ "Romantic Expressionism", "Community" ], [ "Communication Studies", "Community" ], \
[ "Modern Warfare", "Community" ], [ "Advanced Criminal Law", "Community" ] ]
**the dump of the original file is omitted for brevity.
Let me know if you have any additional questions.

Related

Mathjax delay rendering code inside spoilers

I am trying to render mathjax for visible elements in the following. I hid the answers and would like to render math only when someone clicks on the button. Currently mathjax is doing fantastic job even rendering math inside spoilers. Davide (mathjax) suggested a solution but I could not get what he suggested. Can anyone help me with this? The goal is to render mathjax as fast as possible. Code I am using https://cdn.jsdelivr.net/gh/srk7774/cg/mj3_chtml.js
Please make necessary changes to the html code so that I can understand it better.
Davide's suggestion:
https://groups.google.com/g/mathjax-users/c/Xr-arJPN2kI
Site:
https://www.campusgate.in/2011/11/permutations.html
<span class="q-box">1</span>How many arrangements can be made of the letters of the word “ASSASSINATION”? In how many of them are the vowels always together?<br />
<span class="step">A</span>$\dfrac{{13!}}{{{{\left( {4!} \right)}^2}}},\;\dfrac{{8! \times 6!}}{{{{\left( {4!} \right)}^2}}}$<br />
<span class="step">B</span>$\dfrac{{13!}}{{6! \times 7!}},\;\dfrac{{8! \times 6!}}{{{{\left( {4!} \right)}^2}}}$<br />
<span class="step">C</span>$\dfrac{{13!}}{{6! \times 7!}},\;\dfrac{{8! \times 6!}}{{6! \times 7!}}$<br />
<span class="step">D</span>$\dfrac{{13!}}{{{{\left( {4!} \right)}^2}}},\;\dfrac{{8! \times 6!}}{{6! \times 7!}}$<br />
<div class="border" id="spoiler1" style="display: none;">Answer: A<br />
<div class="border1" id="spoiler1A" style="display: none;">Explanation:<br />
Total letters in the word $ASSASSINATION$ $=13$<br />
$(SSSS), (AAA), (II), (NN), T, O$<br />
<span class="f-box">Formula:</span>Number of ways of arranging $n$ items of which $p$ are alike, $q$ alike and so on $ = \dfrac{{n!}}{{p! \times q! \times ...}}$<br />
Total number of arrangements $ = \dfrac{{13!}}{{4! \times 3! \times 2! \times 2!}}$ $ = \dfrac{{13!}}{{4! \times 4 \times 3!}}$ $ = \dfrac{{13!}}{{{{\left( {4!} \right)}^2}}} \qquad (1)$ <br />
Vowels in the given word $=AAAIIO$<br />
Let us put them in a box and name it a letter $X$.<br />
$\boxed{AAAIIO}_{\rightarrow{X}}, S, S, S, S, N, N, T $<br />
Now total letters $= 8$<br />
Number of ways of arranging $8$ letters in $8$ places $ = \dfrac{{8!}}{{4! \times 2!}}$<br />
Numebr of ways the vowels in the box arrange themselves $ = \dfrac{{6!}}{{3! \times 2!}}$<br />
Total ways in which all vowels together $ = \dfrac{{8!}}{{4! \times 2!}} \times \dfrac{{6!}}{{3! \times 2!}}$ $ = \dfrac{{8! \times 6!}}{{{{\left( {4!} \right)}^2}}} \qquad (2)$<br />
<!-- explanation Ends--></div><button onclick="if(document.getElementById('spoiler1A') .style.display=='none') {document.getElementById('spoiler1A') .style.display=''}else{document.getElementById('spoiler1A') .style.display='none'}" title="Click to show/hide content" type="button">Show Explanation</button></div><button onclick="if(document.getElementById('spoiler1') .style.display=='none') {document.getElementById('spoiler1') .style.display=''}else{document.getElementById('spoiler1') .style.display='none'}" title="Click to show/hide content" type="button">Show Answer</button><br />
<br />
<span class="q-box">2</span>In how many ways can the letters of the word ARRANGE be arranged so that two R’s are never together <br />
<span class="step">A</span>900<br />
<span class="step">B</span>360<br />
<span class="step">C</span>120<br />
<span class="step">D</span>1260<br />
<div class="border" id="spoiler2" style="display: none;">Answer: A<br />
<div class="border1" id="spoiler2A" style="display: none;">Explanation:<br />
<img border="0" data-original-height="277" data-original-width="422" src="https://1.bp.blogspot.com/-3LjCBAS8QzE/Xcw3ipNYQLI/AAAAAAAAepc/R70tcTQd5j8g2wLmpmBuY-0tCv8tYq7pwCLcBGAsYHQ/s1600/aarr11%2B%25282%2529.png" /><br />
$ARRANGE$ $=(AA), (RR), N, G, E$<br />
Two R’s are never together $=$ (Total possible arrangements) $-$ (Two R’s are always together)<br />
Total number of arrangements = $\dfrac{{7!}}{{2! \times 2!}}$ = $\dfrac{{7 \times 6 \times 5 \times 4 \times 3 \times 2 \times 1}}{{2 \times 2}}$ $= 1260$<br />
<br />
Arrangements with both R’s together:<br />
Let us put both $R$'s are in a box and name it letter $X$.<br />
$\boxed{RR}_{\rightarrow{X}}, A, A, N, G, E $<br />
Number of ways of arranging above $6$ letters = $\dfrac{{{\text{6}}!}}{{{\text{2}}!}}$ $= 360$<br />
(Note: Two $R$'s in the box arrange only one way)<br />
<br />
R’s never together $= 1260 - 360 = 900$<br />
<!-- explanation Ends--></div><button onclick="if(document.getElementById('spoiler2A') .style.display=='none') {document.getElementById('spoiler2A') .style.display=''}else{document.getElementById('spoiler2A') .style.display='none'}" title="Click to show/hide content" type="button">Show Explanation</button></div><button onclick="if(document.getElementById('spoiler2') .style.display=='none') {document.getElementById('spoiler2') .style.display=''}else{document.getElementById('spoiler2') .style.display='none'}" title="Click to show/hide content" type="button">Show Answer</button><br />
<br />
Fortunately it's possible to do what Davide suggested (which I believe is the best approach) without too much knowledge of JS and HTML. The code snippet you linked tells MathJax not to render inside of an element with the tex2jax_ignore class, so you can add this class to your spoiler divs. Taking the div with id spoiler1A as an example, you would set class="border1 tex2jax_ignore" to prevent MathJax from typesetting that element when the page loads. You would also add tex2jax_ignore to every element you do not want rendering inside of.
Then you need to tell MathJax to render the math inside the spoiler when it is shown. To set that up, you'll want to define this function based off the one in MathJax documentation - I'm guessing you might want to put it in a script tag after the script tag that loads https://cdn.jsdelivr.net/gh/srk7774/cg/mj3_chtml.js:
<script>
function typeset(id) {
MathJax.startup.promise = MathJax.startup.promise
.then(() => MathJax.typesetPromise([id]))
.catch((err) => console.log('Typeset failed: ' + err.message));
return MathJax.startup.promise;
}
</script>
Finally, you need to change the onclick handler for the button that shows the math: instead of onclick="if(document.getElementById('spoiler1A') .style.display=='none') {document.getElementById('spoiler1A') .style.display=''}else{document.getElementById('spoiler1A') .style.display='none'}",
you could write onclick="if(document.getElementById('spoiler1A') .style.display=='none') {document.getElementById('spoiler1A') .style.display=''; document.getElementById('spoiler1A').classList.remove('tex2jax_ignore');typeset('spoiler1A')}else{document.getElementById('spoiler1A') .style.display='none'}".
This removes the tex2jax_ignore class and calls the typeset method we defined to tell MathJax to render that element.

How to make a single column in Telerik Radgrid Resizable?

I have the following Telerik RadGrid.
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" AllowSorting="true"
PageSize="50" HeaderStyle-Height="20" ShowStatusBar="true" AllowCustomPaging="True"
OnNeedDataSource="RadGrid1_NeedDataSource" OnSortCommand="RadGrid1_SortCommand"
OnPageSizeChanged="RadGrid1_PageSizeChanged" OnPageIndexChanged="RadGrid1_PageIndexChanged"
OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound">
<clientsettings>
<Selecting AllowRowSelect="True" />
<Resizing EnableRealTimeResize="true" />
</clientsettings>
<exportsettings filename="list">
</exportsettings>
<mastertableview datakeynames="ID" autogeneratecolumns="false">
<PagerStyle AlwaysVisible="true" PagerTextFormat="{4} {5} item(s) in {1} page(s)" />
<Columns>
<telerik:GridBoundColumn DataField="Contract" HeaderStyle-Width="20%" HeaderText="Contract Title"
UniqueName="Contract" SortExpression="Contract"> </telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Customer" HeaderStyle-Width="20%" HeaderText="Vendor"
UniqueName="Vendor" SortExpression="Customer"> </telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Contractor" HeaderStyle-Width="20%" HeaderText="Contractor"
UniqueName="Contractor" SortExpression="Contractor"></telerik:GridBoundColumn>
**<telerik:GridBoundColumn DataField="Name" HeaderText="Service"
UniqueName="Name" SortExpression="Name" Resizable="true"> </telerik:GridBoundColumn>**
</Columns>
</mastertableview>
</telerik:RadGrid>
I want to make only the last column (Name) resizable. I used Resizable="true" but it is not working. Is there any other way for it?
You need to add AllowColumnResize="True" on RadGrid and you can disable other column's resize properties by using Resizable="False".

Eclipse4 - Application Model and Core Expressions definitions

In Application.e4xmi I have two perspectives:
...
<children xsi:type="advanced:PerspectiveStack" xmi:id="_ySFusPeXEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.perspectivestack.main">
<children xsi:type="advanced:Perspective" xmi:id="_83bVsPeXEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.perspective.testmanager" label="Test manager">
...
<children xsi:type="advanced:Perspective" xmi:id="_bDA4oPeaEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.perspective.configurator" label="Configurator">
...
and a main menu with two items:
<mainMenu xmi:id="_xanVgPfWEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.menu.0">
<children xsi:type="menu:HandledMenuItem" xmi:id="_22vnAPfWEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.handledmenuitem.uno" label="uno" command="_LFFTsPhHEeK44MdhTvpdlg">
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_28cw8PfXEeKXHJPsnYiiYQ" coreExpressionId="com.myapplication.ui.perspectiveselected.testmanager"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_49obAPfWEeKXHJPsnYiiYQ" elementId="com.myapplication.ui.handledmenuitem.due" label="due" command="_NXT1APhHEeK44MdhTvpdlg">
<visibleWhen xsi:type="ui:CoreExpression" xmi:id="_ZP4lgPhHEeK44MdhTvpdlg" coreExpressionId="com.myapplication.ui.perspectiveselected.configurator"/>
</children>
</mainMenu>
The menu item "com.myapplication.ui.handledmenuitem.uno" has to be shown when perspective "com.myapplication.ui.perspective.testmanager" is shown.
The menu item "com.myapplication.ui.handledmenuitem.due" has to be shown when perspective "com.myapplication.ui.perspective.configurator" is shown.
So that, I defined in plugin.xml:
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="com.myapplication.ui.perspectiveselected.testmanager">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="com.myapplication.ui.perspective.testmanager">
</equals>
</with>
</definition>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="com.myapplication.ui.perspectiveselected.configurator">
<with
variable="activeWorkbenchWindow.activePerspective">
<equals
value="com.myapplication.ui.perspective.configurator">
</equals>
</with>
</definition>
</extension>
IT DOESN'T WORK !! (menu items are shown always)
Any ideas?
I see that you have applied on the definition itself. Create a new command and register it with your menu and then write your expression on it.
Example:
<command
commandId=" "
label=" "
mnemonic="A">
<visibleWhen
checkEnabled="false">
<with
variable="">
<equals
value="1">
</equals>
</with>
</visibleWhen>
</command>

ExpressionEngine Zoo Visitor field with Channel Images outputs four images for every one

I have a Zoo Visitor field called "member_gallery" which is a channel images field. Whenever I show the images, it creates 4 images for each one. However I do not want to output 4 images for each one. I want to output one image for each one. Here is the code I write:
{visitor:member_gallery}
{exp:channel_images:images entry_id="{entry_id}"}
<img src="{image:url:large}" alt="{image:title}" />
{/exp:channel_images:images}
{/visitor:member_gallery}
Here is the markup it spits out
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(1)__large.jpeg" alt="Images (1)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(2)__large.jpeg" alt="Images (2)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
<img src="http://staging.eventplanner.verityinteractive.com/images/19/images_(3)__large.jpeg" alt="Images (3)" />
To be clear, I do not want to display 4 images for every one. If you couldn't figure that out. To be extremely EXTREMELY clear, here is my question; How do I write this so I only get 1 image for each one I have uploaded, rather than 4? Thank you. I apologize for any confusion.
You don't need to use the channel entries tag within Zoo Visitor...
It looks as though you have a loop inside a loop, hence the duplication. Have you tried removing the channel entries tag?

Ribbon button should be hidden based on lead status - CRM 2011

I have custom button in lead ribbon. The custom button should be hidden when lead is qualified. How can I do that? Can any one please explain. I appreciate.
You can actually accomplish this entirely with built-in DisplayRule functionality. When a Lead is qualified, the StatusCode property is set to "Qualified", which translates into an OptionSet value of "3". You can check for the value of this property in a ValueRule and display/hide the control appropriately. I can think of two ways to achieve this:
Erik Pool's Visual Ribbon Editor
RibbonXml
<RibbonDiffXml>
<CustomActions>
<CustomAction Id="CompanyName.Form.lead.MainTab.Actions.Sample.CustomAction" Location="Mscrm.Form.lead.MainTab.Actions.Controls._children" Sequence="41">
<CommandUIDefinition>
<Button Id="CompanyName.Form.lead.MainTab.Actions.Sample" Command="CompanyName.Form.lead.MainTab.Actions.Sample.Command" Sequence="29" ToolTipTitle="$LocLabels:CompanyName.Form.lead.MainTab.Actions.Sample.LabelText" LabelText="$LocLabels:CompanyName.Form.lead.MainTab.Actions.Sample.LabelText" ToolTipDescription="$LocLabels:CompanyName.Form.lead.MainTab.Actions.Sample.Description" TemplateAlias="isv" />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
</Templates>
<CommandDefinitions>
<CommandDefinition Id="CompanyName.Form.lead.MainTab.Actions.Sample.Command">
<EnableRules />
<DisplayRules>
<DisplayRule Id="CompanyName.Form.lead.MainTab.Actions.Sample.Command.DisplayRule.ValueRule" />
</DisplayRules>
<Actions>
<Url Address="http://www.bing.com" />
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules>
<DisplayRule Id="CompanyName.Form.lead.MainTab.Actions.Sample.Command.DisplayRule.ValueRule">
<ValueRule Field="statuscode" Value="3" />
</DisplayRule>
</DisplayRules>
<EnableRules />
</RuleDefinitions>
<LocLabels>
<LocLabel Id="CompanyName.Form.lead.MainTab.Actions.Sample.LabelText">
<Titles>
<Title languagecode="1033" description="Sample" />
</Titles>
</LocLabel>
<LocLabel Id="CompanyName.Form.lead.MainTab.Actions.Sample.Description">
<Titles>
<Title languagecode="1033" description="Sample Description" />
</Titles>
</LocLabel>
</LocLabels>
</RibbonDiffXml>

Resources