addEventListener giving error in typescript Posted: 09 Sep 2021 07:49 AM PDT const [locked,setLocked]=useState("pending"); const unlockHandler = (e: string) => { setLocked(e); } useEffect(() => { window.addEventListener("unlockProtocol", unlockHandler); return () => window.removeEventListener("unlockProtocol", unlockHandler); },[]); window.addEventListener("unlockProtocol", unlockHandler) gives error as Type '(e: string) => void' is not assignable to type 'EventListener'. |
Excel VBA - Open workbook, if not already opened, using wildcard or partial name match Posted: 09 Sep 2021 07:48 AM PDT I would like to open a workbook, if it is not already opened, using a wildcard of its name. The only constant name components in the workbook's name are "Report Due". Here are the codes I have tried so far: On Error Resume Next Dim MyWorkbook As Workbook Set MyWorkbook = Workbooks("Report Due*.xlsx") If Err <> 0 Then On Error GoTo 0 Workbooks.Open ("Report Due*.xlsx") End If AND Dim MyFileName As Variant Dim myFolderPath As String myFolderPath = Application.DefaultFilePath MyFileName = Dir(myFolderPath & "Report Due*.xlsx") If MyFileName <> "" Then Workbooks.Open (myFolderPath & MyFileName) End If Both sequences of codes don't seem to be working as there is an Error 1004: Sorry, we couldn't find "Report Due*.xlsx" Many thanks! |
Ruby can't find local function definition in separate file Posted: 09 Sep 2021 07:48 AM PDT I have separated out my seeds into separate files like in db/seeds/foo.rb . In there I have a function defined: def foo puts "here" end Then in the main db/seeds.rb file, I do: load File.join(Rails.root, 'db', 'seeds/foo.rb') foo But it says foo is undefined. How do I get this to work? |
Mongodb LookUp Poor Performans Posted: 09 Sep 2021 07:48 AM PDT var product = db.GetCollection("Product"); var lookup1 = new BsonDocument("$lookup", new BsonDocument { { "from", "Variant" }, { "localField", "Maincode" }, { "foreignField", "Maincode" }, { "as", "variants" } }); var pipeline = new[] { lookup1 }; var result = product.Aggregate(pipeline).ToList(); The data of collection a is very large so it takes me 30 seconds to put the data in the list. What should I do to make a faster lookup? |
How to change icon and text color when icon is `class="p-accordion-toggle-icon ng-tns-c31-4 pi pi-fw pi-minus"` Posted: 09 Sep 2021 07:48 AM PDT please can you help me, how to change icon and text color when I have class="p-accordion-toggle-icon ng-tns-c31-4 pi pi-fw pi-minus" not class="p-accordion-toggle-icon ng-tns-c31-4 pi pi-fw pi-plus" image I try something like that but I want to change color only when icon is pi-minus ::ng-deep { &[aria-expanded='true'] > span { color:red; } } |
is better written in dot notation - eslint Posted: 09 Sep 2021 07:48 AM PDT I have an API response like so { "sents": [ { "day": "2021-08-01", "alerts": 4708, "leads": 500 }, { "day": "2021-08-02", "alerts": 5708, "leads": 389 }, ], "leadStatuses": [ { "status": "No Work", "count": 645 }, { "status": "Follow up", "count": 26 } ], "categories": [ { "category": "Fire", "alerts": 4708, "leads": 140 }, { "category": "Water", "alerts": 9445, "leads": 234 } ] } When I try to access response like so: const sents = pick(res, ['sent']); const sentArray = sents['sent']; //["sent"] is better written in dot notation.eslint So how can I instruct my API developer to comply with this rule without disabling this on the Frontend app? |
FileProvider skipping files while reading from local storage Posted: 09 Sep 2021 07:48 AM PDT I have a method which read files from a particular folder from my phone. I want to share those files via Gmail or other services. It works most of the time but sometime few files are not attached. I have tried so many ways but did not solve this issue yet. I will appreciate if anyone can help me out. Thanks in advance. Here is the code sample. try { File root = Environment.getExternalStorageDirectory(); File directory = new File(root.getAbsolutePath() + LOG_WRITE_FILE_PATH); File[] files = directory.listFiles(); attachments.clear(); if (files != null && files.length > 0) { Log.e("Report:", "-------------for loop start--------"); for (File value : files) { File file = new File(directory, value.getName()); Log.e("Report:", value.getName()); Uri uri = FileProvider.getUriForFile(getContext(), "mypackage_name.provider", file); //grant permision for app with package "packegeName", eg. before starting other app via intent getContext().grantUriPermission(getContext().getPackageName(), uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); //revoke permisions getContext().revokeUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); attachments.add(uri); } Log.e("Report:", "-------------for loop end--------"); } } catch (Exception e) { Log.e("Report:", e.getMessage()); } Here is the code that I added in AndroidManifest file <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <provider android:name="androidx.core.content.FileProvider" android:authorities="bd.com.cmed.pksf.provider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> </provider> Path provider file <paths> <external-path name="external_files" path="."/> </paths> Here is the log that I have got. E/Report:: -------------for loop start-------- E/Report:: member_add.json E/Report:: referral_add.json E/Report:: -------------for loop end-------- E/Report:: -------------for loop start-------- E/Report:: member_add.json E/Report:: referral_add.json E/Report:: -------------for loop end-------- E/Report:: -------------for loop start-------- E/Report:: referral_add.json E/Report:: -------------for loop end-------- E/Report:: -------------for loop start-------- E/Report:: referral_add.json E/Report:: -------------for loop end-------- E/Report:: -------------for loop start-------- E/Report:: member_add.json E/Report:: referral_add.json E/Report:: -------------for loop end-------- |
EF Core - Producing unfiltered queries on all members of dbcontext Posted: 09 Sep 2021 07:48 AM PDT I'm writing this here, in the hope that someone has experienced this before and has a thorough answer to this problem. We have a C# Web API that handles CRUD operations where we are using EF Core as our ORM to manipulate data. From inspecting the SQL logs we can see that there are many select statements that are unfiltered (no where clause). That don't seem to be coming from the code base. What is strange about this is some of the tables that are being called have no other references in the code other than being on the DBContext itself. For example. public class MyContext : DbContext{ public DbSet<MyDbSet> MyDBSet { get; set; } } This seems to periodically output a select statement on the table even if its not used in the code. SELECT [m].[Id], [m].[Column1], [m].[Column2] FROM [MyDBSet] AS [m] The problem with this is, that some of these tables have large amounts of data in which I would like to avoid an unfiltered query. From further inspection it seems that the order in which these unfiltered queries occur is the same order they are found on the DBContext. Example 2 public class MyContext : DbContext{ public DbSet<MyDbSet> MyDBSet { get; set; } public DbSet<MyDbSet2> MyDBSet2 { get; set; } public DbSet<MyDbSet3> MyDBSet3 { get; set; } } SELECT [m].[Id], [m].[Column1], [m].[Column2] FROM [MyDBSet] AS [m] SELECT [m].[Id], [m].[Column1], [m].[Column2] FROM [MyDBSet2] AS [m] SELECT [m].[Id], [m].[Column1], [m].[Column2] FROM [MyDBSet3] AS [m] This happens even when the table is not read or referenced in the codebase, and there are no references to these tables that don't have a where clause. My first assumption is that EF core is taking a snapshot of the table? Perhaps query caching or something similar? I guess my question is, does anyone know what could be causing such odd behaviour and or is there something in EF core that is responsible. NOTE - We are not using Lazy Loading Proxies package and are using eager loading throughout the application |
I need help in solving this problem statement using java language, as I am a beginner I'm finding it difficult to code :) Posted: 09 Sep 2021 07:48 AM PDT Take two numbers n1 and n2 as input from command line argument. - Find prime numbers between n1 and n2, then
- Find smallest (a) and largest (b) number from the generated list, also count of this list.
- Consider smallest and largest number as the 1st and 2nd number to generate Fibonacci series respectively till the count (number of primes in the list).
- Print the last number of a Fibonacci series as an output
Constraints 2 <= n1, n2<= 100 n2 - n1 >= 35 Input Format Two integers n1 and n2. Output Last number of a generated Fibonacci series. |
VBA On opening file check todays date is same as 1st day of the current Month and whether a cell range value is greater then 30 then run the rest Posted: 09 Sep 2021 07:48 AM PDT I would like the following to run if todays date equals the first the of the current month and if a cell value is greater than 30. I am not sure where I am going wrong. Please Help copySheet.Unprotect copySheet.Range("AB2").Copy Sheets("Counter").Visible = True pasteSheet.Unprotect Sheets("Counter").Select Range("D1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False pasteSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("Counter").Visible = False copySheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("Sheet1").Select Range("B5").Select Bellow what complete. Private Sub Workbook_Open() Dim copySheet As Worksheet Dim pasteSheet As Worksheet Dim LastCounterVal As Range Dim FirstDay As Date Dim Today As Date Dim pDate As Date Set copySheet = Worksheets("Sheet1") Set pasteSheet = Worksheets("Counter") Set LastCounterVal = Worksheets("Counter").Range("D1") FirstDay = DateSerial(Year(pDate), Month(pDate), 1) Today = Date If FirstDay = Today And LastCounterVal > 30 Then copySheet.Unprotect copySheet.Range("AB2").Copy Sheets("Counter").Visible = True pasteSheet.Unprotect Sheets("Counter").Select Range("D1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False pasteSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("Counter").Visible = False copySheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True Sheets("Sheet1").Select Range("B5").Select Else Sheets("Sheet1").Select Range("B5").Select End If End Sub |
How to allow python file to export specific functions that can be imported later? [duplicate] Posted: 09 Sep 2021 07:48 AM PDT Suppose I have 2 functions and one global variable in a python file. How do I allow to export only one function? g = 47 def A(): print('a') def B(): print('b') Suppose the above file is named as try.py. I want to restrict all imports from try module except function A. |
How to use autoclick button once? [duplicate] Posted: 09 Sep 2021 07:48 AM PDT I tried to use my button to be clicked automatically for once. <form method="post"> <button id="modal1" type="submit" name="filter" value="filter" class="btn btn-info btn-sm" > <i class="ace-icon fa fa-search bigger-110"></i><?=display('filtering');?> </button> </form> I used this feature to know when my button was clicked And if the case the stop variable takes 1. <?php if (isset($_POST['filter'])){ $stop=1; } ?> here I have my code for my button to be clicked automatically <script> $stop=0; if($stop===0){ jQuery(function(){ jQuery('#modal1').trigger('click'); }); } </script> do you have any suggestions? |
Replace empty string with null values in RDD Posted: 09 Sep 2021 07:49 AM PDT Hello i would like to convert empty string to 0 of my RDD. I have read 20 files and they are in like this formation. YEAR,MONTH,DAY,DAY_OF_WEEK,AIRLINE,FLIGHT_NUMBER,TAIL_NUMBER,ORIGIN_AIRPORT,DESTINATION_AIRPORT,SCHEDULED_DEPARTURE,DEPARTURE_TIME,DEPARTURE_DELAY,TAXI_OUT,WHEELS_OFF,SCHEDULED_TIME,ELAPSED_TIME,AIR_TIME,DISTANCE,WHEELS_ON,TAXI_IN,SCHEDULED_ARRIVAL,ARRIVAL_TIME,ARRIVAL_DELAY,DIVERTED,CANCELLED,CANCELLATION_REASON,AIR_SYSTEM_DELAY,SECURITY_DELAY,AIRLINE_DELAY,LATE_AIRCRAFT_DELAY,WEATHER_DELAY 2015,2,6,5,OO,6271,N937SW,FAR,DEN,1712,1701,-11,15,1716,123,117,95,627,1751,7,1815,1758,-17,0,0,,,,,, 2015,1,19,1,AA,1605,N496AA,DFW,ONT,1740,1744,4,15,1759,193,198,175,1188,1854,8,1853,1902,9,0,0,,,,,, 2015,3,8,7,NK,1068,N519NK,LAS,CLE,2220,2210,-10,12,2222,238,229,208,1824,450,9,518,459,-19,0,0,,,,,, 2015,9,21,1,AA,1094,N3EDAA,DFW,BOS,1155,1155,0,12,1207,223,206,190,1562,1617,4,1638,1621,-17,0,0,,,,,, i would like to fill these empty strings with the number 0 to them def import_parse_rdd(data): # create rdd rdd = sc.textFile(data) # remove the header header = rdd.first() rdd = rdd.filter(lambda row: row != header) #filter out header # split by comma split_rdd = rdd.map(lambda line: line.split(',')) row_rdd = split_rdd.map(lambda line: Row( YEAR = int(line[0]),MONTH = int(line[1]),DAY = int(line[2]),DAY_OF_WEEK = int(line[3]) ,AIRLINE = line[4],FLIGHT_NUMBER = int(line[5]), TAIL_NUMBER = line[6],ORIGIN_AIRPORT = line[7],DESTINATION_AIRPORT = line[8], SCHEDULED_DEPARTURE = line[9],DEPARTURE_TIME = line[10],DEPARTURE_DELAY = (line[11]),TAXI_OUT = (line[12]), WHEELS_OFF = line[13],SCHEDULED_TIME = line[14],ELAPSED_TIME = (line[15]),AIR_TIME = (line[16]),DISTANCE = (line[17]),WHEELS_ON = line[18],TAXI_IN = (line[19]), SCHEDULED_ARRIVAL = line[20],ARRIVAL_TIME = line[21],ARRIVAL_DELAY = line[22],DIVERTED = line[23],CANCELLED = line[24],CANCELLATION_REASON = line[25],AIR_SYSTEM_DELAY = line[26], SECURITY_DELAY = line[27],AIRLINE_DELAY = line[28],LATE_AIRCRAFT_DELAY = line[29],WEATHER_DELAY = line[30]) ) return row_rdd the above is the code i am running |
SQL join one field to two others without duplication Posted: 09 Sep 2021 07:48 AM PDT I am using postgresql to pick out the asset data and location data of (dummy) and join with any devices linked to the device_uuid by foregin (dummy1 and dummy2) key as proof of concept The tables I have look like below: SELECT * FROM dummy; asset_metadata | location_data | device_uuid | asset_1 | location1 | 123456 | asset_2 | location2 | 789 | SELECT * FROM dummy1; device_uuid | metadata | 123456 | test | 789 | test | SELECT * FROM dummy2; device_uuid | metadata | 123456 | test | 789 | test | Ideally, I'd like to combine the asset data on a single row and extend it with two device entries after it like so: asset_metadata | location_data | device_uuid | metadata | device_uuid | metadata | asset_1 | location1 | 123456 | test | 123456 | test | Can anyone advise how to do this? As at the moment because there are 2 devices associated to asset_1 I am getting a a row for each with all the asset data + location data duplicated in the next row I am running the query SELECT * FROM dummy a LEFT JOIN dummy1 c ON a.device_uuid = c.device_uuid LEFT JOIN dummy2 d ON d.device_uuid = a.device_uuid WHERE d.device_uuid = '123456'; and getting the same result duplicated 4 times |
Inserting an object into an array field and only return the inserted object Posted: 09 Sep 2021 07:48 AM PDT I have the document below, and I wanted to add an object in the matches array and return only it and not the entire document, is it possible to do this with MongoDB? { "_id": "25113", "title": "Jogo de futebol", "rounds": { "matches": [{ "firstParticipant": { "address": "789", "battlesWon": 0 }, "secondParticipant": { "address": "748569874", "battlesWon": 0 } }, { "firstParticipant": { "address": "963", "battlesWon": 0 }, "secondParticipant": { "address": "741", "battlesWon": 0 } }, { "firstParticipant": { "address": "258", "battlesWon": 0 }, "secondParticipant": { "address": "789", "battlesWon": 0 } } ] } } My code: const player = { firstParticipant: { address: '789', battlesWon: 0, }, secondParticipant: { address: '748569874', battlesWon: 0, }, }; const result = await this.tournamentModel.findOneAndUpdate( { _id: '25113', status: 'OPEN', }, { $addToSet: { 'rounds.matches': player } }, { returnOriginal: false }, ); the problem is that the result returns the entire document and not just the object added to the array. |
Loading multiple data objects from backend API - all at once or every data object in its own call? Posted: 09 Sep 2021 07:48 AM PDT Lets say i have a form that i use to edit a Customer. In addition to various input fields it will also have multiple drop down lists to set some fields (eg. Country, Category, Status...). Every drop down list will need a seperate lists that i need to get from the backend to populate. That means that if i want to edit a customer with my form, i need to load: - The Customer Object which will be edited
- A list of countries
- A list of categories
- A list of different stattus types
- ...
My question is: Should each of these things be loaded seperatly with its own backend API call, or should i write a API backend call that will combine all these things into a single object and use it to load my data? |
Navbar items alingment for bootstrap 5 Posted: 09 Sep 2021 07:48 AM PDT I am sticking to this problem for such a long time. Please help me to fix it... I really tried various ways but none of them is actually working. I want my login button at the end of my navbar(right side) and when I decrease the screen size i wanted it to be appear on the left side of the burgger menu Here is my code - <header class="header"> <nav class="navbar navbar-expand-md navbar-light bg-light"> <div class="container-fluid"> <a class="navbar-brand" href="#"> <img src="image/logo.png" alt="" width="150px" height="35px"> </a> <div class="login-nav ms-auto mb-2 me-2 "> <ul class="navbar-nav login"> <li class="navbar-item login-item"> <a class="nav-link active" aria-current="page" href="#">Login</a> </li> </ul> </div> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav ms-auto mb-2 "> <li class="nav-item"> <a class="nav-link active" aria-current="page" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Link</a> </li> <li class="nav-item"> <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> </div> </div> </nav> </header> I want them like these pictures : enter image description here enter image description here |
Login to redirect to other page Posted: 09 Sep 2021 07:48 AM PDT import React from "react"; import { useHistory } from "react-router-dom"; function Login() { const history = useHistory(); function checkLogin() { const loginFormUser = document.getElementById("login-form-user"); const loginFormPassword = document.getElementById("login-form-password"); const loginButton = document.getElementById("login-form-submit"); loginButton.addEventListener("click", () => { const username = loginFormUser.username.value; const password = loginFormPassword.password.value; if (username === "toilacoder" && password === "123456") { return ( history.push("/profile" ) )} else { return (history.push("/home")) } }) } return ( <form onSubmit={checkLogin}> <h2>Please login to get access to your profile.</h2> <input type="text" placeholder="Username" id="login-form-user"/> <input type="password" placeholder="Your password" id="login-form-password"/> <button id="login-form-submit" type="submit">Login</button> </form> ) } export default Login; This is my code. But I cannot redirect from Login page to Profile page after clicking Login button. Please show me how. Can you guys show me some ways to fix that. I appreciate your time! |
When using structopt, how to test if the user provided an option or if it comes from the default value? Posted: 09 Sep 2021 07:48 AM PDT I'm using the structopt crate and I have the following struct: #[derive(Clone, StructOpt, Debug)] #[structopt(name = "test")] pub struct CommandlineOptions { #[structopt( long = "length", help = "The length of the the string to generate", default_value = "50", index = 1 )] pub length: usize, } let options = CommandlineOptions::from_args(); If options.length is 50 , how can I know it comes from the default value 50, or the user provided a value of 50? |
Change Price with range input Posted: 09 Sep 2021 07:48 AM PDT I am creating a pricing table and the price should change according to how many users will be registered. The testing site is https://fonexinc.com/price3.html My question is how do I change the price according to the user range input? I use this input range from codepen: https://codepen.io/yavuzselim/pen/qZJQra Code for the price <div class="price-card--price-text"> <div class="price-card--price-number toggle-price-content odometer" data-price-monthly="18.71" data-price-yearly="224.52">18.71</div> </div> Code for the input range <p> Number of users </p> <div class="range"> <input type="range" id="slider2" min="1" max="5" steps="1" value="1"> </div> <!-- <span id="slider_value"></span> --> <ul class="range-labels"> <li class="active selected">1</li> <li>2-20</li> <li>21-99</li> <li>100-999</li> <li>1000+</li> </ul> |
How to convert Hue Saturation and Lightness (HSL) into Hue Saturation and Value (HSV) color? [closed] Posted: 09 Sep 2021 07:48 AM PDT hslcolor = {'h': 153, 's': 89, 'l': 95} def hsltohsv(hsl): # code to convert hsl into hsv I want to know how to convert HSL (Hue, Saturation, and Lightness) into HSV (Hue, Saturation, and Value) using Python without any library (e.g., colorsys ). |
use serialport to send multiple bytes (array) at a time Posted: 09 Sep 2021 07:48 AM PDT The example code from serialport-rs documentation is as follows. let output = "This is a test. This is only a test.".as_bytes(); port.write(output).expect("Write failed!"); Nevertheless, I want to send 64 bytes buffer like this, let buffer = &mut [0_u8; 65]; buffer [0] = 0xA6; buffer [1] = 0x55; port.write(&buffer[0..65]).expect("Write failed!"); I have looked through the documentation, but to no avail. The console shows garbled text. Are there any other ways to achieve this? Thank you! The garbled text is something like this �������������������������������������� |
Change image src on scroll Posted: 09 Sep 2021 07:48 AM PDT I'm attempting to swap / morph one image into another by changing the image src attribute on scroll. It kind a works, but the image flickers. I would also like to reset the src back when scrolling up the page. My code var elements = $('img.image-toggle'); $(window).on('scroll resize', function() { $(elements).each(function(){ var toggled = false; var imagePos = $(this).offset().top; var topOfWindow = $(window).scrollTop(); if (((topOfWindow+250) > topOfWindow ) && !toggled) { toggled = true; $(this).addClass("toggled"); img1 = $(this).attr('src'); img2 = $(this).attr('data-scroll-src'); $(this).attr('data-scroll-src',img1); $(this).attr('src',img2); }else { toggled = false; $(this).removeClass("toggled"); img2 = $(this).attr('src'); img1 = $(this).attr('data-scroll-src'); $(this).attr('data-scroll-src',img2); $(this).attr('src',img1); } }); }); Ideally, I would like to make the transition of the images morph smooth. |
OSMnx: How do I plot a route onto an existing figure? Posted: 09 Sep 2021 07:49 AM PDT If I already have a graph of a city in a figure, can I draw one or more routes on it afterwards? Until now I have created a graph within some bounding box which I then display with plt.show() : north, west = 47.45711622150064, 8.347885652066624 south, east = 47.31625428324118, 8.69120840316829 G = ox.graph.graph_from_bbox(north, south, east, west, network_type='drive', simplify=True, retain_all=False) fig, ax = ox.plot.plot_graph(G) plt.show() So now you can see the graph in the matplot figure: figure of graph Then I want the user to enter start and destination coordinates and display the calculated shortest route on this figure. However, I have no idea how to plot the route on the figure after the figure is opened. This doesn't work: G = ox.add_edge_speeds(G) G = ox.add_edge_travel_times(G) start_node = ox.distance.nearest_nodes(G, 8.435432953597548, 47.39719131318801) end_node = ox.distance.nearest_nodes(G, 8.636963408494227, 47.3699935785241) # Calculate the shortest path route = nx.shortest_path(G, start_node, end_node, weight='travel_time') # Plot the route and street networks fig, ax = ox.plot_graph_route(G, route, route_linewidth=1, show=False, close=False) plt.show() |
InfluxDB 2.0 - How to merge and sum 2 separate buckets stream in one with Flux Posted: 09 Sep 2021 07:48 AM PDT Context I work in an application with influxDB and I am facing a use case I don't know how to solve. I am using influxDB 2 and flux for the queries. Use case To simplify my use case, I'll take an example with bees. I want to measure the evolution of the bee population accross time. I measure 2 populations of bees in 2 separate buckets (bucket A for bee A and bucket B for bee B). So I want to find a query that merges these 2 buckets to get the current population of bees at any time. Using 2 buckets is mandatory in my use case. What I want is just a way to "combine" the result when I query. The results should be sorted based on the timestamps Examples The query on the Bee A and the Bee B buckets returns the values in the first 2 lines. The objective is to create the Total line. Example 1: In case the measurements are always A, B, A, B; the result must be as Populations | | | | | | | | | Bee A | 10 | | 12 | | 5 | | 22 | | Bee B | | 20 | | 16 | | 19 | | 36 | Total | 10 | 30 | 32 | 28 | 21 | 24 | 41 | 58 | Example 2: In case the measurements are A, B, A, A, A, B; the result must be as Populations | | | | | | | | | Bee A | 10 | | 12 | 5 | 22 | | | | Bee B | | 20 | | | | 16 | 19 | 36 | Total | 10 | 30 | 32 | 25 | 42 | 38 | 41 | 58 | Code I tried using union but I couldn't get it to work as it kept 2 separates tables instead of one. bucket1 = from(bucket: "beeA") |> range(start: 0) |> filter(fn: (r) => r["_measurement"] == "population") |> filter(fn: (r) => r["_field"] == "pop") |> sort(columns: ["_time"]) bucket2 = from(bucket: "beeB") |> range(start: 0) |> filter(fn: (r) => r["_measurement"] == "population") |> filter(fn: (r) => r["_field"] == "pop") |> sort(columns: ["_time"]) union(tables: [bucket1, bucket2]) |
Unable to decompress Brotli data in GoLang Posted: 09 Sep 2021 07:48 AM PDT I am implementing the TLS Certificate Compression Ext for Go http client. I added The Ext to the client hello with Package https://github.com/refraction-networking/utls So i targeted a server that support Certificate Compression and I inspect the TLS communication between the go http client and the server to capture the handshake type 25. Once I get it I tried to decompress the certificate on it but I don't got the result I should get. My code: package main import ( "fmt" "bytes" "encoding/hex" "golang.org/x/crypto/cryptobyte" "github.com/andybalholm/brotli" "io/ioutil" "io" ) var handshake string = "19000f25000200169d000f1d81e0b40020433867499a06b1f19815b162d722a243bd78b7428bf863456ce6589129e23a05260613f19143d55e7e47bcf152b9d47805dff1e2bbf6eedfa7a5403b9fde07997079992d3e927534f481f5e800b9b355637b8e3af970fad00996b0403b4190f0590833064c4c1faf839761e110184138a0a3df3dbd64776417000fc6412c7128f9c603c35c780814f490b8000786f3413101c4c78bb407f09e67b00bb0592651b3e809149200e0979ecd26c0e915494f49498ea2d0a249e240f4b834a700bf3ddd86121595a919498f57273826446a923480dae7b7e11250884b4961186969454627a5246bc6d2a3269fa99514cda0275353e849995a246d40bac4082740b4a713f49d9be0151d999a144db08e4e4aa1c650232929d104cbd494b8f1726a4a264183604f06d2223c641220036d92aeb61e493f5084874c06da405f64028c49b240e64e9e266a438fa7501308d6f48494243a8de04ba151a32829d151246120687d2f6e1ea2263d26263a299571877d8009cbfd5400f80f07c784f920c0843911260c434f367ebc248e1aee426967d3dfe6147b4df45e4afc3173d97987dc723f4a9cfb9bf46e99d3b35336dcf797a8c313fc1da62e0b59857ebcb67e174d8cb7970f61a2b15cc307c679bb8fb9548f7e7749df6fa97640d73ef6a974fe4ddfb4f59d153acde8cdb06569c07f30dde774cb11b68c05971d3f5ebb660b867d4642ca40579bfeb183cc2624eefead38a99762da3ff6bf323d19f5a3e1c9c3ea079450f6ace662f1c2b8e3a1a1070fc6b85d2ea73444d19913e58f54a133964b9724dc0fff1cb9d4672013996f99dab09a9f182d82e74027cd89ffb99b540b6e1a9696ac34132cf592d73f871f6d3df8a8b3fef4ad3ab5f66a9b9a4e9f86fb6b94987db9cb3730ae1c04074370231399024c640c7063381f290118fe872200025218ce474a1115068218bb1a06e3f16c38186357c3603c9e0d87005e0ce723c507c3ff501487e059c000c3f948c9a024a00534586a2cd512e5b894148691965664124d33961e45f19a4bc4465163c9c9240db29ebe8e6664120d8498be3501f505dec001e30a2f71804bfec4c36c22303004fa567b115858cd11590e159a3f1e09d8312cb6801b466090a6c60386d17d200e28c894002e1155db4f8f4c66a813018b999d424a748c33bea15c333229c5711f29258f8a02e17c418ba951e5432b3a85a0417bf317adfb7d8f7afe1a509c34023f2a0d2499672e934b2000cf02c0bb0c4705cb16de1074fd153df7ba50ff275e28d92a7c637a1530613cc6a986c1287c2b134111b4e02b5af009fa00a541aa9963ef6b0d0d65dffb26d7459e4f7f32e697531dcef9fdc7de10a560c590f9220882d3e3ca4bf640108a83ec812d220bfdbc25abf1c7c093552cfda731a1a49f282e7fc8ca23e0be7ba9d5f8fe3a9f7d5e08c1ca4f3a96c99d1969d2333f34a260f45d73cfeebf8d37e3bf171baf36d1780e1640e9909cad2d5b808f82ef29f37aad0fdfe24b1eca2b45b64e38e785cc1506273ce64320084e8f2b2f758120140739003b44163a25a3642ad7e7dc773a60fe44f290687ceb2ca978a2e6efb79b75c34f770cb60e20b250ef52c5e1f8e3c3b2eb7d738ccf94632f1f40ff6c5359baa7e2661763ec442944c0837150221f17e20b6de69c47faeff7092964569ea899879678919c924e5145337ee220caf1fc5d909cb4f4528fb4592fcfcc3d4875f24f9e14d1747d7bb7226b9ac72d5fb2cf3133e74883158c8a5273f47cfceda233ca2f924a2742c7d6efc69bf15271c50f3735326aaa75952d291f9f18eed308abcebc9927853563d38548cb698d4fe2eb8ff3a3b6a0b3d39583fbb807fcf5c59b36c39fa9b9277d795b4f75ccb656abbd9e065509d3ee1fbea7453189685ec2d1dff11ddc73785c9979e0e469d35f320606e7d70e7de6bcc4ddfdf7f5f460d4a2c4f8e35b8e36a8d654cb03f76a5ee7d4aecb5d9f5eab093d33bb6337a89f1fbe749cd5e77b2032f1a41291b635663d10bb77a5b502fb09e1b1af30847d044cec2d270cb198d833c0c476300eb53078f3619489dd004c6c0314fcaacf021979042d0404a0dccc14825403aa629c805c4e60d176232a3d21171044f9c80068f8c91b92f54986818006f6012bc081e1d5787188381e4205fbd879c268fbd35e09ec1a9cff1ec375c9535bc7158d2fdf5459381f522f62f18b51ba403fa8072d9eb850952cf8411645e132e17a0b71db8e2bf5dc78f8fa97ba7326137db4a424c9c31d7a05fe901349909a563c95e4f48ad4a124d9f098d5aa345e875dafc898d760be66929a3d56e6959da66a4f6c06bc99bd5d1eb4e4d4d9ecb57838634a0fc7485f3f12b37365a5fe5fead7f7c695e73f9efdf35c049be93efac32a476acf85b1cbf4c72eb5d3654263ab67a71545221681dd911ee6fe38cd8c5cf980bded5742b2df5d13090ffa1269b5fc5cfcda59bfd0b9dacc4a1fcb36ea5afdc151e753c75dd43b70cbfd3b6172620a3b4dc68a533ae45a5cdb4af959fc47b6e3754569991f2c976c154a2d1c33bade0c3f5b092d18ebea0902263279ee178c92541a17ffbe6331d121c044fb0013ed024cdc395611f2ebb0f9e7387875e0d506880d0109e80300808f6842c322bc0a661aec0d72788aeb33193b71ac653167321bb61850733aaf3f2594fd38c4f75c0d567498d7f3feaf8db91145adfbd946cf6b153f79b6f2ed18548c6cf06d8a1ac5d439e59bd8d70b9e659af1cc6555befba47023f279e1991703e8e7a50b41f66f36dfbc9ef27b05fd18b5d2299cd6f48b0b9508e07c68271426d0db3e5bfbf82b45fd5205d538507df8a1ddee01c22b89e219916fc95f6fcfe04f1dfa7392eff1e9ccbbfe07a0d164c637afcded295b8b841709968d0f72841fd192de7fdcb85e78a2ceb5d19750b6f893c77da853b9567679f5f711799917f7097fb6362d27ff3eee1d696f0bfe339f70c0e038e1cf7b88db62ebc60789a19163ce43e31755fdce347b851d7e328ae0606c0543a0e0cf0ae2e5f349f4280ec1261e88959422ca0d38cb98588eec7a57f9c921a2e39d97a3d67d6f7f6c70bcb3ce493ac5047c18531ae251040f01976b8e96416d8135b06499b34c4b8c3db3a424da6e164f494e894e9ae044a62627a75213624b1f88130d6b6009cc2901d04c53ce5050065b62b94fe73dba5030a1b1025615c52f2ded343a1f720f0cbeb2eb2d5c26c7984b0e64b2dd5d8a94c9fe287133ac46a666d5ecc56df6c9484f779f48d75f24a43f91d385f1b6a17fde8ad93e9d135170d2755d6af8b74813e79f4fb15c87e8c4c3173787567b781c2c9f5da74deee1caba77c34784f799dc989c69ffe309b7d7d1fd22224b07f62a8f77d91e3cb2f140462441d8efcdbbeb1e5e61db7b6f99361f3eed397666c5cda3e609fa89a1dda05bc7de6e1503bd10fda5c6746eb2e270b219f7669790d43996cceef67a1da9d1b26bdf1a7af6640cf832ac4e8aed7779fb607bdc36bcd680deccd07e715745b9e20cdee14c11d560649bbc1e18ab1da665760bb01220f40660a21b80891b60e11018416036c08371104b1c48eb67150249025a629c804a8cafc6934e4fe1200089afdbf7b0469cb6e85ba6d6b0086c0e1c7cb8bce7467bdae88de311af40d440013b6d1add8e1039a4f5cf2c7afdf05ac453134fc9dbc2b6ce3ecd19fb230b238eacf151696717c4052b5d566cb55f96ddad6d6c57fb9b4fa9c9f49b59d7fc6c0e4c42ec7f9f131e99d63f65e97188dfd9fbbbcad8c681b1f7c040fa5387d2f718fbc8f8fb894af6870decbdaeda49f5ecdc855edab68c8e246e5fa14377eeac02a34cb73017fbef52ef82a6666ac28d3bbbac8f6e3569bbbeecbea5ecd6aa58717eeef3cd8d0b6d29f828bfb25e1b9f1b1a4423b3ef03a32fc89cc889a8196123f70f4e6dcf32b5dbb9096c79cf1fa08653548416e9f9337d526221a57461f0b8a8bbb7ae33d575c4f8baa3a6ccddc96b9ebf101cacc5011316067cdb08788083e17f472e8cf155f07ec2afe17867a373c56c7b6255fade7d1dc55b2610264fdce6bb0f743a216aa80025a12eeb8d8b26500744960a4ba94401c6b15149747a8a46fb83a401bb3308a8393005c618ea234580801ff9f01a4831ad64e70bfafec766cfa51ddfb3603070eaf211e77ff5616ee83b9a597519b6e87ef842f2373f92c4d8c8aed69def43d7831ef63c7b9a19c1cbddb0b92f3299d4fbe592439331bb4643c891cd9eff15ddf87dc14c9f4d4db67acd93d0a7efb82957c67789126f8b6a070a7326add76c2e0a30788eca7c5e10682d0cdfde4aba94ac20dddb22c7bb24521ee16f23d15cae08437cab331211773c7aaef37910ab3e8f24ff4e5bd36b5addde527fd956f585d875e4eade54d10af30acb23f23941ce7f9b70fe55765dd3e1e185df73dc2dd7a6ea8f4c0fbf43b4ae0979bfb511dae66cbb58a1fda653234d4fe92efaaaee1b4546e86e29fdaddd2995d67aa51c4e8e8b9a68e3c191ef2328802108420b0013cd014c5c340b87c008829378260478307a4b10c91bacbf51009c6aefb86842246f619f444f65b01729d7f6d6344a7232811ce9fe850a63a9d501a4ea893e60da60f239362c329a03c71323d83ffc0cd0f926b128daf82ddfd1ff855ca1c0855982356c5cf4e169b1639df2cbaf4512aeac9e3b8c33f364b8136fc6e6faf6f34f37ad0020f7ac59cc77ffe37cb6df9f8453f30d3db29ffcd0ed4b71bd7c9029b0db677e1957f8b361ac42685fde7daee93e3141fcd2cbe94be80963bbffc93c9fa018b98583d478bd03fca2fdd7bb24c37b0c7e2207d6aedfb363bbcf69f62ae4ff85ff7f75a879351d8ba07a28e229e2360507d42f5b9f927fd06254708e577556f2f28b10e9beda5ac069b8f6a12cff9773c80af9757184b5a20ee2ab0c1fed316610cd133a9f5797c13975377edcf18a0faf19577fe6df3c1066f77b6d460267c2f1ca91144cb5eb7e688fe00014219b4070aef11b1f8a6b331dd78ede70e14feca62c9bd6ffbd7769df8d1d40c8e3ae065481324b91255f228b2ffd9a0203b8bc468f95f05f54c87e13445a9792a131660712c65c87bf8e9d767f04f2865482234e4cede46a7ffb6595567ce7a4e40139ff540eeeb2e858434e618e5996c1e9a659f9e3e63da21760cce6e8ce45aa724fa0629e513f79f55ed13fa281aa76d3bdd8aee2bff5650449f7f285bbc4af56387d97a7650f6eb62b7cec9c7eb0d2fbfae1d9d07e476f82c90951ee79494f51c7a6f847ddfe5c8b5bafb7db24c98754183c8fff5e10a92de21bf5637407be906195780dbffbff1f95eba1c374ff71ae054eef999610c1587ddad2792d12bbfe9504fa8191aac77e210a05eda74f5717b5d25af45d623e518ef21376c7405d56932a47c7239db0a874510b8f0707c0857608020f000104080401003082f7d2396df3b121e7304d9c8cfc4cb6ad23251fdb1569e8514c5af75c7fdc20dc22c4f7e67c4a18f8a18056bcdaea89edc1c9871e929bb40db67de0a0f62fde87c08723cada0c502210b3c8793254a6043b0c5e0e90f59588e9ecd68e22d40a0d4e6b6ed4d0c9343937b9be9345ca7e7ad513dd8b606d2ac0ad78d60e326037f21edcea2ba9e6bfbd2ba65e6a0ff11b0c9f6ae56b70e58b4b21f7790058f8b6b709cb06047670d096c862da834d1f12ae05ca085bc5551e570cd3141b45fceaf5cb833c9e6bb57865a30ca3a2e7b59d30a2a35629aa91d707f333f3e835499efe6859479d6adf15ec4c91fdca1ad2c5c5890e299618e9001e4f998eb18c9f140000200bbacb08b71d710d6f80844786c8a0a7f0feec6c2f52a442f1fbf36cea2c2e5f" func DecompressBr(reader io.Reader, certlentgh int) { data := brotli.NewReader(reader) decompressedData, err := ioutil.ReadAll(data) if err != nil { panic(nil) } //output: no if len(decompressedData) == certlentgh { fmt.Println("yes") } else { fmt.Println("no") } } func ReadCompressedCert() { var ( u8 uint8 u16 uint16 u24 uint32 databyte []byte ) data, err := hex.DecodeString(handshake) if err != nil { panic(err) } cryptobyteSTR := cryptobyte.String(data) //Read The HANDSHHAKE type if cryptobyteSTR.ReadUint8(&u8) { //check if the handsahe type are compmressed cert if int(u8) == 25 { // Read THe length of the handshake cryptobyteSTR.ReadUint24(&u24) //output: 3877 bytes fmt.Println(u24) //Read the Certificate Compression Algo cryptobyteSTR.ReadUint16(&u16) //output: 2 (brotli algo) fmt.Println(u16) //read the uncompressed_length of the certificate cryptobyteSTR.ReadUint24(&u24) //output: 5789 bytes ("So i should get 5789 bytes when i decompress the certificate") fmt.Println(u24) //Now i will READ the compressed cert to prepare it for decompression cryptobyteSTR.ReadBytes(&databyte, 3872) } reader := bytes.NewReader(databyte) DecompressBr(reader, int(u24)) } } func main() { ReadCompressedCert() } The question: Is there something wrong in my code ? |
Cannot install py7zlib package using Python 3.6 Posted: 09 Sep 2021 07:48 AM PDT I am trying to install py7zlib package, however I am getting below error: ERROR: Could not find a version that satisfies the requirement py7zlib (from versions: none) ERROR: No matching distribution found for py7zlib I am using Python 3.6. I tried: pip install py7zlib I would like to have this package working properly. |
ModuleNotFoundError: No module named 'plotly' Posted: 09 Sep 2021 07:48 AM PDT After reading all the existing post related to this issue, i still did not manage to fix it. ModuleNotFoundError: No module named 'plotly' I have tried all the following: pip3 install plotly pip3 install plotly --upgrade as well as uninstalling plotly with: pip3 uninstall plotly And reinstalling it again, i get the following on terminal: Requirement already satisfied, skipping upgrade: six in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from plotly) (1.11.0) Requirement already satisfied, skipping upgrade: nbformat>=4.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from plotly) (4.4.0) Requirement already satisfied, skipping upgrade: retrying>=1.3.3 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from plotly) (1.3.3) Requirement already satisfied, skipping upgrade: urllib3<1.25,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests->plotly) (1.24.1) Requirement already satisfied, skipping upgrade: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests->plotly) (2.7) Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests->plotly) (3.0.4) Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests->plotly) (2018.10.15) Requirement already satisfied, skipping upgrade: jsonschema!=2.5.0,>=2.4 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from nbformat>=4.2->plotly) (2.6.0) Requirement already satisfied, skipping upgrade: jupyter-core in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from nbformat>=4.2->plotly) (4.4.0) Requirement already satisfied, skipping upgrade: traitlets>=4.1 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from nbformat>=4.2->plotly) (4.3.2) Requirement already satisfied, skipping upgrade: ipython-genutils in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from nbformat>=4.2->plotly) (0.2.0) import plotly import plotly.plotly as py yield: ModuleNotFoundError: No module named 'plotly' my version of pip(3) as well as python(3) seem to be both fine May somebody please help? Using Python3 on Atom 1.32.2 x64 |
Angular console log only on development environment Posted: 09 Sep 2021 07:48 AM PDT In our Angular app (made with Angular CLI) we use several console statements. Is there a global way to detect environment and then display console.log in our components and service only under development? What I mean by global way - I know we can use something like: if (!environment.production) { console.log(this.reviewTasksList); } But by using this code everytime we have to console.log (along with necessary import to get environment variable) our code will become kind of verbose. I want to know if there is a way to maybe: - access the environment in a quicker way
- Maybe delete all console logs at prod build time
Or the better solution here is to create a logger service and do all the environment check within it? I don't want my bundle size to be impacted by debug statements and service. |
DynamoDB - Why can't I use an "_" as a prefix in my key condition expression? Posted: 09 Sep 2021 07:49 AM PDT I am using the AWS DynamoDB DocumentClient to query my DynamoDB tables. In my tables I have a property called "_id" that holds a unique ID for each entry. When I try to query for a record based on this ID, I end up receiving an error that says: "Invalid KeyConditionExpression: Syntax error; token: \"_\", near: \"_id\"". The code that makes this query is below. function findById(id) { //Build query var params = {}; params.TableName = "recordDev"; params.IndexName = "_id"; params.KeyConditionExpression = '_id = :id'; params.ExpressionAttributeValues = { ':id': id }; return DynamoDB .query(params).promise() .then(function(records) { return records.Items[0]; }) .catch(function(error) { return Promise.reject(error); }); }; Is there something that I am missing with regards to using an "_" when building the query params for DynamoDB? I have tried looking around for similar errors, but have been unable to find any that are like my scenario. |
No comments:
Post a Comment