嗨,我是竞争性编程的新手,我知道的唯一语言是Javascript但是如果我选择javascript选项我甚至无法理解如何获取输入以及如何在两个站点中打印输出的一些问题是Hackerrank代码看起来像这样
function processData(input) {
//Enter your code here
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
Run Code Online (Sandbox Code Playgroud)
对于某些问题,在同一个hackerrank中,初始代码看起来像这样
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var n = parseInt(readLine());
} …Run Code Online (Sandbox Code Playgroud) 正在使用 react 并尝试实现 Service Worker,我编写了一个用于推送通知的迷你 Service Worker 文件,当用户单击按钮时正在注册 Service Worker,现在如果我发送推送消息,它会按预期工作,但是当我重新加载时注册成功后,申请中的service worker页面显示为已删除,请参考截图
服务工作者代码
const self = this;
function receivePushNotification(event) {
console.log('[Service Worker] Push Received.');
console.log(event);
// const { image, tag, url, title, text } = event.data.json();
const options = {
data: '/neworders',
body: 'New order request',
vibrate: [200, 100, 200],
badge: 'https://spyna.it/icons/favicon.ico',
actions: [
{
action: 'Detail',
title: 'View',
icon: 'https://via.placeholder.com/128/ff0000',
},
],
};
event.waitUntil(self.registration.showNotification('Hello', options));
}
function openPushNotification(event) {
console.log(
'[Service Worker] Notification click Received.',
event.notification.data
);
event.notification.close();
event.waitUntil(clients.openWindow(event.notification.data));
} …Run Code Online (Sandbox Code Playgroud) javascript push-notification reactjs service-worker progressive-web-apps
我是Postgres和Sequelize的新手,我已成功连接到DB,试图在数据库中创建一个表,这是一个错误,表名不存在
sequelize.authenticate().then(() => {
console.log("Success!");
var News = sequelize.define('likes', {
title: {
type: Sequelize.STRING
},
content: {
type: Sequelize.STRING
}
}, {
freezeTableName: true
});
News.create({
title: 'Getting Started with PostgreSQL and Sequelize',
content: 'Hello there'
});
News.findAll({}).then((data) => {
console.log(data);
}).catch((err) => {
console.log(err);
});
}).catch((err) => {
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
哪里弄错了?它说错误:关系"喜欢"不存在.任何形式的帮助表示赞赏
我一直在尝试找出已经通过 MongoDB 手动创建的索引(我已经通过 mongobooster 为两个字段创建了 2d 球体索引,并通过定义它通过模式创建了一个)。现在,如果我在 mongodbooster 中运行此查询
db.collectionname.getIndexes();
Run Code Online (Sandbox Code Playgroud)
它给我带来了 3 个带有 name.key 的文档以及我使用过的索引。我想在猫鼬中执行相同的操作,但找不到相同的等效查询。我试过这个
const indexes = OrderSchema.indexes();
console.log('index:', indexes);
Run Code Online (Sandbox Code Playgroud)
但它只给了我一个索引,我在模式中定义了 _id 我还需要两个其他字段,其中包含 2d-sphere 索引,我怎么才能得到它。我在这里试图实现的是,如果已经创建了 2d 球体索引,则不要创建索引,否则创建一个索引,这正是我在这里试图实现的。任何帮助表示赞赏谢谢
我已经将谷歌地图API与我的应用程序集成以获得自动完成建议,它在我的笔记本电脑(Ubuntu)所有浏览器上运行良好.但是,最近我用iPad和iPhone测试过它不起作用.我无法点击建议的地点.我正在使用AngularJS,我的代码片段如下:
HTML
<div class="row">
<div class="col-md-6">
<form name="searchForm" ng-submit="fillInAddress()">
<div class="input-group well">
<input type="text" class="form-control" id="autocomplete" name="city" placeholder="Enter your city"
onFocus="geolocate()" required />
<span class="input-group-btn">
<button class="btn btn-primary" type="submit" ladda="ldloading.slide_left" data-style="slide-left" data-spinner-color="#000000"
ng-disabled="searchForm.$invalid">
<i class="fa fa-search"></i> Search
</button>
</span>
</div>
</form>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
var placeSearch, autocomplete;
function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete((document.getElementById('autocomplete')),
{types: ['geocode']});
autocomplete.addListener('place_changed', fillInAddress);
}
function fillInAddress() {
// Get the place details from the autocomplete object.
var place = autocomplete.getPlace();
locationfilter.lat=place.geometry.location.lat();
locationfilter.lon=place.geometry.location.lng();
$scope.getOrders($scope.reportParams,locationfilter);
}
$scope.getOrders …Run Code Online (Sandbox Code Playgroud) 我是 Bull 的新手。我尝试根据他们的文档代码运行 bull。流程正在启动,但我的工作尚未完成,或者不确定它是否触发完成事件?我不确定我在哪里犯了错误
下面附上我的代码
const Queue = require('bull');
const myFirstQueue = new Queue('my-first-queue',
{
redis: {
port: Config.redis.port,
host: Config.redis.host,
password: Config.redis.password
},
});
(async function ad() {
const job = await myFirstQueue.add({
foo: 'bar',
});
})();
myFirstQueue.process(async (job, data) => {
log.debug({ job, data }, 'Job data');
let progress = 0;
for (let i = 0; i < 10; i++) {
await doSomething(data);
progress += 10;
job.progress(progress).catch(err => {
log.debug({ err }, 'Job progress err');
});
log.debug({ progress …Run Code Online (Sandbox Code Playgroud) 我是 RDBMS 和 Sequelize 的新手,也想在现在对 JOINS 感兴趣的领域进行更多探索。我不知道如何通过 SEQUELIZE 执行 JOINS。我有 3 个表 USERS、ORDERS、PRODUCTS ORDERS 表包含 USERS、ProductS 主键作为其外键。我在用户模型下面附上了我的模型代码
const Sequelize = require('sequelize');
const sequelize = require('../config');
let Users = sequelize.define('users', {
id : {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
username: {
type: Sequelize.STRING,
},
password: {
type: Sequelize.STRING
}
});
module.exports = Users;
Run Code Online (Sandbox Code Playgroud)
产品型号
const Sequelize = require('sequelize');
const sequelize = require('../config');
let products=sequelize.define('products', {
id : {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
category : {
type: …Run Code Online (Sandbox Code Playgroud) 我已经参加了 MOOC(Coursera Angular)并遵循它。最近我更新了我的 npm,从那时起我遇到了构建错误。我在网上搜索过,但没有一个能解决我的问题。
ERROR in node_modules/@angular/material/dialog/typings/dialog-container.d.ts(10,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'BasePortalOutlet'.
node_modules/@angular/material/dialog/typings/dialog-container.d.ts(10,45): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'CdkPortalOutlet'.
node_modules/@angular/material/expansion/typings/accordion.d.ts(1,30): error TS2307: Cannot find module '@angular/cdk/accordion'.
node_modules/@angular/material/expansion/typings/expansion-panel.d.ts(10,34): error TS2307: Cannot find module '@angular/cdk/accordion'.
node_modules/@angular/material/expansion/typings/expansion-panel.d.ts(36,14): error TS2314: Generic type 'TemplatePortal<C>' requires 1 type argument(s).
node_modules/@angular/material/select/typings/select.d.ts(11,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/overlay"' has no exported member 'CdkConnectedOverlay'.
node_modules/@angular/material/sidenav/typings/drawer.d.ts(15,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/scrolling"' has no exported member 'CdkScrollable'.
node_modules/@angular/material/snack-bar/typings/snack-bar-container.d.ts(10,10): error TS2305: Module '"C:/wamp64/www/Coursera/Angular/Angular-Coursera/node_modules/@angular/cdk/portal"' has no exported member 'BasePortalOutlet'. …Run Code Online (Sandbox Code Playgroud) node.js ×5
javascript ×3
postgresql ×2
sequelize.js ×2
angular ×1
angularjs ×1
express ×1
google-maps ×1
ios ×1
ipad ×1
job-queue ×1
join ×1
mongodb ×1
mongoose ×1
queue ×1
rdbms ×1
reactjs ×1