Posts

Showing posts from February, 2018

Css Smooth Scroll Code Example

Example 1: smooth scroll css html { scroll-behavior: smooth; } /* No support in IE, or Safari You can use this JS polyfill for those */ http://iamdustan.com/smoothscroll/ Example 2: how to smooth scroll in javascript window.scrollTo({ top: 900, behavior: 'smooth' }) Example 3: smooth scroll html < script src = " https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js " > </ script > < script > $ ( document ) . ready ( function ( ) { // Add smooth scrolling to all links $ ( "a" ) . on ( 'click' , function ( event ) { // Make sure this.hash has a value before overriding default behavior if ( this . hash !== "" ) { // Prevent default anchor click behavior event . preventDefault ( ) ; // Store hash var hash = this . hash ; // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it

Conditional SQL Count

Answer : Use the aggregate FILTER option in Postgres 9.4 or later: SELECT category , count(*) FILTER (WHERE question1 = 0) AS zero , count(*) FILTER (WHERE question1 = 1) AS one , count(*) FILTER (WHERE question1 = 2) AS two FROM reviews GROUP BY 1; Details for the FILTER clause: Aggregate columns with additional (distinct) filters If you want it short : SELECT category , count(question1 = 0 OR NULL) AS zero , count(question1 = 1 OR NULL) AS one , count(question1 = 2 OR NULL) AS two FROM reviews GROUP BY 1; Overview over possible variants: For absolute performance, is SUM faster or COUNT? Proper crosstab query crosstab() yields the best performance and is shorter for longer lists of options: SELECT * FROM crosstab( 'SELECT category, question1, count(*) AS ct FROM reviews GROUP BY 1, 2 ORDER BY 1, 2' , 'VALUES (0), (1), (2)' ) AS ct (category text, zero int, one int, two int); Detailed explanation

Converting From IEnumerable To List

Image
Answer : You can do this very simply using LINQ. Make sure this using is at the top of your C# file: using System.Linq; Then use the ToList extension method. Example: IEnumerable<int> enumerable = Enumerable.Range(1, 300); List<int> asList = enumerable.ToList(); In case you're working with a regular old System.Collections.IEnumerable instead of IEnumerable<T> you can use enumerable.Cast<object>().ToList() If you're using an implementation of System.Collections.IEnumerable you can do like following to convert it to a List . The following uses Enumerable.Cast method to convert IEnumberable to a Generic List . //ArrayList Implements IEnumerable interface ArrayList _provinces = new System.Collections.ArrayList(); _provinces.Add("Western"); _provinces.Add("Eastern"); List<string> provinces = _provinces.Cast<string>().ToList(); If you're using Generic version IEnumerable<T> , The conversion is straight forward.

Android Project, Change Firebase Account

Answer : Follow the below steps, to switch firebase account Go to your firebase console, and select the project you want to shift Select the icon besides the project name on top right. Select Permissions from the flyout. You've reached the IAM & Admin page of firebase. Click on +Add button on top. Enter the email ID of the account to transfer the project to. In the dropdown, Select a role > Project > Owner. Click add Check mail in the email added above. Accept the invite, and go to IAM & Admin page of the transferred project. Use remove button to delete the previous user Hope this helps. 1- Yes, it's possible and you can follow this tutorial to do so. 2- If you want to simply switch projects, generate a new JSON on the console and remove the old one. If you want to migrate your database, it's possible, just check this question. 3- Both answers are "yes" so, try them out.

Java Return Multiple Values From Method Code Example

Example: how to return two values from a function in java int [ ] ans = new int [ 2 ] ; ans [ 0 ] = a + b ; ans [ 1 ] = a - b ; return ans ;

Can't Install PgAdmin 4 On 20.04 LTS

Answer : I was able to install pgadmin4 on ubuntu 20.04 (focal fossa) using the following article as a base: https://linuxhint.com/install-pgadmin4-ubuntu/ A few changes to the instructions are required: In part 2: sudo apt-get install build-essential libssl-dev libffi-dev libgmp3-dev sudo apt-get install python3-virtualenv libpq-dev python3-dev In part 5: The latest version for the moment is: https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v4.20/pip/pgadmin4-4.20-py2.py3-none-any.whl (I used release, not a daily snapshot) In part 6: Use pip install pgadmin4-4.20-py2.py3-none-any.whl In part 7: Use 'python3.8' instead of 'python2.7' That's all. Worked for me. Update: Please note that it's possible install pgadmin4 (4.21) directly from the repositories now. The problem of the upstream debian repository was the python 3.8 support. They said that was fixed in this commit, but they are apparently missing this: https://github.com/postgre

Converting ISO 8601-compliant String To Java.util.Date

Answer : Unfortunately, the time zone formats available to SimpleDateFormat (Java 6 and earlier) are not ISO 8601 compliant. SimpleDateFormat understands time zone strings like "GMT+01:00" or "+0100", the latter according to RFC # 822. Even if Java 7 added support for time zone descriptors according to ISO 8601, SimpleDateFormat is still not able to properly parse a complete date string, as it has no support for optional parts. Reformatting your input string using regexp is certainly one possibility, but the replacement rules are not as simple as in your question: Some time zones are not full hours off UTC, so the string does not necessarily end with ":00". ISO8601 allows only the number of hours to be included in the time zone, so "+01" is equivalent to "+01:00" ISO8601 allows the usage of "Z" to indicate UTC instead of "+00:00". The easier solution is possibly to use the data type converter in JAXB, since JAXB m

Creating Xor Checksum Of All Bytes In Hex String In Python

Answer : You have declared packet as the printable representation of the message: packet = '0x8d 0x1e 0x19 0x1b 0x83 0x00 0x01 0x01 0x00 0x00 0x00 0x4b 0x00 0x00' so your current message is not [0x8d, 0x1e, ..., 0x00] , but ['0', 'x', '8', 'd', ..., '0'] instead. So, first step is fixing it: packet = '0x8d 0x1e 0x19 0x1b 0x83 0x00 0x01 0x01 0x00 0x00 0x00 0x4b 0x00 0x00' packet = [chr(int(x, 16)) for x in packet.split(' ')] Or, you could consider encoding it "right" from the beginning: packet = '\x8d\x1e\x19\x1b\x83\x00\x01\x01\x00\x00\x00\x4b\x00\x00' At this point, we can xor, member by member: checksum = 0 for el in packet: checksum ^= ord(el) print checksum, hex(checksum), chr(checksum) the checksum I get is 0x59 , not 0xc2 , which means that either you have calculated the wrong one or the original message is not the one you supplied.

Button Onclick Unity Code Example

Example 1: unity assign button onclick public Button yourButton ; void Start ( ) { Button btn = yourButton . GetComponent < Button > ( ) ; //Grabs the button component btn . onClick . AddListener ( TaskOnClick ) ; //Adds a listner on the button } void TaskOnClick ( ) { Debug . Log ( "You have clicked the button!" ) ; } Example 2: how to code button click unity using UnityEngine ; using UnityEngine . UI ; using System . Collections ; public class ClickExample : MonoBehaviour { public Button yourButton ; void Start ( ) { Button btn = yourButton . GetComponent < Button > ( ) ; btn . onClick . AddListener ( TaskOnClick ) ; } void TaskOnClick ( ) { Debug . Log ( "You have clicked the button!" ) ; } } Example 3: unity onclick object void Update ( ) { } void OnMouseDown ( ) { // this object was clicked - do something Destroy ( this . gameObject

Remove React Bootstrap Footer White Space Below Footer Code Example

Example: css remove white space below footer <body > <section > This is content of the page </section > <footer > Text of footer </footer > </body > section { min-height : 100 vh ; /* minus the height of the footer */ }

Conda Delete Environment By Path Code Example

Example 1: conda remove environment conda remove --name myenv --all Example 2: conda list environments conda info --envs Example 3: how to see all the environments in Conda conda env list Example 4: remove a conda environment conda env remove --name < name > --all

Addforce Unity 2d Code Example

Example: how to make rb.addforce 2d public Rigidbody rb ; //make reference in Unity Inspector public float SpeedX = 0.1f ; public float SpeedY = 0.5f ; rb . AddForce ( new Vector2 ( SpeedX , SpeedY ) ) ;

Calculating Just A Specific Property In Regionprops Python

Answer : There seems to be a more direct way to do the same thing using regionprops with cache=False . I generated labels using skimage.segmentation.slic with n_segments=10000 . Then: rps = regionprops(labels, cache=False) [r.area for r in rps] My understanding of the regionprops documentation is that setting cache=False means that the attributes won't be calculated until they're called. According to %%time in Jupyter notebook, running the code above took 166ms with cache=False vs 247ms with cache=True , so it seems to work. I tried an equivalent of the other answer and found it much slower. %%time ard = np.empty(10000, dtype=int) for i in range(10000): ard[i] = size(np.where(labels==0)[1]) That took 34.3 seconds. Here's a full working example comparing the two methods using the skimage astronaut sample image and labels generated by slic segmentation: import numpy as np import skimage from skimage.segmentation import slic from skimage.data import a

CSS: Transition Opacity On Mouse-out?

Answer : You're applying transitions only to the :hover pseudo-class, and not to the element itself. .item { height:200px; width:200px; background:red; -webkit-transition: opacity 1s ease-in-out; -moz-transition: opacity 1s ease-in-out; -ms-transition: opacity 1s ease-in-out; -o-transition: opacity 1s ease-in-out; transition: opacity 1s ease-in-out; } .item:hover { zoom: 1; filter: alpha(opacity=50); opacity: 0.5; } Demo: http://jsfiddle.net/7uR8z/6/ If you don't want the transition to affect the mouse-over event, but only mouse-out , you can turn transitions off for the :hover state : .item:hover { -webkit-transition: none; -moz-transition: none; -ms-transition: none; -o-transition: none; transition: none; zoom: 1; filter: alpha(opacity=50); opacity: 0.5; } Demo: http://jsfiddle.net/7uR8z/3/

Android Debug Keystore Code Example

Example 1: download debug.keystore keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" Example 2: android create keystore command line keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Alter Auto_increment Code Example

Example 1: auto_increment mysql ALTER TABLE User AUTO_INCREMENT = 1 ; Example 2: alter table auto_increment ALTER TABLE ALLITEMS CHANGE itemid itemid INT ( 10 ) AUTO_INCREMENT PRIMARY KEY ;

Spirally Traversing A Matrix Code Example

Example: spiral order matrix traversal in C++ vector < int > Solution :: spiralOrder ( const vector < vector < int > > & A ) { int row_start = 0 , row_end = A . size ( ) - 1 , col_start = 0 , col_end = A [ 0 ] . size ( ) - 1 ; vector < int > v ; while ( row_start <= row_end && col_start <= col_end ) { //for row_start for (int col = col_start; col<=col_end; col++) { v.push_back(A[row_start][col]); } row_start++; //for col_end for (int row = row_start; row<= row_end; row++) { v.push_back(A[row][col_end]); } col_end--; //for row_end for (int col = col_end; col>=col_start; col--) { v.push_back(A[row_end][col]); } row_end--; //for col_start for (int row = row_end; row>=row_start; row--) { v.push_back(A[row][col_start]); }

Create Folders In Github Repository Code Example

Example 1: how to create folder in github You cannot create an empty folder and then add files to that folder, but rather creation of a folder must happen together with adding of at least a single file. On GitHub you can do it this way: Go to the folder inside which you want to create another folder Click on New file On the text field for the file name, first write the folder name you want to create Then type /. This creates a folder You can add more folders similarly Finally, give the new file a name (for example, .gitkeep which is conventionally used to make Git track otherwise empty folders; it is not a Git feature though) Finally, click Commit new file. Example 2: github create directory touch README.md nano README.md #### ADD YOUR INFORMATION #### Press: control + X #### Type: Y #### Press: enter