Posts

Showing posts from September 1, 2018

Why is reduce performing better in this use case of finding duplicates in an array [closed]

Image
Clash Royale CLAN TAG #URR8PPP Why is reduce performing better in this use case of finding duplicates in an array [closed] Recent problem stated that given an array of very large size we need to find first duplicate value and return it (not the index but the value). So given an example array of [1,2,3,4,5,3] we need to return 3 since it is the first value with a duplicate in the array. [1,2,3,4,5,3] 3 Now the array in question could be 100K and much larger. Given those requirements there are few solutions that come to mind right away. 1.Using ES6 with Set solution: function firstDuplicate(a) var r = new Set(); for (var e of a) if (r.has(e)) return e; else r.add(e); 2.Using for loop with lastIndexOf: const firstDuplicate = (arr) => for(var i = 0; i < arr.length ; i++) if(arr.lastIndexOf(arr[i]) > i) return arr[i] 3.Using reduce & lastIndexOf: Note: I am aware that this approach mutates the input via splice used to exit from the reduce... splice const...

PermissionUtils can not be resolved

Image
Clash Royale CLAN TAG #URR8PPP PermissionUtils can not be resolved I'm trying to get my current location in my app but I'm getting PermissionUtils error. This isn't getting resolved. I got the codes from google's official github tutorial. PermissionUtils public class MapsActivity extends FragmentActivity implements GoogleMap.OnMyLocationButtonClickListener, GoogleMap.OnMyLocationClickListener, OnMapReadyCallback, ActivityCompat.OnRequestPermissionsResultCallback /** * Request code for location permission request. * * @see #onRequestPermissionsResult(int, String, int) */ private static final int LOCATION_PERMISSION_REQUEST_CODE = 1; /** * Flag indicating whether a requested permission has been denied after returning in * @link #onRequestPermissionsResult(int, String, int). */ private boolean mPermissionDenied = false; private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentVi...

Create CSV in VBA for Excel for certain range with prompt if file exists

Image
Clash Royale CLAN TAG #URR8PPP Create CSV in VBA for Excel for certain range with prompt if file exists I've mixed code and get good results considering that I wish to create csv file without header and for first 12 columns of file. Also, I've found way to send message about successful creation. My main problem now, is the fact that I can't push code to ask me if file exists, and to create it just after confirmation. The best solution will be if I may on easier way do next: Below is code and obviously I need help Private Sub CommandButton1_Click() Dim fs As Object, a As Object, i As Integer, s As String, t As String, l As String, mn As String, PathCSV As String, NameCSV As String PathCSV = "D:BOM" NameCSV = "MMA - " & Format(Date, "mmmm yyyy") & ".csv" Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("D:BOMMMA - " & Format(Date, "mmmm yyyy") & ".c...

Checking if a website is up via Python

Image
Clash Royale CLAN TAG #URR8PPP Checking if a website is up via Python By using python, how can I check if a website is up? From what I read, I need to check the "HTTP HEAD" and see status code "200 OK", but how to do so ? Cheers Duplicate: stackoverflow.com/questions/107405/… – Daniel Roseman Dec 22 '09 at 21:43 11 Answers 11 You could try to do this with getcode() from urllib getcode() >>> print urllib.urlopen("http://www.stackoverflow.com").getcode() >>> 200 EDIT: For more modern python, i.e. python3 , use: python3 import urllib.request print(urllib.request.urlopen("http://www.stackoverflow.com").getcode()) >>> 200 Following question, using urlopen.getcode does fetch the entire page or not? – OscarRyz Dec 22 '09 at 23:13 urlopen.getcode As far as i know, getcode retreives the status from the response that is sent back – Anthony Forloney Dec 23 '09 at 0:38 getcode @Oscar...

Match Rows By ID and return a value from the row with the closet date before a specified date

Image
Clash Royale CLAN TAG #URR8PPP Match Rows By ID and return a value from the row with the closet date before a specified date I'm using Google Sheets and have dataset 1 pictured below, which includes ID, Date, Value. This dataset has a number of rows with the some duplicate ID's but different dates against them. Dataset 1 I then have dataset 2 with ID, Date, Empty Column. I want to be able to populate the empty column with the value from dataset 1 that matches the row ID, however is pulled from the row with the closest date before the date specific in dataset 2. (Hope I've explained that well enough). Attached a couple of images for references. Any help would be really appreciated on this one! Dataset 2 1 Answer 1 For clarity and maintenance, I am doing this in 2 steps. In theory it should be doable in one as described at sql with dates. I have also referred to dates with qoogle query, and looking there one may find simplifications. On the Dataset2 sheet, I added a c...

How do I invert a matrix in tensorflow-js?

Image
Clash Royale CLAN TAG #URR8PPP How do I invert a matrix in tensorflow-js? Simple question. Is there an operation for it, also, how do you create an identity matrix? I've checked the documentation but can't find a single operation. 2 Answers 2 For now tensorflowJs does not have any direct operator that can return the inverse of a matrix M. You can consider using the module Math.js Having said that, it is possible to invert a matrix using tensorflowJs operators. The following calculates the inverse of a matrix using the adjoint method with tensorflowJs operators. // calculate the determinant of a matrix m function det(m) return tf.tidy(() => const [r, _] = m.shape if (r === 2) const t = m.as1D() const a = t.slice([0], [1]).dataSync()[0] const b = t.slice([1], [1]).dataSync()[0] const c = t.slice([2], [1]).dataSync()[0] const d = t.slice([3], [1]).dataSync()[0] result = a * d - b * c return result else let s = 0; rows = [...Array(r).keys()] for (let i ...

S1000 Operation not allowed after ResultSet closed in Intellij only

Image
Clash Royale CLAN TAG #URR8PPP S1000 Operation not allowed after ResultSet closed in Intellij only When using When I execute a call to a stored procedure, I get an error message [S1000] Operation not allowed after ResultSet closed A simple stored procedure for testing DELIMITER $$ CREATE PROCEDURE test1() BEGIN SELECT 'THIS IS A TEST TEXT'; END $$ DELIMITER ; The call CALL test1(); The output NOTE: I don't get the issue when using console. Which version of MySQL Connector/J are you using? – Mark Rotteveel Aug 12 at 6:43 mysql-5.7.17-winx64 – zessi Aug 12 at 8:05 That is your MySQL version, I asked about the MySQL Connector/J version (the version of the MySQL JDBC driver you use in IntelliJ). – Mark Rotteveel Aug 12 at 8:06 5.1.64 in intellij settings.Don't know which one datagrip uses. – zessi Aug 12 at 8:09 There is no version 5.1.64, did you mean 5.1.46? – Mark Rotteveel Aug 12 at 8:09...

Format a 'numeric' string as a number-like string

Image
Clash Royale CLAN TAG #URR8PPP Format a 'numeric' string as a number-like string I would like to format a 'numeric' string as a 'string number' in Clojure. This is the format mask: "#,###,###,##0.00" Given the string "9999.99" I would expect to receive back "9,999.99". How would I do this in Clojure without resorting to writing a function i.e. using format or something similar? format By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

JavaScript Nested Functions cross referencing

Image
Clash Royale CLAN TAG #URR8PPP JavaScript Nested Functions cross referencing I have a nested function that needs a return type of the previously declared function to use it as a function argumen t . I don't know if my structure is correct or can support this . would be grateful for some advice on how to call it var myObject = funct1 : (function ()..... return funct1; )(), funct2 : (function (funct1)..... return func2; )(funct1) ; So the question is how would I call that funct1 argument correctly in the second function Do I use the myObject.Funct1 or is there another method of calling that object internally ... Im currently getting a error Cannot read property 'funct1' of undefined Can you clarify what you mean by “return type”? – Xufox Aug 12 at 3:22 So function one returns the funct1 object ... function two needs that object and uses it as an argument . Im not sure how to call it with in the myObject object ... thanks for the help –...

Using OR statement within Query Importrange function?

Image
Clash Royale CLAN TAG #URR8PPP Using OR statement within Query Importrange function? I have a spreadsheet that I use to track orders for our business. Within this sheet, there's a cell that contains a data validation list with various statuses for the order. I am attempting to set up a secondary sheet for our delivery person to view only orders that are currently anything other than "Delivered", "On Hold" or "Canceled" status. Other statuses are "New", "Packed" and "Pending". What I have so far is the following: =query(IMPORTRANGE("1CtEslspJ0qmsEc94q6RT6JW7ODxCrTK3MbI2wDF8BUE","'Order Tracker'!A:I"), "select Col1, Col2, Col3, Col5, Col6, Col9 where Col3 = 'New'",-1) This works great to pull all orders that are New, but obviously I need more than that. Not sure how to proceed because I tried inserting an OR() statement with the where Col3 is, but it spat errors no matter ...

Display picture in React Native

Image
Clash Royale CLAN TAG #URR8PPP Display picture in React Native I'm making a React Native app with Expo. In my app, I upload some pictures via the API of my website, in a local database (SQLite). The problem is that I want to display these pictures like a gallery but I can't. I'm doing something like this: for (var x =0; x <= prod.length; x++) require('../../web/image/'+prod[x].picture); Can someone help me? 1 Answer 1 In React and React Native, a component renders using its render function. render For instance, in React Native the native Image component is used for rendering images. To render a single image, your component should include something like this: render() return ( <View> <Image source=require('/react-native/img/favicon.png') /> </View> ); Adding logic inside of your JSX is easy too! Simply wrap any Javascript code inside of curly braces as follows: renderImages() var images = ; for (var x=0; x <= prod...

Python Programming - to modify a list item in a dictionary

Image
Clash Royale CLAN TAG #URR8PPP Python Programming - to modify a list item in a dictionary Question: # Write a program to modify the email addresses in the records dictionary to reflect this change records records = 57394: ['Suresh Datta', 'suresh@example.com'], 48539: ['ColetteBrowning', 'colette@example.com'], 58302: ['Skye Homsi','skye@example.com'], 48502: ['Hiroto Yamaguchi', 'hiroto@example.com'], 48291: ['Tobias Ledford', 'tobias@example.com'], 48293: ['Jin Xu', 'jin@example.com'], 23945: ['Joana Dias', 'joana@example.com'], 85823: ['Alton Derosa', 'alton@example.com'] I have iterated through the dictionary and created a new list with the values and split the email at @ and was able to change the the email from .com to .org. My approach was to join the changed email and change the values of the dictionary. However, I keep on getting a TypeError: seq...

Rapidjson Iterating over and Getting Values of Complex JSON Object Members

Image
Clash Royale CLAN TAG #URR8PPP Rapidjson Iterating over and Getting Values of Complex JSON Object Members I have the following JSON object "prog":[ "iUniqueID":1, "bGroup":1, "inFiles":[ "sFileType":"Zonal Data 1", "bScenarioSpecific":0, "pos": "x1":1555, "y1":-375, "x2":1879, "y2":-432 , "sFileType":"Record File", "bScenarioSpecific":0, "pos": "x1":1555, "y1":-436, "x2":1879, "y2":-493 ], "outFiles":[ "sFileType":"Record File 1", "bScenarioSpecific":1, "pos": "x1":2344, "y1":-405, "x2":2662, "y2":-462 ] , "iUniqueID":2, "bGroup":1, "inFiles":[ "sFileType":"Matrix File 1", "bScenarioSpecific":0...

Spring Boot Application cannot run test cases involving Two Databases correctly - either get detached entities or no inserts

Image
Clash Royale CLAN TAG #URR8PPP Spring Boot Application cannot run test cases involving Two Databases correctly - either get detached entities or no inserts I am trying to write a Spring Boot app that talks to two databases - primary which is read-write, and secondary which is read only. primary secondary This is also using spring-data-jpa for the repositories. Roughly speaking this giude describes what I am doing: https://www.baeldung.com/spring-data-jpa-multiple-databases And this documentation from spring: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-two-datasources I am having trouble understanding some things - I think about the transaction managers - which is making my program error out either during normal operation, or during unit tests. I am running into two issues, with two different TransactionManagers that I do not understand well 1) When I use JPATransactionManager , my secondary entities become detached between func...

aws-sdk/clients/cognitoidentity has no exported member 'String'

Image
Clash Royale CLAN TAG #URR8PPP aws-sdk/clients/cognitoidentity has no exported member 'String' when starting an angular 6.1.2 project i have this error : ERROR in node_modules/aws-amplify-angular/lib/components/storage/photo-picker-component/photo-picker.factory.d.ts(3,10): error TS2305: Module '"/Users/knewtone/Dropbox/knewtone.com/projects/WorkSpace/softwares/yet.marketing/node_modules/aws-sdk/clients/cognitoidentity"' has no exported member 'String'. package.json "name": "******", "version": "3.0.2", "license": "UNLICENSED", "config": "host": "****", "cloudfront": "******", "spechost": "******", "speccloudfront": "*******" , "scripts": , "private": true, "dependencies": "@angular/animations": "^6.1.2", "@angular/common": ...