Posts by LeandroLuk • 4,989 points
276 posts
-
-1
votes0
answers10
viewsQ: How to create a Trigger for an Intex in Elasticsearch to save the previous state before an update
Hello, I’m creating a solution that will use Elasticsearch as a non-relational database. In the solution I want to control the history of a document as in the example below (this example is not…
-
1
votes1
answer20
viewsQ: How to return a list of specific fields in an Aggregation in Mongodb
Hello I am creating a generic query according to the code below: // dados de exemplo em uma coleção "test" do mongodb const test = [ { "name": "foo", age: 2 }, { "name": "bar", age: 16 }, { "name":…
-
1
votes0
answers23
viewsQ: How to test a "await import" with Jest in Typescript
I have an api that in the file that imports the routes to then link them to the express app I use fast-glob to search for files with the extension *.route.ts and then import these methods, like…
-
0
votes0
answers30
viewsQ: How to test a 500 status with Jest in Expressjs
I have an application where I am trying to create a simple test to improve code coverage. I currently have a route that returns a health check, like this: import { Express, Request, Response, Router…
-
1
votes1
answer104
viewsQ: How to Force Prettier to Always Put a Multilevel Ternary
I am creating an application using Vscode as IDE and, to do the lint of the code, I’m using the Eslint and the GTS (Google Typescript Style) where in a code location I have something similar to…
-
0
votes0
answers21
viewsQ: How to force jest not to run tests on interfaces in Typescript
Hello, I have a project built in Typescript and in it I am using Jest (ts-jest) to do the tests. While running jest with the command --coverage realized that it is passing over lines of code that…
-
-1
votes1
answer86
viewsQ: How to mock a constant object in Jest
Hello I have got a constant file set like this in an React project: src/constants/env.ts export default { PROD: ['prod', 'production'].includes((process.env.NODE_ENV || '').toLowerCase()) } This…
-
0
votes0
answers13
viewsQ: How to mock part of a context in React
Hello I have the following context: import React from 'react' const AuthContext = React.createContext({ isAuth: false, login: f => f, logoff: f => f }) const AuthProvider = ({ children })…
jestasked LeandroLuk 4,989 -
8
votes1
answer147
viewsQ: How to use a predefined interpolation in Javascript
I was reading in ES6 documentation about interpolation (or Template strings) and saw that I can create "escaped templates", as in the example below: class InvalidParamError extends Error { static…
-
2
votes2
answers184
viewsQ: How to make a window.scrollTo(0.0) without animation
I have an React application that in certain situations (because of the React-router) I should scroll to the top of the page. The problem is that in most cases the scroll should be animated and in…
-
0
votes1
answer51
viewsQ: How to change the pre-name of classes generated by Material UI
Hello, I am creating a project that uses Material UI and I realize that when I compile it generates the classes in production of JSS ex: I’m used to working using css modules together with the…
-
1
votes1
answer139
viewsQ: To configure the resolution of modules in the tsconfig.json file to use the ts-Node library in Typescript
Hello, I am creating an API in typescript and the structure of my project is as follows:: api | - src | - index.ts | - server.ts | - package.json | - tsconfig.json Within api/src/server.ts I have a…
-
0
votes0
answers29
viewsQ: how to get the result of multi processes in a list in Python3
I am creating a robot that at a given time needs to make multiple HTTP requests at the same time and, return the result in a list. The code so far is like this: import requests import simplejson…
python-3.xasked LeandroLuk 4,989 -
2
votes1
answer482
viewsQ: How to take the class name inside a python method
I am creating a base class that keeps some common methods for daughter classes in Python3: import abc class Bot(abc.ABC): def log(self, message): bot = self.__name__ version =…
python-3.xasked LeandroLuk 4,989 -
3
votes2
answers279
viewsA: How to divide strings into equal parts
What you’re looking for is the function that was declared here: https://stackoverflow.com/questions/7033639/split-large-string-in-n-size-chunks-in-javascript function chunkString(str, length) {…
-
1
votes1
answer80
viewsA: To return the result of a query in Influxdb with the "time" column as number
Soon after posting the question I found the solution in the documentation. According to her, I can pass the parameter "epoch=ns" so that the column "time" is not formatted, like this:…
-
0
votes1
answer80
viewsQ: To return the result of a query in Influxdb with the "time" column as number
I am doing tests in Influxdb (inside a Docker container) and for that I ran the code below: # criando a imagem do influxdb docker run -d --name influxdb -p 8086:8086 influxdb # acessando o terminal…
-
-6
votes3
answers177
viewsQ: How to initialize a constant with the value of time. Now() in Golang?
I’m used to doing projects in Python where, when initializing the same I keep a variable saying when it started (to measure the execution time of the project) like this: import time started_at =…
-
4
votes2
answers389
viewsA: How to return the number of elements of a document property in a collection in Mongodb
I found the solution below: db.test.aggregate([ {$match: {checked: true}}, {$project: {size: {$size : "$styles"}}}, {$group: {_id: null, total: {$sum: "$size"}}} ])…
mongodbanswered LeandroLuk 4,989 -
3
votes2
answers389
viewsQ: How to return the number of elements of a document property in a collection in Mongodb
Hello, I have a collection that has the documents with the format below: { "_id" : ObjectId("..."), "checked": true, "styles": ["foo", "bar", "bin"] } I need to add the array size styles for all…
mongodbasked LeandroLuk 4,989 -
2
votes2
answers47
viewsQ: How to access the data in a variable of type double[ , ] in C#
I’m studying C# and in a certain code I came across the following situation: double[,,] R = new double[_StatesMaxCount, 3, 2]; In all the time I’ve been studying, I’ve never seen this kind of…
-
0
votes1
answer149
viewsA: How to detect navigation using the Webbrowser class and capture information with C#
To solve my problem I had to reformulate my application so that it behaved like a webaplication and my application could make use of all the resources of solutions on the web because after ML…
-
1
votes1
answer62
viewsQ: How to create extension methods in Kotlin
Hello, I’m coming from C# to work with Kotlin and C# when there was any code that was used constantly, it was common to create extension methods that worked as shortcuts to it. Ex: namespace Test {…
-
1
votes1
answer84
viewsQ: How to get the default value of a type in Kotlin?
I’m coming from C# and starting working with Kotlin (Android). In C#, if I want the default expected value for a type I should call it as in the example below: class Foo {} class Main { public…
-
1
votes2
answers248
viewsQ: How to return values of a daughter Activity in Kotlin
Hello, I’m starting to work with Kotlin and I have the following situation: I have the Activity Foo with a button that navigates to Activity Bar. In Bar, I process some information and have a button…
-
0
votes1
answer112
viewsQ: How to import existing Packages into the same directory in a Nodejs application
Hello, I am creating a solution that has been distributed across multiple projects and that contains resources shared with each other. My solution is developed in general in Nodejs along with other…
node.jsasked LeandroLuk 4,989 -
1
votes1
answer513
viewsQ: How to create a hash using the hashlib library using the "time.time()" method in Python3
Hello, I have the following situation: I have to create a hexdigest of a concatenation of 2 numbers transformed into a string. For this, I must use the library hashlib and the project must be in…
-
4
votes1
answer799
viewsQ: How to export classes, methods or constants in a Python module
Hello, I’m starting to work with Python and have a good experience with Typescript. In Typescript, I have a habit of creating modules when I need to organize my code, so: <rootDir> domain…
-
2
votes1
answer289
viewsQ: How to configure Vscode to identify private field syntax
I’m testing new JS features, but my Vscode can’t detect that the project uses the new private field syntax. The code is like this: entities.js class Person { constructor(p = {}) { if(p)…
visual-studio-codeasked LeandroLuk 4,989 -
0
votes2
answers407
viewsA: How to fire a Redux Action without a React
I was able to solve my problem by placing the interceptors declaration in a function that receives the store, so I can call this creation of the interceptors right after the store index.js thus:…
-
2
votes2
answers407
viewsQ: How to fire a Redux Action without a React
Hi, I’m creating a Interceptor to the Xios which, if my Answer case there is an error with the status Forbidden (403) the same need to trigger the Action that starts the user’s logoff to force him…
-
-1
votes1
answer33
viewsQ: How to use Linq in 2 lists so that one complements the other in C#
Hello, I have the following situation: public class Foo { int id { get; set; } Bar bar { get; set; } } public class Bar { int id { get; set; } int FooId { get; set; } } public class Program { public…
-
1
votes2
answers48
viewsQ: How to create a new object containing all the values of an initial object but adding new attributes in C#
Hello, I have a question regarding C# and the optimization of the form of code generation. In Typescript, if I have the code below I can create a new object from a previous one and, in the creation…
-
1
votes0
answers57
viewsQ: How to track the scroll event of an element (not the window) using a directive in Angular (v2+)
Hello, I’m creating a screen with this structure: <div class="wrapper"> <div class="appbar"> ... </div> <div class="main" #main> <router-outlet></router-outlet>…
-
0
votes1
answer36
viewsQ: How to access the array in an extended Javascript function
Hello, I’m doing a class extension Array where I want to create a method that checks whether a property exists within the Array: thus: Array.prototype.contains = function(element){ for(let e of…
-
1
votes1
answer82
viewsQ: How to declare an extended type in Typescript
Hello, I have the following situation: // essa classe contém apenas 2 propriedades interface Foo { a: string; b: number; } // em determinada situação, eu preciso declarar // a interface junto com…
typescriptasked LeandroLuk 4,989 -
3
votes1
answer104
viewsQ: How to create an Object in a Linq.Expressions.Expression and add properties dynamically to it in C#
Hi, I’m creating a library of DataAnnotations to extend Entityframeworkcore with structures that today only exist using Fluentapi. In one of them, I’m trying to recreate this block of Fluentapi:…
-
0
votes1
answer149
viewsQ: How to detect navigation using the Webbrowser class and capture information with C#
Hello, I’m doing an integration with the Free Market API, where I need to open a browser screen with the page for the user to allow access to my application’s API (as the documentation here). To do…
-
1
votes1
answer62
viewsQ: How to force an event to occur from an extension method?
I am creating a C# application and I am using the interface INotifyPropertyChanged thus: public class Test: INotifyPropertyChanged { private int foo; public int Foo { get => foo; set =>…
-
2
votes1
answer45
viewsQ: How to sum the first 2 occurrences of a column using a key as reference in Sqlserver
Hello, I have the following table: create table events ( type int not null, value int not null, time datetime unique(type, time) ); Where in the same I have the following records:…
-
1
votes2
answers94
viewsA: What is the best way to add a static method to an existing class in C#?
My solution was to create the method I wanted as an extension of the class and with another name, so: public static class Extensions { public static JObject FromObjectCompressed(this JObject…
-
-1
votes2
answers94
viewsQ: What is the best way to add a static method to an existing class in C#?
I’m creating an app restfull using the library Newtonsoft to send information through controllers. In my application, I have numerous classes such as user: public class UsuarioModel { public int Id…
-
1
votes1
answer122
viewsQ: How to define a color using the <Color/> element of Xamarin Forms within a Resourcedictionary
Hello, I’m following you this tutorial and, starting from what it shows along with the Xamarin.Forms documentation, I can create a Resource Dictionary as follows: <?xml version="1.0"…
-
1
votes2
answers413
viewsA: How to detect the hardwareBackPress event with React Native when you have an open Modal
After read that issue of own react-navigation, found that Modal blocks access to hardwareBackPress. So I had to take and transform my Modal into an absolute component and make this change manually.…
react-nativeanswered LeandroLuk 4,989 -
0
votes2
answers413
viewsQ: How to detect the hardwareBackPress event with React Native when you have an open Modal
Hello, there is 1 week that I am trying to find this problem and I can not solve... I have an application that at a certain time opens a modal that overlaps the main screen. Here are my codes...…
react-nativeasked LeandroLuk 4,989 -
0
votes1
answer603
viewsQ: How to get the status of a React within a React Native
Hello, I’m new to React Native and I’m having problems to pass the status of a Reducer to a component I made. the same is as follows: import React from 'react' import { connect } from 'react-redux'…
-
1
votes1
answer2028
viewsA: How to prevent an React Native application from returning by clicking on the Backbutton using React Navigation
Based on what @sant0will said in the answers, I was able to "solve" the problem by adding on all screens a specific treatment for Backhandler, thus: export default SplashScreen extends…
-
2
votes2
answers193
viewsA: Column that fills the screen according to width
Hello, this type of screen is called Feature Screen and usually do not have a content that exceeds the size of the screen itself. To make a screen like this you can use the structure below: * {…
cssanswered LeandroLuk 4,989 -
0
votes1
answer2028
viewsQ: How to prevent an React Native application from returning by clicking on the Backbutton using React Navigation
Hello, I am creating an application in React Native, and for the browsing I have been working with the plugin React Navigation. The structure of my project is like this: import React from 'react';…
-
5
votes1
answer66
viewsQ: How to return a Promise from an Angularfireobject using @angular/fire in Angular(V6+)
Hello, I’m working on a project in Angular where I need to return a Promisein a particular service. My code is like this: import { Injectable } from '@angular/core'; import { AngularFireDatabase }…