Select only inline code blocks [closed] - regex

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I need to select every inline code blocks (not multilane)
Here is text https://regex101.com/r/8e7nPL/7
Example of inline blocks that I need to extract: f.call();, yield(), Fiber

this could help you:
function test(text) {
var re = /`([^`\n]+)`/g;
let match;
while(match = re.exec(text)) {
console.log('match', match);
}
}
test(
`
Пример создания файбера и передача ему в качестве аргумента вызываемой функции:
\`\`\`
auto f = new Fiber(&foo);
\`\`\`
\`f.call();\` вызов файбера
\`Fiber.yield();\` метод \`yield()\` класса \`Fiber\` вызывающий преостановку выполнение текущей функции
Пример:
\`\`\`
import std.stdio;
import core.thread;
void main()
{
auto f = new Fiber(&foo);
f.call(); // Prints Hello
f.call(); // Prints World
}
void foo()
{
writeln("Hello");
Fiber.yield();
writeln("World");
}
\`\`\`
Результат:
\`\`\`
> app.exe
Hello
World\`
`
)

Related

loop failing when wrapped in try catch to run few times [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
Have this code where i am trying to run a loop for few times to make sure i do get my result, but for some reason, i am still getting an error displayed on sreen and it is not even doing the cflog so i can know what is going on, any help will be appreciated
var aData = [];
for (i = 1; i <= 10; i++) {
try {
var a = {};
var as = calltoapitoogetdata;
a['count'] = as;
ArrayAppend(aData, mData);
var retJSON = serializeJSON(aData);
writedump(retJSON);
//return serializeJSON(aData);
break;
} catch (any e) {
i = i + 1;
cflog(text = "Call failed #i#", application = true, file = "loogevent");
writedump(i);
}
}
Thanks
If your code is still erroring it is most likely coming from the cflog call being made in your cfcatch. If you are running a version of Adobe ColdFusion the script version would be :
WriteLog(type="Error", file="myapp.log", text="[#ex.type#] #ex.message#");
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-t-z/writelog.html
Lucee has made many of the CFScript functions equivalent of their tag names but with Adobe CF there are a number of functions that do not comply with this. <cfdump> -> writeDump for example.
Too long for a comment.
I think troubleshooting is easier if all available information is right in front of you on the screen. So, I would troubleshoot like this. Your code is below with my additions in uppercase:
var aData = [];
for (i = 1; i <= 10; i++) {
try {
WRITEOUTPUT('TRY NUMBER #I# <BR>);
var a = {};
var as = calltoapitoogetdata;
WRITEDUMP(AS);
a['count'] = as;
ArrayAppend(aData, mData);
var retJSON = serializeJSON(aData);
writedump(retJSON);
//return serializeJSON(aData);
break;
} catch (any e) {
i = i + 1; // THIS LINE IS NOT NECESSARY
WRITEOUTPUT('CATCH NUMBER #I# <BR>);
cflog(text = "Call failed #i#", application = true, file = "loogevent"); //THIS LINE GETS REPLACED BY
WRITEDUMP(E);
writedump(i); // THIS LINE GOES AWAY
}
}

Parser JSON ON QT [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Is it possible to use an operator || in json like this :
{
"ven":{
"source":"logicCtrl" ,
"msg":"radio_volume" || "radio-mute", || "radio3",
"type":"int"
}
}
i can after get data by parsing data in C++ side like this :
QFile jsonFile("VenParser.json");
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "problème d'overture du fichier, exit";
}
QByteArray jsonData = jsonFile.readAll();
QJsonParseError *err = new QJsonParseError();
QJsonDocument doc = QJsonDocument::fromJson(jsonData, err);
if (err->error != 0)
qDebug() << err->errorString();
Venparser myparser;
if (doc.isNull())
{
qDebug() << "Document invalide";
}
else if (doc.isObject())
{
//recuperer l'object json
QJsonObject jObject = doc.object();
//convertir l'object json to variantmap
QVariantMap mainMap = jObject.toVariantMap();
// variant map
QVariantMap Map = mainMap["ven"].toMap();
myparser.source = Map["source"].toString();
myparser.msg = Map["msg"].toString();
myparser.type = Map["type"].toString();
header.H file : i define my struct
struct Venparser {
QString source;
QString msg;
QString type;
My problem is that i don't want a list in my "msg" but something like this :
when i call myparser.msg , then it will check just the value i need in msg and return it.
"msg":"radio_volume" || "radio-mute", || "radio3",
Thanks,
Your example with the || token is not a valid JSON. You can read more about its format here. However, if I understand you correctly, you can easily use JSON arrays for your task.
JSON:
{
"ven": {
"source": "logicCtrl",
"msg": ["radio_volume", "radio-mute", "radio3"],
"type": "int"
}
}
C++:
You can access the msg array using the toStringList() method. Also, you can use QVariantList and toList() respectively if you fill your array with data different from strings.
QStringList messages = Map["msg"].toStringList();
Now the messages variable contains "radio_volume", "radio-mute" and "radio3" values so you can extract the required string any way you need using your code.
If you still need to parse your exact example (which is technically not a valid JSON as I said before), you will have to go with writing your own parser, which is a bit wide topic for the answer.

Bash for manipulating curly bracket delimited config files [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Currently I have a config file of the following form:
under Time {
TimeStep = 0.001;
MaxTime = 0.2;
MaxIts = 400;
Type = Implicit;
under Implicit {
Type = ForwardEuler;
Jacobian = FiniteDifference;
under Newton {
MaxIts = 20;
Eps = 0.01;
}
}
}
First Question: I want to write a set of bash scripts that can
set property = value in a file; add it if it is not there.
get property from such a file.
line-by-line editting is not suitable here: take MaxIts for example, the script needs to distinguish between Time.MaxIts and Time.Implicit.MaxIts.
Second Question: I want to write a bash script that transforms above into:
Time.TimeStep = 0.001;
Time.MaxTime = 0.2;
Time.MaxIts = 400;
Time.Type = Implicit;
Time.Implicit.Type = ForwardEuler;
Time.Implicit.Jacobian = FiniteDifference;
Time.Implicit.Newton.MaxIts = 20;
Time.Implicit.Newton.Eps = 0.01;
so that sed or awk can do the job simply.
Here's how to do the 2nd part:
$ cat tst.awk
function descend(name) {
while ( (getline > 0) && !/}/ ) {
if ( /{/ ) {
descend(name "." $2)
}
else {
sub(/^[[:space:]]+/,"")
print name "." $0
}
}
}
{ descend($2) }
$ awk -f tst.awk file
Time.TimeStep = 0.001;
Time.MaxTime = 0.2;
Time.MaxIts = 400;
Time.Type = Implicit;
Time.Implicit.Type = ForwardEuler;
Time.Implicit.Jacobian = FiniteDifference;
Time.Implicit.Newton.MaxIts = 20;
Time.Implicit.Newton.Eps = 0.01;
I'm sure you can write a script to do the reverse mapping and then you can just do all the manipulation related to your first question on the flat format above.

Renaming placed containers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm just wondering is there a way to give or rename a container like chest that is already on ground?
I mean not using NMS. But the spigot API to edit the names?
There is no API for it but it is possible with NMS. I made this method some time ago, it allows you to name any tile entity.
You give it a normal bukkit block and name that will be applied to the block. Name can have § coloring char.
With this code you can make version using reflections if you want to avoid NMS and CB imports.
import net.minecraft.server.v1_8_R1.INamableTileEntity;
import net.minecraft.server.v1_8_R1.TileEntity;
import net.minecraft.server.v1_8_R1.TileEntityBrewingStand;
import net.minecraft.server.v1_8_R1.TileEntityChest;
import net.minecraft.server.v1_8_R1.TileEntityCommand;
import net.minecraft.server.v1_8_R1.TileEntityDispenser;
import net.minecraft.server.v1_8_R1.TileEntityEnchantTable;
import net.minecraft.server.v1_8_R1.TileEntityFurnace;
import net.minecraft.server.v1_8_R1.TileEntityHopper;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld;
public static void setName(String name, Block block) {
final CraftWorld world = (CraftWorld) block.getWorld();
final TileEntity nmsTileEntity = world.getTileEntityAt(block.getX(), block.getY(), block.getZ());
if (nmsTileEntity instanceof INamableTileEntity) {
if (nmsTileEntity instanceof TileEntityChest) {
((TileEntityChest) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityFurnace) {
((TileEntityFurnace) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityDispenser) {
((TileEntityDispenser) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityHopper) {
((TileEntityHopper) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityBrewingStand) {
((TileEntityBrewingStand) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityEnchantTable) {
((TileEntityEnchantTable) nmsTileEntity).a(name);
} else if (nmsTileEntity instanceof TileEntityCommand) {
((TileEntityCommand) nmsTileEntity).getCommandBlock().setName(name);
}
nmsTileEntity.update();
}
}

Problems with NSNumber [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hey guys i'm building a tweak for instagram i'm adding a sub preference called instatroll similar to trolltwitter to change the number of followers to any number the user sets (using PSEditTextCell) here is my code so far
#import <Foundation/Foundation.h>
static NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:#"/var/mobile/Library/Preferences/com.idevicelover.InstaEnhancer.plist"];
NSNumber *chosenNumber = [NSNumber numberWithInt:999];
int number = chosenNumber;
static BOOL followerson = NO;
%hook IGUser -(void)setFollowerCount:(NSNumber*)fp8{
followerson = [[plist objectForKey:#"followerson"]boolValue];
if(followerson){
%orig(number);
}
else{
%orig;
}
}
%end
%ctor
{
NSDictionary *InstaEnhancer = [[NSDictionary alloc] initWithContentsOfFile:#"/var /mobile /Library/Preferences/com.idevicelover.InstaEnhancer.plist"];
if ([InstaEnhancer objectForKey:#"numberoffollowers"]) number = [[InstaEnhancer objectForKey:#"numberoffollowers"] intValue];
[InstaEnhancer release];
}
i'm getting this error when compiling :"assigning to NSNumber * from incompatible type "int"
NSNumber is an object. In order to use it as a primitive data type such as an int, you have to pull that type of value out of it with the appropriate method:
NSNumber *chosenNumber = [NSNumber numberWithInt:999];
int number = [chosenNumber intValue];
Also, later on, here:
number = [[InstaEnhancer objectForKey:#"numberoffollowers"] intValue];
If at this point number is an int (I have no clue as this syntax isn't C++ or Objective-C) then this should be fine. But if number is of type NSNumber *, then you need to drop the call to intValue:
number = [InstaEnhancer objectForKey:#"numberoffollowers"];