quagga doesn't detected my primary barcode - reactjs

I tried to use the quagga module to detect my barcode number but I couldn't find the best initialization to do that.
this is my quagga initial:
Quagga.init({
inputStream: {
type : "LiveStream",
constraints: {
width: 640,
height: 480,
facing: "environment" // or user
}
},
locator: {
patchSize: "medium",
halfSample: true
},
numOfWorkers: 2,
decoder: {
readers : [ "code_128_reader"]
},
locate: true
}, function(err) {
if (err) {
return console.log(err);
}
Quagga.start();
});
Quagga.onDetected(this._onDetected);
and this is the image that I am going to detect:
enter image description here
finally after scanning this barcode quagga detected "6251503158" but I need to 1503158fe0ce46e6cbd
who knows the best initialization quagga to detect my barcode?

Related

Create a custom element in EditorJs

I added EditorJs plugin in my react js application:
import ReactDOM from "react-dom";
import React, { Component } from "react";
import EditorJs from "react-editor-js";
import { EDITOR_JS_TOOLS } from "./constants";
class ReactEditor extends Component {
render() {
return (
<EditorJs
tools={EDITOR_JS_TOOLS}
data={{
blocks: [
{
type: "header",
data: {
text: "Editor.js",
level: 2
}
},
{
type: "paragraph",
data: {
}
},
{
type: "header",
data: {
text: "Key features",
level: 3
}
},
{
type: "list",
data: {
style: "unordered",
items: [
"It is a block-styled editor",
"It returns clean data output in JSON",
"Designed to be extendable and pluggable with a simple API"
]
}
},
{
type: "header",
data: {
text: "What does it mean «block-styled editor»",
level: 3
}
},
{
type: "paragraph",
data: {
text:
'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.'
}
},
{
type: "paragraph",
data: {
text:
'There are dozens of ready-to-use Blocks and the simple API for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.'
}
},
{
type: "header",
data: {
text: "What does it mean clean data output",
level: 3
}
},
{
type: "paragraph",
data: {
text:
"Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below"
}
},
{
type: "paragraph",
data: {
text:
'Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.'
}
},
{
type: "paragraph",
data: {
text:
"Clean data is useful to sanitize, validate and process on the backend."
}
},
{
type: "delimiter",
data: {}
},
{
type: "paragraph",
data: {
text:
"We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏"
}
},
{
type: "image",
data: {
file: {
url:
"https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg"
},
caption: "",
withBorder: true,
stretched: false,
withBackground: false
}
}
],
version: "2.12.4"
}}
/>
);
}
}
ReactDOM.render(<ReactEditor />, document.getElementById("root"));
According to the documentation i can create a custom element:
render() {
return (
<EditorJs holder="custom">
<div id="custom" />
</EditorJs>
);
}
Question: I want to add as a custom element an input: <input type="text"/>, but i don't manage even if i do:
<EditorJs holder="custom">
<input id="custom" type="text"/>
</EditorJs>
Who knows how to add this custom element in the plugin above?
demo: https://codesandbox.io/embed/react-editor-js-23opz
I found in the documentation that i can create a plugin for editor.js:
https://editorjs.io/the-first-plugin. One of example looks like this:
class SimpleImage {
static get toolbox() {
return {
title: 'Image',
icon: '<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>'
};
}
render() {
return document.createElement('input');
}
save(blockContent) {
return {
url: blockContent.value
}
}
}

AJV validator and custom or user-friendly error message

I have the following schema and json to validate using ajv. I am developing a REST API that takes a JSON and gets validated against the schema and it returns the error (400- with the ajv error) or (200 - when successfully validated)
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [ "countries" ],
"definitions": {
"europeDef": {
"type": "object",
"required": ["type"],
"properties": { "type": {"const": "europe"} }
},
"asiaDef": {
"type": "object",
"required": ["type"],
"properties": { "type": {"const": "asia"} }
}
},
"properties": {
"countries": {
"type": "array",
"items": {
"oneOf":[
{ "$ref": "#/definitions/europeDef" },
{ "$ref": "#/definitions/asiaDef"}
]
}
}
}
}
const data = {
"countries":[
{"type": "asia1"},
{"type": "europe1"}
]
}
const isValid = ajv.validate(schema, data); //schema, data
if(! isValid){
console.log(ajv.errors);
}
and the error is:
[ { keyword: 'const',
dataPath: '/countries/0/type',
schemaPath: '#/definitions/europeDef/properties/type/const',
params: { allowedValue: 'europe' },
message: 'should be equal to constant' },
{ keyword: 'const',
dataPath: '/countries/0/type',
schemaPath: '#/definitions/asiaDef/properties/type/const',
params: { allowedValue: 'asia' },
message: 'should be equal to constant' },
{ keyword: 'oneOf',
dataPath: '/countries/0',
schemaPath: '#/properties/countries/items/oneOf',
params: { passingSchemas: null },
message: 'should match exactly one schema in oneOf' },
{ keyword: 'const',
dataPath: '/countries/1/type',
schemaPath: '#/definitions/europeDef/properties/type/const',
params: { allowedValue: 'europe' },
message: 'should be equal to constant' },
{ keyword: 'const',
dataPath: '/countries/1/type',
schemaPath: '#/definitions/asiaDef/properties/type/const',
params: { allowedValue: 'asia' },
message: 'should be equal to constant' },
{ keyword: 'oneOf',
dataPath: '/countries/1',
schemaPath: '#/properties/countries/items/oneOf',
params: { passingSchemas: null },
message: 'should match exactly one schema in oneOf' } ]
I know why the error is appearing (reason: as I have used 'asia1' & 'europe1' and it is not conforming the schema standard)
My question is, as I have derived this schema so I can pretty much understand the error. But for a third person it would definitely take some time to figure it out (and it may take more time, if the schema/errors are more complex).
If I returned that whole error message as a response as it is, it will be more complex error message to understand and to present to the enduser.
So, Is there any way by which I can provide more meaningful & user friendly error message to understand ?
ex: Invalid countries values found in JSON
I have checked: ajv-errors, better-ajv-errors but they are not providing the exact way I want?
Can someone suggest how to do that in a more user friendly way or any alternative mechanism?
I am using below code for generating the human readable error message
let msg: string = "Wrong body" // fallback error message;
if (errors && errors.length > 0) {
const error = errors[0];
msg = `${error.instancePath} ${error.message}`;
}
res.status(4xx).json({
errorMsg: msg,
});
I am using below dependencies to generate the validate functions in runtime with the below code
"dependencies": {
"ajv": "^8.11.0",
... // other dependencies
}
"devDependencies": {
"ajv-cli": "^5.0.0"
}
Below code gets run before project build and hence creating runtime generated validation files
const ajv = new Ajv({
schemas: schemas, // list of parsed json *.json schemas
code: { source: true, esm: true },
});
let moduleCode = standaloneCode(ajv);
Below is the few examples of error messaged diaplayed
Case of missing property:
"/items/0/price must have required property 'currency_code'"
Case of additional property: "/address must NOT have additional properties"
Case when quantity is fraction(allowed is +ve number): "/items/0/quantity must be integer"
Case when quantity is -ve(allowed is +ve number): "/items/0/quantity must be >= 1"
Case when passed value is not allowed(case of the enum): /items/0/price/currency_code must be equal to one of the allowed values

MongoDB - AND request on array with GeoJSON element

I've looked at other issues without finding a suitable answer for my problem, so I hope you may help me.
SITUATION
I am currently working on a localisation app with MongoDB. For the moment I test my queries in the MongoDB shell.
I have a collection of Point documents with locations. I use GeoJSON objects for the coordinates of my point.
Here is what a Point document looks like :
{
_id: "Roma_DellArte",
localisations: [
{ location_type_id: 1, location: { type: "Point", coordinates: [ 41.9097306,12.2558141 ] } }
]
}
My location_type_id refers to another collection, juste for you to know.
I already made a query which gets me all the points near a precise location :
db.point.createIndex({ 'localisations.location': "2dsphere" })
db.point.find({
'localisations.location': {
$near: {
$geometry: { type: "Point", coordinates: [ 48.8588377, 2.2770207 ] },
$minDistance: 0,
$maxDistance: 100000
}
}
})
Now I would like to query all the points which are near a precise location AND those with a specific location_type_id.
TRIES AND FAILS
I tried many queries in the MongoDB shell but none of them produced a satisfying result.
Query 1
I think it doesn't return anything because location: isn't an exact field.
db.point.createIndex({ location: "2dsphere" })
db.point.find({
'localisations': {
location_type_id: 1,
location: {
$near: {
$geometry: { type: "Point", coordinates: [ 48.8588377, 2.2770207 ] },
$minDistance: 0,
$maxDistance: 100000
}
}
}
})
Query 2
The main problem here is it gets me a point document if in the localisations field there is an object with a correct location_type_id and an object with the correct location. It is not necessarily the same object, which I want it to be.
see: https://docs.mongodb.com/manual/tutorial/query-array-of-documents/#combination-of-elements-satisfies-the-criteria - second paragraph at the end.
db.point.createIndex({ 'localisations.location': "2dsphere" })
db.point.find({
'localisations.location_type_id': 1,
'localisations.location': {
$near: {
$geometry: { type: "Point", coordinates: [ 48.8588377, 2.2770207 ] },
$minDistance: 0,
$maxDistance: 100000
}
}
})
Query 3
I wanted to try this method : https://docs.mongodb.com/manual/tutorial/query-arrays/#query-for-an-array-element-that-meets-multiple-criteria
db.point.createIndex({ location: "2dsphere" })
db.point.find({
localisations: {
$elemMatch: {
location_type_id: 1,
location: {
$near: {
$geometry: { type: "Point", coordinates: [ 48.8588377, 2.2770207 ] },
$minDistance: 0,
$maxDistance: 100000
}
}
}
}
})
Unfortunately, I get this error:
Error: error: {
"ok" : 0,
"errmsg" : "geoNear must be top-level expr",
"code" : 2,
"codeName" : "BadValue"
}
Now you know everything, I hope you can help me.

flowplayer playlist track auto change is giving error

I am using Flowplayer(in Mean js audio streaming project) for RTMP audio streaming with Wowza streaming engine software and using below service of angular js.
app.service('flowPlayerService', ['$cookies','constant',function ($cookies,constant) {
player: null,
currentTitle:'',
constructPlaylist: function (playlist) {
var currentObj = this;
this.player = flowplayer("flashPlayer", "lib/flowplayer/flowplayer-3.2.18.swf", {
playlist:playlist,
onBegin: function(talk){
console.log('clip changed');
},
onFail:function(){
//alert('loading failed');
},
onFinish:function(){
console.log('finisheds');
},
// engine:'html5',
// Specify the location of the RTMP plugin.
plugins: {
rtmp: {
url: 'lib/flowplayer/flowplayer.rtmp-3.2.13.swf',
netConnectionUrl: 'rtmp://10.10.3.11/vod'
},
controls: {
autoHide: 'never',
url: 'lib/flowplayer/flowplayer.controls-3.2.16.swf',
tooltips: {
buttons: true,
fullscreen: false,
pause: 'Continue playing',
},
playlist: true,
fullscreen:false,
},
dock: {
enabled:false,
gap: 5,
autoHide: false
}
},
onMouseOut:function(){
console.log('mouse out');
}
//canvas: {backgroundGradient: 'none'}
});
console.log(this.player);
//this.player = flowplayer();
},
}
While playing single track it is working fine.But when I try to run playlist first track plays file but when first track finished it gives error like:-
VM36229:1 [ERROR] time 13:51:35.968 :: 201, Unable to load stream or clip file, cannot play video: Error #2154, clip: '[Clip] 'mp3:02 Jashn-E-Bahaara-1469775940586.mp3''
below playlist array example:-
[{
url:"mp3:track.mp3",
provider:"rtmp",
title:'track title'
},
{
url:"mp3:track1.mp3",
provider:"rtmp",
title:'track title1'
}
]
please help.
Passing the "duration" to clip objects resolve this issue.

Uncaught Rally.data.ModelFactory.getModel(): Could not find registered factory for type: milestone

Trying to display Milestone for each release, but when trying to create DataStore for Milestone getting error
Uncaught Rally.data.ModelFactory.getModel(): Could not find registered factory for type: milestone
below is my code any ideas or suggestions on this
_getMileStones: function(startDate, endDate, project_id) {
var startDateFilter = Ext.create('Rally.data.QueryFilter', {
property: 'TargetDate',
operator: '>',
value: startDate
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '<',
value: endDate
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '!=',
value: null
});
startDateFilter = startDateFilter.and({
property: 'TargetDate',
operator: '!=',
value: null
});
var filters = startDateFilter;
Ext.create('Rally.data.wsapi.Store',{
model: 'milestone',
autoLoad: true,
filters: filters,
context: {
project: project_id,
projectScopeDown: true,
projectScopeUp: false
},
fetch: ['Name','FormattedID','DisplayColor'],
listeners: {
load: function(store,records) {
console.log("records values", records);
}
}
}, this);
},
The current stable rc3 release candidate of AppSDK2 predates milestones. They are not available in rc3. When I use rc3 I get the same error you get. If I switch to "x", in the app's config file, and use rab build to rebuild the app, the error goes away:
{
"name": "myapp",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "x",
"javascript": [
"App.js"
],
"css": [
"app.css"
]
}
Generally it is not recommend using "x" because it is constantly changes. It is not a stable version. But as long as you know that, you may use "x". The AppSDK next release may not be too far in the future, and it will include support for Milestones.
UPDATE: AppSDK2.0 GA has not been announced yet, but it is expected to be released soon. If you use "sdk":"2.0" you get Milestone data.
"x" returns Milestones, but it is a head version that is subject to constant changes. 2.0rc3 does not have Milestones.
You may choose to use 2.0 even though it is not formally available yet.
This app example:
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
Ext.create('Rally.data.wsapi.Store',{
model: 'milestone',
autoLoad: true,
fetch: ['Name'],
listeners: {
load: function(store,records) {
console.log("records values", records);
}
}
}, this);
}
});
Along with this config:
{
"name": "milestones",
"className": "CustomApp",
"server": "https://rally1.rallydev.com",
"sdk": "2.0",
"javascript": [
"App.js"
],
"css": [
"app.css"
]
}
will return milestone data:

Resources