how i can sort this object by user_id ?
{
key_1: { user_id: 3 },
key_2: { user_id: 1 },
key_3: { user_id: 2 }
}
I need this:
{
key_2: { user_id: 1 },
key_3: { user_id: 2 },
key_1: { user_id: 3 }
}
thanks for help
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
how i can sort this object by user_id ?
{
key_1: { user_id: 3 },
key_2: { user_id: 1 },
key_3: { user_id: 2 }
}
I need this:
{
key_2: { user_id: 1 },
key_3: { user_id: 2 },
key_1: { user_id: 3 }
}
thanks for help
I have a SharePoint List (list_dls) which has all the Email addresses. The list has a single column with Field name “Title”. I need to validate that the Item in the “LookupField” is contained in the ‘list_dls’. The list has over 5000 emails, hence I will need to do a CAML query. The script does not seem to find the item. Any ideas to get it to work would be really appreciated.
Here is the code.
<input type='button' value='get Lists' onclick="PopulateLookupField();"/>
<p id="demo"></p>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
var LookupField = '[email protected]';
function PopulateLookupField()
{
var clientContext = new SP.ClientContext.get_current();
var LookupList = clientContext.get_web().get_lists().getByTitle('list_dls');
var camlQuery_list = new SP.CamlQuery();
camlQuery_list.ViewXml = @"<View Scope='RecursiveAll'><ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields><RowLimit Paged='TRUE'>5000</RowLimit></View>";
LookupList<ListItem> allListItems = new LookupList<ListItem>();
do
{
var listItemCollection = LookupList.GetItems(camlQuery_list);
clientContext.Load(listItemCollection);
clientContext.ExecuteQuery();
allListItems.AddRange(listItemCollection);
var ItemFound = listItemCollection.Where(item => item.FieldValues["Title"].ToString().Contains(LookupField);
if(ItemFound !== null){break;}
camlQuery_list.ListItemCollectionPosition = listItemCollection.ListItemCollectionPosition;
} while (camlQuery_list.ListItemCollectionPosition != null);
clientContext.load(ItemFound);
alert("ItemFound = " + ItemFound);
}
</script>
I am trying to POST the songFiles array pushed from the getTableData() function (inside the ajax request) into the /api/fileNames endpoint, which is then sent to a callback postFileNames() that should post the array, but I just can’t seem to get it working. Any help would be appreciated.
I’m a bit of beginner with using ajax and flask, I have scoured far and wide for a solution, but can’t seem to find any to fit my goal, forgive my lack of knowledge.
JavaScript Code
function getTableData() {
$.ajax({
method: "GET",
url: "/api/getSong",
dataType: "json",
success: function(data) {
createMusicTable();
let indexObj = Object.keys(data.song).length;
for (var i = 0; i < indexObj; i++) {
var song = data.song[i]
var id = data.song[i].song_id;
var fileName = data.song[i].song_file + ".mp3";
songFiles.push(fileName);
appendMusic(song, id);
songTitle.id = "s" + i;
console.log("td-ok");
postFileNames(songFiles);
}
}
});
}
function postFileNames(data) {
$.ajax({
method: "POST",
url: "/api/fileNames",
dataType: "json", // data is an array, so not sure what to put here.
data: data, // not sure if correct
success: function(data) {
// should: post the data into the endpoint.
// data is not logged, goes straight to error.
console.log(data)
},
error: function() {
console.log("cry")
}
})
}
FLASK Endpoint Code
@app.route("/api/fileNames", methods=['POST', 'GET'])
def fileNameStorage():
if request.method == 'POST':
data = request.get.data() # not too sure what to do here either.
return data
else:
return "error" # goes to 'return error'
I am trying to send a message from one worker to the other (and then respond back through a SharedArrayBuffer). But I can’t find any information on posting a message to another worker from within a worker. How would I go about doing it? (I tried posting the worker itself as a message, but it doesn’t work).
Here is my code:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type='text/javascript'>
var s_curFile;
var s_curFile2;
var s_SAB = new SharedArrayBuffer(65563);
var u8buf = new Uint8Array(s_SAB);
function JSprocessFilePicker( input )
{
let url = input.value;
let ext = url.substring( url.lastIndexOf( '.' ) + 1 ).toLowerCase();
if ( input.files && input.files[0] && ( ext == "txt" ) )
{
s_curFile = input.files[0];
try {
fileWorker.postMessage({
'cmd' : 'file',
'file' : s_curFile
});
} catch(e) {
alert('Can't spawn files to worker - '+e)
}
try {
worker.postMessage({
'cmd' : 'run'
});
} catch(e) {
alert('Can't spawn files to worker - '+e)
}
}
}
u8buf[0] = 0;
var worker = new Worker('worker.js');
var fileWorker = new Worker('fileWorker.js');
try {
worker.postMessage({
'cmd' : 'SAB',
'sab' : s_SAB
}, fileWorker);
} catch(e) {
alert('Can't send Shared Array Buffer to worker - '+e);
}
try {
fileWorker.postMessage({
'cmd' : 'SAB',
'sab' : s_SAB
});
} catch(e) {
alert('Can't send Shared Array Buffer to worker - '+e);
}
var input = document.createElement( "input" );
input.setAttribute( "id", "file_picker" );
input.setAttribute( "type", "file" );
input.setAttribute( "accept", ".fzp" );
input.setAttribute( "onchange", "JSprocessFilePicker(this)" );
</script>
<button onclick="input.click();">Open</button>
</body>
</html>
worker.js:
var s_SAB;
var u8buf;
var fileWorker;
self.onmessage = function(e) {
if( e.data.cmd === 'SAB' )
{
s_SAB = e.data.sab;
u8buf = new Uint8Array(s_SAB);
fileWorker = e.data.fileWorker;
console.log(s_SAB);
console.log(fileWorker);
}
else if( e.data.cmd === 'run' )
{
try {
fileWorker.postMessage({
'cmd' : 'load'
});
} catch(e) {
console.log('Can't post message from web worker - '+e); //I GET AN ERROR HERE
}
while(u8buf[0] === 0)
{
//This loop here I am doing heavy processing, that i cannot change really
console.log("worker waiting for file...n");
}
console.log("worker got data!n");
let Idx;
for (Idx = 0; Idx < 20; ++Idx) {
console.log(u8buf[Idx+1]);
}
}
fileWorker.js
var s_curFile;
var s_SAB;
var u8buf;
let xhrReq = new XMLHttpRequest();
xhrReq.overrideMimeType('text/plain; charset=x-user-defined');
self.onmessage = function(e) {
if( e.data.cmd === 'file' )
{
s_curFile = e.data.file;
console.log("got file!");
}
else if( e.data.cmd === 'SAB' )
{
s_SAB = e.data.sab;
u8buf = new Uint8Array(s_SAB);
console.log(s_SAB);
}
else if( e.data.cmd === 'load' )
{
let uri = URL.createObjectURL(s_curFile.slice(40, 100));
xhrReq.open('GET', uri, true);
xhrReq.send(null);
URL.revokeObjectURL(uri);
let Idx;
let sz = xhrReq.response.length;
console.log("Response Size: "+sz);
for (Idx = 0; Idx < sz; ++Idx) {
u8buf[Idx+1] = xhrReq.response.charCodeAt(Idx);
}
u8buf[0] = 1;
}
}
I have website with backend in Python (Django) and JavaScript hosted on heroku.
I want to use an external code that is working on Google Colab, this code uses CNN to do image classification. My idea is that user upload an image through the website then the code that is written in python in Google Colab does the classification and returns the result to the website.
Does anyone know what would be the best way to do this?
I want to show letters only in uppercase in input text field.
<oj-input-text style="text-transform: uppercase;" id="text-input" placeholder="Select new Item number"
value="{{newItemNumber}}"></oj-input-text>
I have tried adding css “text-transform: uppercase” property to the element but that did not work. I also wrapped the element in a span and added css property but of no use. I want the input field to convert and show all input letters to uppercase as the user types. Is there a way to do it in ojet?
// Update the other user that current user has asked for revision
export async function updateOtherUserForContractRevision(contractID : string, comments : any) {
// getting userDetails
let currentUser : string | any = localStorage.getItem("userDetails");
currentUser = JSON.parse(currentUser);
// update fields in contractRecieved
const contractsRecievedRef : any = doc(db, "contractsRecieved", currentUser.uid);
// const queryContractsRecieved = query(contractsRecievedRef,
// where('contractDetails.contract.contractID','array-contains',contractID)
// );
// console.log(".////////updateOtherUserForContractRevision", queryContractsRecieved ,contractID)
onSnapshot(contractsRecievedRef, (doc: any) => {
doc.data().contract.map((contract: any) => {
if(contract.contractDetails.contract.contractID === contractID) {
// I reach my desired array Index and want to update the msg field to my comments parametre
console.log(".////////contract", contract);
}
})
})
}
I want to update my msg field as well as content field in contract object. I have search and reached to my desired array value using onSnapShot, how can I update these fields in the onSnapShot method ? or I should use another approach for searching and updating fields in objects contained by arrays.
var request = require('request');
var d;
request('my.servers.ip?group=1', function (error, response, body) {
let d = body
})
console.log(d)
This is my code currently, it says the variable d is undefined and I’m not sure why.
Anyone have ideas on why it might be?
Say we have a function like this:
const getUserId = (req) => {
if(!req.user){
throw 'no user'
}
if(!req.user.id){
throw 'no user id'
}
return req.user.id;
}
and say we use it in a block of code where we don’t want to experience a thrown error:
const logUserId = (req) => {
const userId = getUserId(req); // this might throw
console.log(userId);
}
so we could do this:
const logUserId = (req) => {
try{
const userId = getUserId(req); // this might throw
console.log(userId);
}
catch (err) {
console.error(err);
}
}
but I am wondering if there is a pattern to capture it earlier, like this:
const catchWrapper = (fn) => {
try {
return [null, fn()];
}
catch(err){
return [err]
}
}
const logUserId = (req) => {
const [err, userId] = catchWrapper(() => getUserId(req));
console.log(userId);
}
does this pattern make any sense
var menu = document.querySelectorAll('.chap_below');
var last = menu[menu.length- 1];
var div = document.createElement('li');
div.classList.add("chap_below");
var div_ch = document.createElement('SPAN');
div_ch.classList.add("chbx");
div_ch.appendChild(div);
last.parentNode.insertBefore(div, last.nextSibling);
I want to add div_ch as a siblings to div element but it’s not going as planned and I have no idea why would be appreciated if anyone could help.
I currently have a grouped bar chart being drawn with this code:
bars = barCanvas.selectAll(".bar-group") .data(data).enter().append("g")
.attr("class", "bar-group")
.attr("transform",function(d) { return "translate(" + xGroup(d.group) + ",0)"; })
.selectAll("rect")
.data(function(d) { return stacks.map(function(stack) { return {key: stack.stack, value: d[stack.stack], group: d.group, groupField: d.groupField, field: stack.value}; }); })
.enter().append("rect")
.on("mouseover", highlight)
.on("mouseout", unhighlight)
.on("mousemove", positionTooltip)
.style("cursor", function() {
if (c.chartOptions.clickable == true || c.chartOptions.clickable == 'true') {
return "pointer";
}
else {
return '';
}
})
.on("click", function(d) {
if (c.chartOptions.clickable == true || c.chartOptions.clickable == 'true') {
return openList(d);
}
else {
return '';
}
})
.attr("class", "little-bar")
.attr("width", xStack.bandwidth())
.attr("x", function(d) {return xStack(d.key); })
.style("fill", function(d) { return getColor(d.key) })
.attr("y", height)
.attr("height", 0)
.transition().delay(function() {
if (barsEntered)
return 500;
else
return 0;
})
.duration(500)
.attr("y", function(d) { return y(d.value); })
.attr("height", function(d) { return height - y(d.value); });`
The chart is working perfectly, but I am having no luck when trying to add labels to the top of each bar. I’ve attempted to position the labels very similar to how the individual bars are positioned but have had no luck in getting them to display so far.
I have an ag-grid that contains different columns and column groups, as well as row groups.
I am trying to test the DOM elements displayed in the row group using Jest and Angular Testing Library. The problem I am having is that the DOM renderer for the test does not detect any children of that row and only shows it as a self-enclosed DIV tag with no childer. But when I check it on the web browser I can see all the group rows and the nested rows within them.
I initially thought it was due to the row virtualization, but I have set the rowBuffer to 99999 and the cell fails to render anything but an empty DIV still.
What could be the issue? all the other cells and columns are rendering correctly, but the cell that contains a row group fails to render anything.
How do I check if this is true (no data from the rest api) so I can respond to the client to a error massege? I tried using this but nothing happends.. enter image description here
This is the code I fetch my api: enter image description here
I’m working on a Chrome extension and have a set of js files imported in the extension’s popup in <script defer src="../utils/X.js"></script> tags.
The folder structure looks like
src/
utils/
parser.js
functions.js
other.js
popup/
popup.js
popup.html
popup.js uses functions from files in utils/ and the files in utils/ use each other’s functions.
All was going well and I could navigate to function definitions with cmd+click
As I integrated tests, and to be able to test my functions in a node environment (mocha) I added the following at the bottom of my util files:
if (typeof module !== "undefined" && module.exports != null) {
module.exports = {
log,
...
};
}
And that breaks VSCode’s ability to Go to Definition, not sure why or how to fix it.
For reference, here’s my jsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
},
"include": [
"src/**/*.js"
]
}
I have very simple component template:
<button (click)="emitNextValue()">Next Value</button>
<p *ngIf="text$ | async">
{{ text$ | async }}
</p>
and component code:
export class AppComponent {
count = 1;
text$ = new Subject<string>();
emitNextValue(): void {
this.text$.next(`Value ${this.count}`);
this.count += 1;
}
}
As you can see, the <p> in the template should be displayed only if text$ Subjects emit value. Clicking the “Next Value” button will call next on the subject and thus should show the paragraph.
The problem is that <p> is displayed only on the second click, which I think is incorrect.
Any idea what I am missing, or this is actual bug?
Demo is available on stackblitz.