RegEx for matching URLs with video IDs - ios

I am trying to make an iOS shortcut that will makes me open all the websites videos links at once in new tabs so for that I need a RegEx for it.
Here is how the video links on this website look like:
https://m.worldstarhiphop.com/apple/video.php?v=wshhn5icmk9cKSyh9A17
https://m.worldstarhiphop.com/apple/video.php?v=wshhc8Ew271C2BZE0l31
I have this so far:
^(?!image$).*(worldstarhiphop.com/apple/video)
Because I don’t want the shortcut to open all images links but only video links.

I have added multiple capturing groups to this expression to be easy to modify/change and understand:
^((https?:\/\/.*)(worldstarhiphop.com)((\/apple\/video.php\?v=)|\/videos\/video.php\?v=)([A-Za-z0-9]{20}))
I did not close the right side using $, which you can do so, if you might want to.
The URLs you are wishing to match are in two mobile and web versions, which I have added both with various protocols, just in case. If it is unnecessary, you may remove it.
RegEx Descriptive Graph
The graph visualize how it works and you might want to test other expressions in this link:
Basic Performance Test
This JavaScript snippet returns runtime of a 1-million times for loop for performance.
const repeat = 1000000;
const start = Date.now();
for (var i = repeat; i >= 0; i--) {
const string = 'https://m.worldstarhiphop.com/apple/video.php?v=wshhc8Ew271C2BZE0l31';
const regex = /^((https?:\/\/.*)(worldstarhiphop.com)((\/apple\/video.php\?v=)|\/videos\/video.php\?v=)([A-Za-z0-9]{20}))/gm;
var match = string.replace(regex, "\nGroup #1: $1\nGroup #2: $2 \nGroup #3: $3 \nGroup #4: $4\nGroup #6: $6 \n");
}
const end = Date.now() - start;
console.log("YAAAY! \"" + match + "\" is a match πŸ’šπŸ’šπŸ’š ");
console.log(end / 1000 + " is the runtime of " + repeat + " times benchmark test. 😳 ");

Related

Print each process in OPL

I'm a college student in Taiwan and I'm doing a research about "how much wind turbines and solar photovoltaic panels should be installed to satisfy the require of minimum energy penetration rate in a semiconductor factory".
My professor hope I can display each variable in each period, but I don't know what code I should write.
Maybe there will be "execute" and "writeln" in my code? But there is nothing happened.
The following is my brief code:
{string} product = ...;
range time = 1..2;
{string} GreenPower = ...;
string NonGreenPower = ...οΌ›
dvar float InPut[product][time]; //In t period, amount of input of products
dvar float working[product][time]; //In t period, amount of working of products
dvar float OutPut[product][time]; //In t period, amount of output of products
So, I want to see the change in IntPut in each time, how to do it.
Thanks for your reading and tolerating my grammatical or spelling mistakes QQ
In order to print the solution to a console, you can use a post-processing block. A post-processing block is implemented by putting an execute block after the constraint specification (after the subject to block).
A post-processing block to print variables could look like this (untested code):
execute {
for (var p in product) {
for (var t in time) {
writeln(p + ", " + t + ": " + InPut[p][t] + ", " + working[p][t] + ", " + OutPut[p][t]);
}
}
}
Many of the examples shipped with CPLEX use post processing to display solutions to the console. You can look through them to learn what can be done in post processing and what are different ways to visualize solutions in the console.

Batch process macro in Fiji fails to work

I have a hyperstack which has 2 time frames and 13 z projection in each time frame. From the menu I choose Process, Batch, and then Macro. In the input I select the input folder and then determine the output folder in the output. Finally I use the code below to sum all the z projection:
run("Z Project...", "projection=[Max Intensity] all");
close();
Here is an screenshot:
After running process or Test the file I get in the output is the same as input without the z projection being summed.
Here is a sample tif file (13 MB). I tried to do this on different computers but the result is the same.
I'm not familiar with using batch process in this way, so I'm not sure I can address your issue directly, but, I can say that I know how to do this by recording/writing a macro directly. First though, have you tried using the "Save" button provided in the GUI you screenshotted? In that case, if it still doesn't work, you'd maybe want to do something like this in the macro editor instead:
openPath = getDirectory("Choose Source Directory");
savePath = getDirectory("Choose Save Location");
File.makeDirectory(savePath + "UNIQUE ID");
savePath = savePath + "UNIQUE ID" + File.separator;
files = getFileList(openPath);
setBatchMode(true);
for (timePoint = 0; timePoint < (files.length); timePoint++)
{
run("Z Project...", "projection=[Max Intensity] all");
saveAs("Tiff", savePath + "UNIQUE ID");
close();
}
setBatchMode(false);
I hope that helps some!

Sage notebook limit representation

In Sage notebook, I want to print the standard mathematical notation for the limit of a function.
I expect something like this:
f = x+1
latex(limit(f, x=0)) + '=' + lim(f, x=0)
to print a properly formatted 'lim x->0 x+1 = 1'
naturally, I figured it out shortly after posting the question, always seems to work that way. here's the code from my notes-book:
show("NOTE: how to print lim")
# raw latex
f = (x^2-1)/(x-1)
Lf = LatexExpr(r'\lim_{x\to\infty}') + latex(f)
show(Lf)
# dummy limit
from sage.calculus.calculus import dummy_limit as lim
Lf = lim(f, x, 0)
out = latex(Lf) + "=" + latex(limit(f, x=0))
show(out)
Not very elegant, really wish the limit had a better way to represent itself in unevaluated form.

Pattern matching a binary in erlang

I'm trying to pattern match a binary against this
<<_:(A * ?N + A + B)/binary,T:1/binary,_/binary>>
However it seems erlang throws an error saying that variable T is unbound. Just a quick explanation: I want to ignore a certain number of bytes and then read a byte and then ignore the remaining bytes. How can I achieve this?
In bit syntax we can't use runtime expressions as bit size.
We can use only constants, compile time expressions like _:(4*8)/binary and variables: _:Var/binary.
In your case, solution is to bind A * ?N + A + B to variable first.
IgnoredBytes = A * ?N + A + B,
<<_:IgnoredBytes/binary,T:1/binary,_/binary>> = SomeBinary,
T.
It's Better explained in answer from [erlang-questions]

Feed an intermediate digest to a sha-1 function?

I need to compute a hash of a text that is in two pieces, held by two different parties, who should not have access to each others' texts.
Since SHA-1 is incremental I have heard that this should be possible but cannot find any answers with Google of any libraries that implement this.
I'd like the first party to SHA-1 hash its part of the text, and then feed the hash (digest) to the 2nd party, and they will continue with hashing, and compute the total digest of the combined texts. If this is possible, does anyone know of any library that takes a text and a previous hash as input arguments? Preferably in javascript or python but I'm actually happy to accept any language.
Update: I am looking at the source code of the forge (javascript) implementation of SHA-1, and see this code in the update method:
// initialize hash value for this chunk
a = s.h0;
b = s.h1;
c = s.h2;
d = s.h3;
e = s.h4;
And at the end of that method:
s.h0 = (s.h0 + a) | 0;
s.h1 = (s.h1 + b) | 0;
s.h2 = (s.h2 + c) | 0;
s.h3 = (s.h3 + d) | 0;
s.h4 = (s.h4 + e) | 0;
So it seems that by carrying these values + any remaining data in the input buffer over, one should be able to re-create the state of the SHA-1 object at party number 2. So a bit of the buffer will leak over but I think that should be fine. Will investigate further to see if this works.

Resources