VSCode settings for .t files - visual-studio-code

I want to change some settings for .t files for Prysk/Cram tests. How do I do this? Normally, language-specific settings can be set with:
{
"[html]": {
"someSetting": false
}
}
But none of these work:
{
"[t]": {
"someSetting": false
},
"[*.t]": {
"someSetting": false
},
"[prysk]": {
"someSetting": false
},
"[cram]": {
"someSetting": false
}
}
The best I've been able to come up with is to treat .t files as plaintext with a file association, and set that setting instead.
{
"files.associations": {
"*.t": "plaintext"
},
"[plaintext]": {
"someSetting": false
},
}
This isn't ideal because it affects other plaintext files also, of course.

Related

SendGrid: Disable Clicktrack using Node

I am using the sendgrid-nodejs library to send emails using SendGrid.
I want to disable click-tracking on a per-email basis.
I understand that you can include an attribute within dynamic templates to disable click tracking:
Click tracking can be turned off for individual links by including the clicktracking=off attribute inside the anchor of an HTML link before the href. For example, <a clicktracking=off href="http://example.com">link text</a> would not be tracked.
However, I wish to control this programmatically.
According to SendGrid documentation, it is possible to disable click-tracking by using the clicktrack filter:
{
"filters": {
"clicktrack": {
"settings": {
"enable": 0,
"enable_text": false
}
}
}
}
Looking at the Mail constructor, it appears we have the ability to set headers. The type bindings indicate it expects header values to be a string.
headers?: { [key: string]: string }
Note: I can confirm this per SendGrid's error return (if attempting to pass an object):
{
"body": {
"errors": [
{
"message": "Invalid type. Expected: string, given: object.",
"field": "headers",
"help": "http://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#message.headers"
}
]
}
}
Regardless of what I pass, nothing seems to have any impact. The emails are being sent successfully, but click-tracking is not being disabled.
const { SENDGRID_KEY } = process.env
const mail = require('#sendgrid/mail')
mail.setApiKey(SENDGRID_KEY)
mail.send({
headers: {
// this doesn't have any impact
"X-SMTPAPI": JSON.stringify({
filters: {
clicktrack: {
settings: {
enable: 0,
enable_text: false
}
}
}
}),
// neither does this
"filters": JSON.stringify({
clicktrack: {
settings: {
enable: 0,
enable_text: false
}
}
}),
},
to: 'somebody#email.com',
from: 'nobody#email.com',
templateId: 'd-xxxxxxxxxxxxxxxxxxxxxxxx',
dynamic_template_data: {
subject: 'Hello World'
}
})
Why isn't this working?
I've found my answer. There is a trackingSettings property available:
const { SENDGRID_KEY } = process.env
const mail = require('#sendgrid/mail')
mail.setApiKey(SENDGRID_KEY)
mail.send({
trackingSettings: {
clickTracking: {
enable: false,
enableText: false
}
},
to: 'somebody#email.com',
from: 'nobody#email.com',
templateId: 'd-xxxxxxxxxxxxxxxxxxxxxxxx',
dynamic_template_data: {
subject: 'Hello World'
}
})

$elemMatch on array of objects

My schema has 6 attributes of type Array, which can each contain objects, like this:
alpha : Array
0 : Object
linkedID : "62495a66fb140b240476d8ff"
verified : false
1 : Object
linkedID : "62494fd789291c4f58bdad86"
verified : true
...
I want to write a query that returns a document where at least one of these Arrays contains an object that has the attribute verified == false. I've tried with $elemMatch:
myModel.findOne(
{$or: [
{ alpha: { $elemMatch: { verified: false } } },
{ beta: { $elemMatch: { verified: false } } },
{ gamma: { $elemMatch: { verified: false } } },
{ delta: { $elemMatch: { verified: false } } },
{ epsilon: { $elemMatch: { verified: false } } },
{ zeta: { $elemMatch: { verified: false } } }
] }
)
But this didn't work. I think this may be because it's a nested object, but I have no idea how to solve this. I'd really appreciate any advice.

Mongodb double query

I have following MongoDb collection:
{
"id":1,
"isBig": true } {
"id":2,
"isBig": true } {
"id":3,
"isBig": true } {
"id":4,
"isBig": true } {
"id":5,
"isBig": false } {
"id":6,
"isBig": false } {
"id":7,
"isBig": false }
I'd like to choose four random items: 2 should be big and 2 not. My attempt:
db.aggregate([
{ $match: { isBig: true } },
{ $sample: { size: 2 } }
]).toArray()
This choose only two big. I would need also two not big. COndition is I can access database only one time.

VueCLI 3 - Eslint Prettier

I have issues with this Vue project configuration. I'm using prettier and eslint but files don't get the format the way they should.
I'm using VS Code as code editor and I have prettier installed with formatting on save.
Code Example:
async fetchGenres({ commit }) {
try {
const response = await Vue.axios.get('/api/genres.json/', {
headers: { Authorization: '' }
})
commit('SET_GENRES', response.data)
} catch (err) {
handleRouteError({ err, showReportDialog: false })
}
},
Always gets formatted to this:
async fetchGenres({
commit
}) {
try {
const response = await Vue.axios.get('/api/genres.json/', {
headers: {
Authorization: ''
}
})
commit('SET_GENRES', response.data)
} catch (err) {
handleRouteError({
err,
showReportDialog: false
})
}
},
I've also noticed in case I have semi-colons in the code, they are not removed, at that is not the desired behaviour. Formatting should also get rid of semi-colons.
babel.config.js
module.exports = {
presets: ['#vue/app']
}
.eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
node: true
},
plugins: ['vue', 'prettier'],
extends: ['plugin:vue/essential', '#vue/prettier'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
},
parserOptions: {
parser: 'babel-eslint'
}
}
.prettierrc
{
"printWidth": 160,
"tabWidth": 4,
"singleQuote": true,
"semi": false,
"trailingComma": "none",
"bracketSpacing": true
}
It seems as

Karma debugging in Chrome no longer working

We are working on an Angular project where we are using Karma/Jasmine for our testing environment. We've been using the karma-chrome-launcher for debugging the tests and it was working great. For some reason, it has stopped working lately. I can't figure out why though, as we haven't changed anything regarding that pipeline. We tried updating to latest Karma (1.4.1), but that didn't help. Has anyone else seen this issue and been able to fix it? Help is appreciated. I've attached two images of what the Chrome inspector looks like when you first open the debugger and then after setting a breakpoint and hitting Refresh (it should look the same as the 1st image, but doesn't) edit: karma.config at bottom as well
'use strict';
var path = require('path');
var conf = require('./gulp/conf');
var _ = require('lodash');
var wiredep = require('wiredep');
var pathSrcHtml = [
path.join(conf.paths.src, '/**/*.html')
];
function listFiles() {
var wiredepOptions = _.extend({}, conf.wiredep, {
dependencies: true,
devDependencies: true
});
var patterns = wiredep(wiredepOptions).js
.concat([
path.join(conf.paths.src, '/app/**/*.module.js'),
path.join(conf.paths.src, '/app/**/*.js')
])
.concat(pathSrcHtml)
.concat('karmaMobileFramework/*.js');
var files = patterns.map(function(pattern) {
return {
pattern: pattern
};
});
files.push({
pattern: path.join(conf.paths.src, '/assets/**/*'),
included: false,
served: true,
watched: false
});
return files;
}
module.exports = function(config) {
var configuration = {
files: listFiles(),
singleRun: false,
autoWatch: true,
preprocessors : {
'/**/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
stripPrefix: conf.paths.src + '/',
moduleName: 'directive-templates'
},
logLevel: 'WARN',
frameworks: ['jasmine', 'jasmine-matchers', 'angular-filesort'],
angularFilesort: {
whitelist: [path.join(conf.paths.src, '/**/!(*.html|*.spec|*.mock).js')]
},
browsers : ['Chrome'],
plugins : [
'karma-chrome-launcher',
'karma-angular-filesort',
'karma-coverage',
'karma-jasmine',
'karma-jasmine-matchers',
'karma-ng-html2js-preprocessor',
'karma-htmlfile-reporter',
'karma-junit-reporter'
],
coverageReporter: {
type : 'html',
dir : 'reports/coverage/',
reporters: [
{ type: 'html', subdir: 'report-html' },
{ type: 'cobertura', subdir: 'report-jenkins' }
]
},
reporters: ['progress', 'html', 'junit'],
junitReporter: {
outputDir: 'reports/tests/',
outputFile: 'test-results.xml',
useBrowserName: false
},
htmlReporter: {
outputFile: 'reports/tests/results.html',
pageTitle: 'BOLT Unit Tests'
},
proxies: {
'/assets/': path.join('/base/', conf.paths.src, '/assets/')
}
};
// This is the default preprocessors configuration for a usage with Karma cli
// The coverage preprocessor is added in gulp/unit-test.js only for single tests
// It was not possible to do it there because karma doesn't let us now if we are
// running a single test or not
configuration.preprocessors = {};
pathSrcHtml.forEach(function(path) {
configuration.preprocessors[path] = ['ng-html2js'];
});
config.set(configuration);
};