which is the "vcl_backend_response" method - varnish

('/etc/varnish/default.vcl' Line 97 Pos 5)
sub vcl_backend_response {
----####################--
...which is the "vcl_backend_response" method
Legal returns are: "abandon" "deliver" "fail" "pass" "retry"
Running VCC-compiler failed, exited with 2
VCL compilation failed
my code is :
sub vcl_backend_response {
if ( beresp.status == 500 ||
beresp.status == 502 ||
beresp.status == 503 ||
beresp.status == 504 ||
beresp.status == 400 ||
beresp.status == 404 ||
beresp.status == 403 ){
set beresp.uncacheable = true;
}
include "/etc/varnish/additional_vcls/resp.vcl";
if (bereq.http.X-Application ~ "(?i)wordpress") {
include "/etc/varnish/backend_response/wordpress.vcl";
} else if (bereq.http.X-Application ~ "(?i)drupal") {
include "/etc/varnish/backend_response/drupal.vcl";
} else if (bereq.http.X-Application ~ "(?i)woocommerce") {
include "/etc/varnish/backend_response/woocommerce.vcl";
} else if (bereq.http.X-Application ~ "(?i)magento") {
if (bereq.http.X-Version) {
if (bereq.http.X-Version ~ "^2") {
include "/etc/varnish/backend_response/magento2.vcl";
} else {
include "/etc/varnish/backend_response/magento.vcl";
}
} else {
include "/etc/varnish/backend_response/magento.vcl";
}
} else if (bereq.http.X-Application ~ "(?i)mediawiki") {
include "/etc/varnish/backend_response/mediawiki.vcl";
} else if (bereq.http.X-Application ~ "(?i)joomla") {
include "/etc/varnish/backend_response/joomla.vcl";
} else if (bereq.http.X-Application ~ "(?i)phpstack") {
include "/etc/varnish/backend_response/phpstack.vcl";
} else {
include "/etc/varnish/backend_response/default.vcl";
}
}
sub vcl_backend_response {
if ( beresp.status == 500 ||
beresp.status == 502 ||
beresp.status == 503 ||
beresp.status == 504 ||
beresp.status == 400 ||
beresp.status == 404 ||
beresp.status == 403 ){
set beresp.uncacheable = true;
}
include "/etc/varnish/additional_vcls/resp.vcl";
if (bereq.http.X-Application ~ "(?i)wordpress") {
include "/etc/varnish/backend_response/wordpress.vcl";
} else if (bereq.http.X-Application ~ "(?i)drupal") {
include "/etc/varnish/backend_response/drupal.vcl";
} else if (bereq.http.X-Application ~ "(?i)woocommerce") {
include "/etc/varnish/backend_response/woocommerce.vcl";
} else if (bereq.http.X-Application ~ "(?i)magento") {
if (bereq.http.X-Version) {
if (bereq.http.X-Version ~ "^2") {
include "/etc/varnish/backend_response/magento2.vcl";
} else {
include "/etc/varnish/backend_response/magento.vcl";
}
} else {
include "/etc/varnish/backend_response/magento.vcl";
}
} else if (bereq.http.X-Application ~ "(?i)mediawiki") {
include "/etc/varnish/backend_response/mediawiki.vcl";
} else if (bereq.http.X-Application ~ "(?i)joomla") {
include "/etc/varnish/backend_response/joomla.vcl";
} else if (bereq.http.X-Application ~ "(?i)phpstack") {
include "/etc/varnish/backend_response/phpstack.vcl";
} else {
include "/etc/varnish/backend_response/default.vcl";
}
}

Related

Is there an ESLint rule that limits the number of return statements?

The rule I'm looking for is(the name is provisional.):
This rule limits the number of return statements in a function.
(The example is ugly, but I expect the following behavior.)
// "max-return-statement-per-function": ["error", 4]
// incorrect
function Foo(str) {
if (str === "a") {
return "a";
} else if (str === "b") {
return "b";
} else if (str === "c") {
return "c";
} else if (str === "d") {
return "d";
} else {
return "others";
}
}
// correct
function Foo(str) {
if (str === "a") {
return "a";
} else if (str === "b") {
return "b";
} else if (str === "c") {
return "c";
} else {
return "others";
}
}

Trying to create a command line interface in node

I'm attempting to create a command-line so I can do commands like !!help but it doesn't seem to run the other if statements if more code is needed to properly evaluate my situation then I'll gladly provide more
// CLI interface
rl.on('line', (line) => {
// CLI cmds
if (line == line.includes(prefixs.cliprefix)) {
if (line == line.includes('help')) {
console.log(clihelp()); console.log("new method"); clihelp();
} else {
//test for event
if (line == line.includes('event') && line == line.includes('list')) {
console.log("example method");
gists.get('5f718f4198f1ea91a37e3a9da468675c')
.then(ress => console.log(ress))
.catch(console.error);
console.log("new method");
console.log(gists.get('5f718f4198f1ea91a37e3a9da468675c'));
console.log("end");
}
}
} else {
// send cmd to mc
socket.send(JSON.stringify({
"body": {
"origin": {
"type": "player"
},
"commandLine": line,
"version": 1
},
"header": {
"requestId": "00000000-0000-0000-000000000000",
"messagePurpose": "commandRequest",
"version": 1,
"messageType": "commandRequest"
}
}));
console.log("command sent: " + line);
}
});
//CLI closed
The problem is with you if statements. You would like the code inside the if block to be run when the line variable includes some text I see. But the condition that you created is not correct.
They should be like this:
if (line.includes('help'))
instead of
if (line == line.includes('help'))
I was able to get it to work via useing tmi.js command handler example found here
https://tmijs.com/ and the knowledge of a if else if ladder found here https://www.google.com/amp/s/www.geeksforgeeks.org/else-statement-javascript/amp/
rl.on('line', (line) => {
if (line === line.includes(prefixs.cliprefix)) return;
const args = line.slice(prefixs.cliprefix.length).split(' ');
const command = args.shift().toLowerCase();
console.log("command = '" + command + "' args = '" + args + "'");
if(command === 'help') { clihelp(); }
if(command === 'ping') { console.log("Pinging twitch"); client.ping(); }
if(command === 'log') { console.log(logsettings); }
if(command === 'log' && args === args.include("on")) {
if(args === args.include("error")) {console.log("now logging Error's"); logsettings.type = 'error'; }
if(args === args.include("info")) {console.log("now logging Info"); logsettings.type = 'info'; }
if(args === args.include("debug")) {console.log("now logging debug"); logsettings.type = 'debug'; }
if(args === args.include("all")) {console.log("now logging everything"); logsettings.type = 'all'; }
return; }
if(command === 'log' && args.include("off")) { console.log("Logging is now OFF"); logsettings.log = 'off'; }
if(command === 'prefix') {
const nclip = args.slice(4);
const nmcp = args.slice(3);
if(args === args.include('cli')) { console.log("Prefix for " + args.slice(0,4) + " is now " + nclip); prefixs.cliprefix=nclip; }
if(args === args.include('mc')) { console.log("Prefix for " + args.slice(0,3) + " is now " + nmcp); prefixs.mcprefix = nmcp; }
if(args === ' ') { console.log(prefixs); }
return;
}
}); // CLI closed ```

Firebase Cloud Function to return data of 2 collections

I have written these 2 Cloud Functions to post data in the Cloud Firestore and they are working fine. Now I need to write a Cloud Function that should get data of both collections that were created above to post data. The data should be inside a new object and merged together
Desired JSON Output:
[
{
"course": "xxx";
"client": "hello";
"location": "lahore";
"instructor": "ahsan";
"bidding": true;
"price": "400";
"totalHours": "15";
"maxStudents": "30",
"listing": true,
"closeDays": "20",
"assistants": "hassan",
"publicNotes": "nothing to say",
"internalNotes": "nothing to say",
"course": "xxx",
"date": "25/9/2019",
"hour": "3",
"minute": "15",
"timeofday": "PM",
"tohour": "6",
"tominute": "15",
"totimeofday": "PM"
}
]
//Schedule a class
exports.scheduleClass = functions.https.onRequest((req, res) => {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET', 'POST');
res.set('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.end();
}
else
{
if(req.body.course != null && req.body.client != null && req.body.location != null && req.body.instructor != null && req.body.bidding != null
&& req.body.price != null && req.body.totalHours != null && req.body.maxStudents != null && req.body.listing != null && req.body.closeDays != null
&& req.body.assistants != null && req.body.publicNotes != null && req.body.internalNotes != null
|| req.body.course != undefined && req.body.client != undefined && req.body.location != undefined && req.body.instructor != undefined && req.body.bidding != undefined
&& req.body.price != undefined && req.body.totalHours != undefined && req.body.maxStudents != undefined && req.body.listing != undefined
&& req.body.closeDays != undefined && req.body.assistants != undefined && req.body.publicNotes != undefined && req.body.internalNotes != undefined) {
let docId = Math.floor(Math.random() * (99999 - 00000));
let newClass = {
"course": req.body.course,
"client": req.body.client,
"location": req.body.location,
"instructor": req.body.instructor,
"bidding": req.body.bidding,
"price": req.body.price,
"totalHours": req.body.totalHours,
"maxStudents": req.body.maxStudents,
"listing": req.body.listing,
"closeDays": req.body.closeDays,
"assistants": req.body.assistants,
"publicNotes": req.body.publicNotes,
"internalNotes": req.body.internalNotes
}
usersClasses.add(newClass).then(snapshot => {
res.send(200, {
"message": "Class was successfully created"
})
});
} else {
res.send(400, {
"message": "All fields are required"
})
}
}
});
//Add Time for classes
exports.addTimes = functions.https.onRequest((req, res) => {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET', 'POST');
res.set('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.end();
}
else {
if(req.body.course != null && req.body.date != null && req.body.hour != null && req.body.minute != null
&& req.body.timeofday != null && req.body.tohour != null && req.body.tominute != null && req.body.totimeofday != null
|| req.body.course != undefined && req.body.date != undefined && req.body.hour != undefined && req.body.minute != undefined && req.body.timeofday != undefined
&& req.body.tohour != undefined && req.body.tominute != undefined && req.body.totimeofday != undefined)
{
let docId = Math.floor(Math.random() * (99999 - 00000));
let newTimes = {
"course": req.body.course,
"tohour": req.body.tohour,
"tominute": req.body.tominute,
"totimeofday": req.body.totimeofday,
"date": req.body.date,
"hour": req.body.hour,
"minute": req.body.minute,
"timeofday": req.body.timeofday,
}
classtimesCollection.add(newTimes).then(snapshot => {
res.send(200, {
"message":"Time has been added"
})
});
}
else {
res,send(400, {
"message": "All fields are required"
})
}
}
});
I am able to get data from one collection like this:
exports.getClassesSchedule = functions.https.onRequest((req, res) => {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET', 'POST');
res.set('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.end();
}
else
{
let allClasses = [];
usersClasses.get()
.then(snapshot => {
snapshot.forEach(doc => {
allClasses.push(doc.data());
});
res.send(allClasses);
})
.catch(err => {
console.log("Error getting documents", err);
});
}
});
I think you're close you just need to make the other call. You'll want to use Promise.all to wait for both promises to be guaranteed to be complete before you start to collate the data.
exports.getClassesSchedule = functions.https.onRequest((req, res) => {
res.set('Access-Control-Allow-Origin', '*');
res.set('Access-Control-Allow-Methods', 'GET', 'POST');
res.set('Access-Control-Allow-Headers', 'Content-Type');
if (req.method === 'OPTIONS') {
res.end();
}
else
{
let classTimes = []
let promise1 = classTimesRef.get()
.then(snapshot => {
snapshot.forEach(doc => {
classTimes.push(doc.data());
});
return classTimes
})
.catch(err => {
console.log("Error getting documents", err);
});
let allClasses = [];
let promise2 = usersClassesRef.get()
.then(snapshot => {
snapshot.forEach(doc => {
allClasses.push(doc.data());
});
return allClasses
})
.catch(err => {
console.log("Error getting documents", err);
});
return Promise.all([promise1, promise2]).then(data => {
let times = data[0]
let classes = data[1]
// Collate the data here
return res.send()
}
}
});

Why is Spring Boot so slow in comparison to Node.js and Electron?

I was working on converting a trading applications API calls to Spring boot in order to leverage IB's TWS API. I figured I may as well keep it all in one application. Initially, I was issuing my requests through Angular 2, leveraging Electron. However, when I converted to Spring Boot, I noticed what took a second to return in with Angular and Electron, took upwards of almost seven seconds. I'm having a hard time believing that Java is this slow in comparison to JavaScript. I'm assuming at this point there's a much faster way to do what I'm attempting to do in Java. Any help would be appreciated. Again, I'm simply looking for advice on how to speed things up here, if at all possible.
//Spring Boot Service Layer ---- 7 seconds :-o Seriously....
public List<QuoteResponse> getGapUps(PriceParams p) {
GapUpFilter guf = new GapUpFilter(p);
int payloadSize = 200;
StringBuilder payLoad = new StringBuilder();
String stocks = this.getAllStocks();
String[] sArr = stocks.split(",");
LinkedList<String> ll = new LinkedList<String>( Arrays.asList(sArr));
List<QuoteResponse> qrList = new ArrayList<QuoteResponse>();
while (ll.size() > 0) {
int i = 0;
while (i < payloadSize && ll.size() > 0) {
String stock = ll.pop();
if (stock != null && stock.length() > 0 && ll.size() > 1) {
payLoad.append(stock);
payLoad.append(",");
}
if (stock != null && stock.length() > 0 && ll.size() == 1) {
payLoad.append(stock);
}
i++;
}
QuoteResponseWrapper qrw = this.getPrice(payLoad.toString());
QuoteResponse qr = guf.filterQuote(qrw.getQuoteResponse());
if (qr.getResult().length > 0) {
qrList.add(qr);
}
payLoad = new StringBuilder();
}
return qrList;
}
// Angular, Node.js with Electron - instantaneous
geMarketGaps(stocks: string, pFilter: PriceParams) {
this.securityService.getGaps(stocks).takeUntil(this.ngUnsubscribe).subscribe(lst => {
for (let i = 0; i < lst.quoteResponse.result.length; i++) {
try {
const ppq = new PrePostQuote();
ppq.symbol = lst.quoteResponse.result[i].symbol;
try { ppq.pclose = lst.quoteResponse.result[i].regularMarketPrice.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.cprice = lst.quoteResponse.result[i].regularMarketPrice.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.regularMarketPrice = lst.quoteResponse.result[i].regularMarketPrice.raw; } catch (e) { }
try { ppq.ask = lst.quoteResponse.result[i].ask.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.bid = lst.quoteResponse.result[i].bid.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.shortName = lst.quoteResponse.result[i].shortName; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.sharesOutstanding = lst.quoteResponse.result[i].sharesOutstanding.fmt; } catch (e) { ppq.sharesOutstanding = '0'; }
try { ppq.regularMarketVolume = lst.quoteResponse.result[i].regularMarketVolume.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.averageDailyVolume3Month = lst.quoteResponse.result[i].averageDailyVolume3Month.raw; } catch (e) {
console.log(ppq.symbol, e); }
try { ppq.epsTrailingTwelveMonths = lst.quoteResponse.result[i].epsTrailingTwelveMonths.raw; } catch (e) {
console.log(ppq.symbol, e); }
try { ppq.priceToBook = lst.quoteResponse.result[i].priceToBook.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.askSize = lst.quoteResponse.result[i].askSize.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.bidSize = lst.quoteResponse.result[i].bidSize.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.fullExchangeName = lst.quoteResponse.result[i].fullExchangeName; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.regularMarketDayHigh = lst.quoteResponse.result[i].regularMarketDayHigh.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.regularMarketDayLow = lst.quoteResponse.result[i].regularMarketDayHigh.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.regularMarketOpen = lst.quoteResponse.result[i].regularMarketOpen.raw; } catch (e) {console.log(ppq.symbol, e); }
try { ppq.shortPotential = ppq.getShortPotential(1.2); } catch (e) { }
try {
ppq.marketState = lst.quoteResponse.result[i].marketState;
// console.log('Market State: => ' + ppq.symbol, ppq.marketState);
} catch (e) { }
if (!ppq.marketState) {
continue;
}
try { ppq.regularMarketChangePercent = lst.quoteResponse.result[i].regularMarketChangePercent.raw; } catch (e) { }
try { ppq.pctraw = ppq.regularMarketChangePercent; } catch (e) { console.log(e); }
if (ppq.marketState === 'REGULAR') {
this.marketState = 'Reg Mkt';
}
if ((ppq.marketState === 'POST')
&& lst.quoteResponse.result[i].postMarketPrice) {
try { ppq.cprice = lst.quoteResponse.result[i].postMarketPrice.raw; } catch (e) { console.log(e); }
try { ppq.postMarketChangePercent
= lst.quoteResponse.result[i].postMarketChangePercent.raw; } catch (e) { console.log(e); }
try { ppq.pctgain = lst.quoteResponse.result[i].postMarketChangePercent.fmt; } catch (e) { console.log(e); }
try { ppq.pctraw = ppq.postMarketChangePercent; } catch (e) { console.log(e); }
this.marketState = 'Post Mkt';
}
if ((ppq.marketState === 'PREPRE' || ppq.marketState === 'POSTPOST'
|| ppq.marketState === 'CLOSED') && lst.quoteResponse.result[i].postMarketPrice) {
try { ppq.cprice = lst.quoteResponse.result[i].postMarketPrice.raw; } catch (e) { console.log(e); }
try { ppq.postMarketPrice = lst.quoteResponse.result[i].postMarketPrice.raw; } catch (e) { console.log(e); }
try { ppq.postMarketChangePercent = ppq.getPrePrePctChange(); } catch (e) { console.log(e); }
try { ppq.pctgain = ppq.getPrePrePctChange().toFixed(2) + '%'; } catch (e) { console.log(e); }
try {
ppq.pctraw = ppq.postMarketChangePercent;
if ( ppq.pctraw > 5) {
console.log(ppq.symbol + ' is greater than five percent');
}
} catch (e) { console.log(e); }
this.marketState = 'Post Mkt';
}
if (ppq.marketState === 'PRE' && lst.quoteResponse.result[i].preMarketPrice) {
try { ppq.cprice = parseFloat(lst.quoteResponse.result[i].preMarketPrice.raw); } catch (e) { console.log(e); }
try { ppq.preMarketChangePercent
= parseFloat(lst.quoteResponse.result[i].preMarketChangePercent.raw); } catch (e) { console.log(e); }
try { ppq.pctgain = lst.quoteResponse.result[i].preMarketChangePercent.fmt; } catch (e) { console.log(e); }
try { ppq.pctraw = ppq.preMarketChangePercent; } catch (e) { console.log(e); }
this.marketState = 'Pre Mkt';
}
//////////////////////////////////////////////////////////////////////////////
if (ppq.cprice >= pFilter.minPrice && ppq.cprice <= pFilter.maxPrice) {
if (ppq.pctraw > 0
&& this.activeFilter === 'Market Movers'
&& (ppq.marketState === 'PRE' || ppq.marketState === 'PREPRE' || ppq.marketState === 'POST' || ppq.marketState === 'POSTPOST'
|| ppq.marketState === 'CLOSED'
)
) {
if (ppq.postMarketChangePercent >= pFilter.percent || ppq.preMarketChangePercent >= pFilter.percent ) {
this.quotes.push(ppq);
}
}
//////////////////////////////////////////////////////////////////////////////
if (ppq.pctraw > 0 && this.activeFilter === 'Pct Gainers') {
if (ppq.regularMarketChangePercent >= pFilter.percent) {
this.quotes.push(ppq);
}
}
//////////////////////////////////////////////////////////////////////////////
if (ppq.pctraw < 0 && this.activeFilter === 'Market Losers'
&& (ppq.marketState === 'PRE' || ppq.marketState === 'PREPRE' || ppq.marketState === 'POST'
|| ppq.marketState === 'POSTPOST' || ppq.marketState === 'CLOSED')
) {
if (ppq.postMarketChangePercent <= (pFilter.percent * -1) || ppq.preMarketChangePercent <= (pFilter.percent * -1)) {
this.quotes.push(ppq);
}
}
//////////////////////////////////////////////////////////////////////////////
if (ppq.pctraw < 0 && this.activeFilter === 'Pct Losers') {
if (ppq.regularMarketChangePercent <= (pFilter.percent * -1)) {
this.quotes.push(ppq);
}
}
//////////////////////////////////////////////////////////////////////////////
}
} catch (ex) {
console.log(ex);
}
}
this.recordsProcessed++;
this.securityService.progressStart.next(this.recordsProcessed);
if (this.recordCount === this.recordsProcessed) {
this.showRecs = true;
}
}, error => {
this.recordsProcessed++;
this.securityService.progressStart.next(this.recordsProcessed);
if (this.recordCount === this.recordsProcessed) {
this.showRecs = true;
}
});
}
For anyone who is interested, CompleteableFuture was the solution I employed. I was able to literally pull down over 7MB of JSON in a fraction of the time, literally all quote data for all stock exchanges. By making each request utilize a new thread, the queries ran in parallel, so fast in fact, I had to inject a slight delay in the calls, which laughably is what consumes most of the time. I have to admit, I was of the school of thought that Node.js was certainly faster due to REPL and its non-blocking architecture. However, after taking a deeper dive into the Rabbit hole of Java's multi-threaded abyss, I would strongly caution against such claims.
#Async
public void loadPriceQuotes(String stocks) throws InterruptedException, ExecutionException {
this.currentRecord++;
System.out.println(this.currentRecord + " => " + this.recordCount);
URLUtility urlUtil = new URLUtility();
RestTemplate rt = new RestTemplate();
CompletableFuture.supplyAsync(new Supplier<QuoteResponseWrapper>() {
#Override
public QuoteResponseWrapper get() {
String url = urlUtil.getPriceURL(stocks);
ResponseEntity<QuoteResponseWrapper> response = rt.getForEntity(url, QuoteResponseWrapper.class);
for (Quote q: response.getBody().getQuoteResponse().getResult()) {
SkyWalker.stockQuotes.add(q);
}
return response.getBody();
}
},executor);
return;
}

What is wrong with this script?

var isEven = function(number) {
if (number%2 === 0) {
return true;
};
else if (isNaN(number) === true) {
return ("please input a number");
};
else {
return false;
};
};
Your script should not have the ; behind your closing brackets
Try this:
var isEven = function(number){
if (number%2 === 0) {
return true;
} else if (isNaN(number)===true) {
return ("please input a number");
} else {
return false;
}
}

Resources