What is wrong with my pattern for preg_replace? - preg-replace

I have a variable containing the following html code
Bloom's: Knowledge<br> Difficulty: Medium<br> Learning Objective: 01-03 <br> Topic: Economic<br>
I want to use preg_replace to remove each of 'Bloom's:...' , 'Difficulty:....', 'Learning Objective:....', 'Topic:...'
I tried to match those terms but it doesn't work.
/Bloom's:.*<br>/ or /Difficulty:.*<br>
Can you show me the right way? Thanks a lot!

Not sure what you want but:
$whole_question = "Bloom's: Knowledge<br> Difficulty: Medium<br> Learning Objective: 01-03 <br> Topic: Economic<br>";
$removeKeys = array(
'Bloom:',
'Difficulty:',
'Learning Objective:',
'Topic:',
);
foreach ($removeKeys as $removeKey){
$removeKey = '/'.$removeKey.'.*<br>/';
$whole_question = preg_replace($removeKey,'<br>',$whole_question);
}
echo $whole_question;//Bloom's: Knowledge<br> <br>

Related

how can I add phone "tel" link in shortcode

Im challanged with adding a "tel" link in a shortcode. I have tried several ways and I have not succeeded.
Here is a sample of the current code:
[vc_custom_heading text="(123) 456-7890" font_container="tag:p|font_size:22px|text_align:left|color:#326496|line_height:26px" use_theme_fonts="yes" font_weight="600" link="url:tel:1234567890|title:Phone Number" el_class="ms-0 ms-lg-4 mr-md-0 ps-3 ps-md-1 mb-0 d-none d-md-block"]
Thank You,
Gary
Solved. See code below.
[porto_info_box pos="top" icon_type="porto" read_more="box" icon_size="55" icon_border_radius="500" title="Phone Number" subtitle="(123) 456-7890" title_font_style="700" subtitle_font_style="300" icon_porto="porto-icon-tablet" icon_color="#3296c8" title_font_size="1.5em" title_font_color="#ffffff" subtitle_font_size="1.2em" subtitle_font_color="rgba(255,255,255,0.5)" icon_margin_bottom="16px" title_margin_bottom="1px" sub_title_margin_bottom="0px" el_class="p-b-lg mb-5" link="url:tel%3A1234567890"]

Easy way to cite academic references in the README.md of a github-repo

I was just wondering if there is any easy way that I can use a .bib-file to create academic references in the README of a github site.
In rmarkdown I'm used to just do the following in the text:
#test2010
and if I have specified the correct bibtex-file in the yaml-header it works perfectly.
Is there anything similar in "normal" github markdown?
Bibliographies are not supported in GitHub Flavored Markdown(GFM). The workaround is producing GFM from R Markdown.
Step: create README.Rmd and bibliography.bib and knit README.Rmd.
README.Rmd:
---
output:
md_document:
variant: markdown_github
bibliography: bibliography.bib
---
[#xie2018]
bibliography.bib:
#Book{xie2018,
title = {R Markdown: The Definitive Guide},
author = {Yihui Xie and J.J. Allaire and Garrett Grolemund},
publisher = {Chapman and Hall/CRC},
address = {Boca Raton, Florida},
year = {2018},
note = {ISBN 9781138359338},
url = {https://bookdown.org/yihui/rmarkdown},
}
The output README.md:
(Xie, Allaire, and Grolemund 2018)
<div id="refs" class="references csl-bib-body hanging-indent">
<div id="ref-xie2018" class="csl-entry">
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. *R Markdown: The
Definitive Guide*. Boca Raton, Florida: Chapman; Hall/CRC.
<https://bookdown.org/yihui/rmarkdown>.
</div>
</div>

What is preventing some of the content from an Invoke-WebRequest showing?

I am trying to get some acsii art characters directly from a webpage. You can navigate to the page using the following URL.
http://patorjk.com/software/taag/#p=display&f=Acrobatic&t=A
If you go to that page you will see a rendering of the character A using the Acrobatic font.
o
<|>
/ \
o/ \o
<|__ __|>
/ \
o/ \o
/v v\
/> <\
Using the following code nets me most of the page.
$fontUrlTemplate = "http://patorjk.com/software/taag/#p=display&f={0}&t={1}"
$fontName = [uri]::EscapeUriString("Acrobatic")
$character = "A"
$fontUrl = $fontUrlTemplate -f $fontName, $character
$webResult = Invoke-WebRequest $fontUrl
$webResult.Content
However when I inspect the Content the actual result I am looking for is missing.
...
<div id="maincontent" >
<div id="outputFigDisplay" ></div>
</div>
...
There should be something like this in there
<pre id="taag_output_text" style="float:left;" class="fig" contenteditable="true">...</pre>
I am sure there is a server side reason for this but I would like to better understand and, if possible, mitigate it. I have tried mucking around with -ContentType and -UserAgent but it didn't change anything

Pulling Data from Google spreadsheet

I am having difficulty pulling data from Google spreadsheet
I have added following gem files
gem 'roo'
gem 'google_drive'
gem 'google-spreadsheet-ruby'
My jobs file is
require 'roo'
require 'rubygems'
def fetch_spreadsheet_data()
google_user = "MY EMAIL ADDRESS"
google_password = "MY PASSWORD"
workbook = Roo::Google.new("https://docs.google.com/spreadsheet/ccc?key=1hdwnrDsuJId1FLE0yWICYP1HGqYNu2NHH2IcoPyAzOQ#gid=0",user: google_user, password: google_password)
send_event('catchup_data', {current: s.cell('B',2) })
send_event('Bounced_back', {current: s.cell('B',3) )
end
SCHEDULER.every '5m' do
fetch_spreadsheet_data()
end
My dashboard.erb file has following html
<li data-row="2" data-col="3" data-sizex="1" data-sizey="1">
<div data-id="bounce_back" data-view="Number" data-title="Triage - Work in Progress" style="background-color:#5AC352;"></div>
</li>
<li data-row="2" data-col="4" data-sizex="1" data-sizey="1">
<div data-id="catchup_data" data-view="Number" data-title="Squad catchup sessions last month" style="background-color:#DBA901;"></div>
</li>
Not sure what am I missing that the data is not coming through. Can anyone please help me?
There are a few things wrong that I can see:
You're sending 'Bounced_back' but binding to the id of 'bounce_back'
You are trying to get the cell data from 's' but 's' is undefined
Looking at the Roo docs, I believe you have copied 's' from there. Just above that, they use sheet instead so I believe you have to grab the sheet from the workbook before using it.
I googled a bit and found this: http://etzelstorfer.com/en/dashing-graph-from-google-spreadsheet/
In summary, this should work for you:
def fetch_spreadsheet_data()
google_user = "MY EMAIL ADDRESS"
google_password = "MY PASSWORD"
workbook = Roo::Google.new("https://docs.google.com/spreadsheet/ccc?key=1hdwnrDsuJId1FLE0yWICYP1HGqYNu2NHH2IcoPyAzOQ#gid=0",user: google_user, password: google_password)
s = workbook.sheets[0] # assuming first sheet in workbook
send_event('catchup_data', {current: s.cell('B',2) })
send_event('bounce_back', {current: s.cell('B',3) )
end
SCHEDULER.every '5m' do
fetch_spreadsheet_data()
end

Mason2 wrong utf8 encoding with the "go" method

Bit long question, because AFAIK Poet/Mason2 isn't the very often used framework - so I'm trying to be detailed.
Two years ago I asked a question how to make Mason2 utf8 clean. As far as i know, here isn't much new in Mason/Poet in this field - and unfortunately today I meet another problem. Simple test case:
$ poet new my #create new poet application
$ cd my
Override some methods, allowing to use utf8 in the components:
add to ./lib/My/Mason/Compilation.pm
override 'output_class_header' => sub {
return join("\n",
super(), qq(
use utf8;
use Encode qw(encode decode);
)
);
};
The above adds to each compiled Mason component the use utf8....
Also need encode the output from Mason (Plack need bytes), so in: ./lib/My/Mason/Request.pm
override 'run' => sub {
my($self, $path, $args) = #_;
my $result = super();
$result->output( Encode::encode('UTF-8', $result->output()) );
return $result;
};
Now, can create a component such page.mc for example with a content:
% sub { uc($_[0]) } {{
a quick brown fox jumps over the lazy dog.
διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα.
árvíztűrő tükörfúrógép.
dość gróźb fuzją, klnę, pych i małżeństw!
эх, чужак, общий съём цен шляп (юфть) – вдрызг!
kŕdeľ šťastných ďatľov učí pri ústí váhu mĺkveho koňa obhrýzať kôru a žrať čerstvé mäso.
zwölf boxkämpfer jagen viktor quer über den großen sylter deich.
% }}
After running a poet app bin/run.pl you can go to: http://0:5000/page and will get a correct content.
A QUICK BROWN FOX JUMPS OVER THE LAZY DOG. ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ
ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ. ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP. DOŚĆ GRÓŹB
FUZJĄ, KLNĘ, PYCH I MAŁŻEŃSTW! ЭХ, ЧУЖАК, ОБЩИЙ СЪЁМ ЦЕН ШЛЯП (ЮФТЬ) –
ВДРЫЗГ! KŔDEĽ ŠŤASTNÝCH ĎATĽOV UČÍ PRI ÚSTÍ VÁHU MĹKVEHO KOŇA OBHRÝZAŤ
KÔRU A ŽRAŤ ČERSTVÉ MÄSO. ZWÖLF BOXKÄMPFER JAGEN VIKTOR QUER ÜBER DEN
GROSSEN SYLTER DEICH.
But when create another component, say go.mc with a content
% $m->go('/page');
the internal redirect (the go method) somewhat mess up the content and will produce:
A QUICK BROWN FOX JUMPS OVER THE LAZY DOG. ÎÎÎΦΥÎÎÎΤÎ
ÎÎÎÎÎΠΤΠÎΩΠΣÎΣ ÎÎ Î ÎÎÎÎÎΠΨΥΧÎÎÎ
ΤΡÎÎÎÎΤÎ. ÃRVÃZTÅ°RÅ TÃKÃRFÃRÃGÃP. DOÅÄ GRÃŹB
FUZJÄ, KLNÄ, PYCH I MAÅÅ»EÅSTW! ЭХ, ЧУÐÐÐ, ÐÐЩÐÐ
СЪÐРЦÐРШÐЯР(ЮФТЬ) â ÐÐРЫÐÐ! KÅDEĽ Å
ŤASTNÃCH ÄATĽOV UÄà PRI ÃSTà VÃHU MĹKVEHO KOÅA OBHRÃZAŤ
KÃRU A ŽRAŤ ÄERSTVà MÃSO. ZWÃLF BOXKÃMPFER JAGEN VIKTOR QUER
ÃBER DEN GROSSEN SYLTER DEICH.
Strange, the $m->visit() works correctly. So, somewhere in Poet/Mason is need do something to get correct output for the go method.
Could anyone help?
I've been working on a plugin for Mason to deal with encoding. $result->output is the wrong place to encode output, because visit will run a subrequest, encoding its own content at the end, before returning to the original component, which then re-encodes everything when it completes. So the content in the visit gets encoded twice. I'm surprised you are having a problem with go, because that discards all previous content and starts again, which should be OK.
Have a look at https://github.com/davebaird/mason-plugin-withencoding