天道酬勤,学无止境

技术分享

How to pick proper video dimension based on device resolution

Question We've a demo video provided by design team with three different dimension (1024*768), (2048*1536) and (2732, 2048). I'm trying to pick proper video based on current device resolution (supported format). For eg: If it its first generation iPad its resolution is (1024 * 768) it can play video format upto 720p more than that it will not play, likewise iPad3 (Retina) resolution is (2048 * 1536) but it can play video format upto 1080p. Similar iPad pro I guess it will play upto 4k videos. I afraid system will not pick proper video on its own if we name it to 1x, 2x or 3x like in image. If

2022-01-25 05:42:53   ios   ipad   video   screen-resolution

Remove object from firebase using JavaScript

Question I am setting some objects on firebase-database, and showing them on a HTML table with 'child_added' and append() to dynamically add them as soon as they are added to the database, and there has to be a delete button on each row of the table, but the problem is, I can't get this delete button to work... This is how the database structure looks like: Assets: { -KkBgUmX6BEeVyrudlfK: { id: '-KkBgUmX6BEeVyrudlfK', name: 'John', brand: 'HP' } -KkDYxfwka8YM6uFOWpH: { id: '-KkDYxfwka8YM6uFOWpH', name: 'Jack', brand: 'Dell' } } And this is my index.js: var rootRef = firebase.database().ref()

2022-01-25 05:42:48   javascript   jquery   html   firebase   firebase-realtime-database

SonarQube java.lang.ClassCastException: ParametrizedTypeJavaType cannot be cast to ParametrizedTypeJavaType

Question I am trying to make my own SonarQube rule, the objective of the rule is to check that I am not using the contains method on a collection of a specific object. Example with Integer Object : List<Integer> a = new ArrayList<>(); a.contains(1); // Noncompliant To do that I am trying to get the ParametrizedTypeJavaType. Then I will be able to test if it is an Integer or not ... @Override public void visitNode(Tree tree) { MethodInvocationTree methodInvocationTree = (MethodInvocationTree) tree; ExpressionTree expressionTree = ((MethodInvocationTree) tree).methodSelect(); if(expressionTree

2022-01-25 05:42:43   java   sonarqube

Element wise average of structure fields with arrays

Question I have a structure called "xyz" with the following contents. How can I make a new variable (a 141x136 double) having an element wise average of the fields. Answer1 You can follow these steps: Convert the struct to a cell array. Generate a comma-separated list from the cell, and concatenate the cells' contents along the third dimension, producing a 3D numeric array. Compute the mean along the 3rd dimension. Example: xyz.v1 = ones(5,6); xyz.v2 = 2*ones(5,6); % example data c = struct2cell(xyz); % step 1 c = cat(3, c{:}); % step 2 result = mean(c, 3); % step 3 Consider if you really need

2022-01-25 05:42:37   matlab   struct

Get the total cookie size of a website given its header

Question My problem is simple, I have to get the total cookie size (by bytes). I used the Http Header and called the set-cookie element: public static String getCookiesField(URLConnection connection){ return connection.getHeaderField("Set-Cookie"); // it can return null } I get the result of the field as: dwsid=H-GOhXnQOVZU1SKVvlnOMJOYZq5CNAs9AUYMWArBVV00TnFO3a8VgoaUtl6wpJqgKWkidqt-y1ihDRm9yo3a7g==; path=/; HttpOnly I don't know what it mean but I need to get the size of the cookie by bytes. Answer1 Call getBytes() on the string of the cookie. If you're unsure what the cookie is, mdn can help

2022-01-25 05:42:27   java   http   header   session-cookies

Queries and Commits take longer as the session lives on

Question I use Fluent NHibernate to import data into a SQL Server Database. I used Automapping on my entities (which worked perfectly) Fluently.Configure(nhibernateConfig_) .Mappings(map_ => map_.AutoMappings.Add(AutoMap .AssemblyOf<EntityMapping>(new AutomapConfiguration()) .UseOverridesFromAssemblyOf<EntityMapping>() .Conventions.AddFromAssemblyOf<EntityMapping>())); and use QueryOver to get data from the database public AttributeTranslation GetOrCreateAttributeTranslation(Attribute attribute_, string language_) { AttributeTranslation translation = _session .QueryOver<AttributeTranslation>()

2022-01-25 05:42:22   performance   nhibernate   fluent-nhibernate

ADLA job is not producing expected results

Question I am processing data in U-SQL but not getting expected results. Here is what I am doing: 1- Select data from ADL table partitions and assign it to @data1 2- Aggregate data using Group BY and assign it to @data2 3- Truncate partitions 4- Insert data(produced in step 2) into the same table 5- Use @data2 and generate a unique GUID for every record using user defined function and assign it to @data2 //UDF Code public static Guid GetNewGuid () { return Guid.NewGuid (); } 6- Select few columns from @data2 and assign it to @data3 Strangely GUIDs in @data2 and @data3 are totally different. If

2022-01-25 05:42:18   azure-data-lake   u-sql

How to automate the creation of String elements with datetime

Question This thread arises from my previous question. I need to create Seq[String] that contains paths as String elements, however now I also need to add numbers 7,8,...-22 after a date. Also I cannot use LocalDate as it was suggested in the answer to the above-cited question: path/file_2017-May-1-7 path/file_2017-May-1-8 ... path/file_2017-May-1-22 path/file_2017-April-30-7 path/file_2017-April-30-8 ... path/file_2017-April-30-22 .. I am searching for a flexible solution. My current solution implies the manual definition of dates yyyy-MMM-dd. However it is not efficient if I need to include

2022-01-25 05:42:07   scala

bash extract xml attribute value using xmllint

Question I am extracting an attribute value from xml file, but I get an error. I'd like to extract the value for key="qua" in the firstpart element. Here is my script, but below you find the errors: #!/bin/bash myfile=$1 myvar=$(echo 'cat //firstpart/step/category/id/info[@key="qua"]/@value' | xmllint --xpath "$myfile" | awk -F'[="]' '!/>/{print $(NF-1)}') echo "$myvar" how my xml file looks like: <?xml version='1.0' encoding='UTF-8'?> <firstpart> <step name="Home"> <category name="one"> <id name="tools"> <info key="qua" value="1"/> </id> </category> </step> <step name="Contact"> <category

2022-01-25 05:42:03   xml   bash   shell   awk   xmllint

Preventing Conditional INSERT/UPDATE Race Condition in MS-SQL

Question I wonder that do i follow correct approach and need your help to figure out Here my non-protected query DECLARE @cl_WordId bigint = NULL SELECT @cl_WordId = cl_WordId FROM tblWords WHERE cl_Word = @cl_Word AND cl_WordLangCode = @cl_WordLangCode IF (@cl_WordId IS NULL) BEGIN INSERT INTO tblWords (cl_Word, cl_WordLangCode, cl_SourceId) VALUES (@cl_Word, @cl_WordLangCode, @cl_SourceId) SET @cl_WordId = SCOPE_IDENTITY() SELECT @cl_WordId END ELSE BEGIN SELECT @cl_WordId END And to protect it, i modify it as below DECLARE @cl_WordId bigint = NULL SELECT @cl_WordId = cl_WordId FROM tblWords

2022-01-25 05:41:58   sql   sql-server   conditional   sql-server-2016