Posts

Showing posts from July, 2007

20 Lakh Rs To Usd Code Example

Example: 11 lakh to usd hmmm.... i know you are going to get this amount in your future... best of luck

Debug.log Unity Object Code Example

Example: debug.log unity Debug . Log ( "Hello, World" ) ;

Angular Material And Changing Fonts

Answer : You can use the CSS universal selector ( * ) in your CSS or SCSS : * { font-family: Raleway /* Replace with your custom font */, sans-serif !important; /* Add !important to overwrite all elements */ } Starting from Angular Material v2.0.0-beta.7 , you can customise the typography by creating a typography configuration with the mat-typography-config function and including this config in the angular-material-typography mixin: @import '~@angular/material/theming'; $custom-typography: mat-typography-config( $font-family: 'Raleway' ); @include angular-material-typography($custom-typography); Alternatively ( v2.0.0-beta.10 and up): // NOTE: From `2.0.0-beta.10`, you can now pass the typography via the mat-core() mixin: @import '~@angular/material/theming'; $custom-typography: mat-typography-config( $font-family: 'Raleway' ); @include mat-core($custom-typography); Refer to Angular Material's typography documentation for more

Calculate Distance Between Two Latitude-longitude Points? (Haversine Formula)

Answer : This link might be helpful to you, as it details the use of the Haversine formula to calculate the distance. Excerpt: This script [in Javascript] calculates great-circle distances between the two points – that is, the shortest distance over the earth’s surface – using the ‘Haversine’ formula. function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) { var R = 6371; // Radius of the earth in km var dLat = deg2rad(lat2-lat1); // deg2rad below var dLon = deg2rad(lon2-lon1); var a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon/2) * Math.sin(dLon/2) ; var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); var d = R * c; // Distance in km return d; } function deg2rad(deg) { return deg * (Math.PI/180) } I needed to calculate a lot of distances between the points for my project, so I went ahead and tried to optimize the code, I have found here. On average in different bro

Sprintf Php Calculation Code Example

Example 1: php sprintf There are already some comments on using sprintf to force leading leading zeros but the examples only include integers . I needed leading zeros on floating point numbers and was surprised that it didn't work as expected . Example : < ? php sprintf ( '%02d' , 1 ) ; ? > This will result in 01. However , trying the same for a float with precision doesn't work : < ? php sprintf ( '%02.2f' , 1 ) ; ? > Yields 1.00 . This threw me a little off . To get the desired result , one needs to add the precision ( 2 ) and the length of the decimal seperator "." ( 1 ) . So the correct pattern would be < ? php sprintf ( '%05.2f' , 1 ) ; ? > Output : 01.00 Please see http : //stackoverflow.com/a/28739819/413531 for a more detailed explanation. Example 2: php sprintf < ? php $num = 5 ; $location = 'tree' ; $format = 'There are %d monkeys in the %s' ; echo sp

C Fread Example

Defined in header <stdio.h> size_t fread ( void * buffer , size_t size , size_t count , FILE * stream ) ; (until C99) size_t fread ( void * restrict buffer , size_t size , size_t count , FILE * restrict stream ) ; (since C99) Reads up to count objects into the array buffer from the given input stream stream as if by calling fgetc size times for each object, and storing the results, in the order obtained, into the successive positions of buffer , which is reinterpreted as an array of unsigned char . The file position indicator for the stream is advanced by the number of characters read. If an error occurs, the resulting value of the file position indicator for the stream is indeterminate. If a partial element is read, its value is indeterminate. Parameters buffer - pointer to the array where the read objects are stored size - size of each object in bytes co

Convert List To Array In Java

Answer : Either: Foo[] array = list.toArray(new Foo[0]); or: Foo[] array = new Foo[list.size()]; list.toArray(array); // fill the array Note that this works only for arrays of reference types. For arrays of primitive types, use the traditional way: List<Integer> list = ...; int[] array = new int[list.size()]; for(int i = 0; i < list.size(); i++) array[i] = list.get(i); Update: It is recommended now to use list.toArray(new Foo[0]); , not list.toArray(new Foo[list.size()]); . From JetBrains Intellij Idea inspection: There are two styles to convert a collection to an array: either using a pre-sized array (like c.toArray(new String[c.size()]) ) or using an empty array (like c.toArray(new String[0]) . In older Java versions using pre-sized array was recommended, as the reflection call which is necessary to create an array of proper size was quite slow. However since late updates of OpenJDK 6 this call was intrinsified, making the performance of the empty a

Add Html To Each Element With Class Jquery Code Example

Example: jquery add div element $ ( '#someParent' ) . append ( '<div>I am new here</div>' ) ;

Three Way Comparison C++ Code Example

Example 1: three way comparison operator c++ //Since C++20 lhs <=> rhs The expression returns an object that - compares < 0 if lhs < rhs - compares > 0 if lhs > rhs - compares == 0 if lhs and rhs are equal / equivalent . Example 2: three-way comparison c++ lhs <=> rhs //Since C++20 The expression returns an object that : - compares < 0 if lhs < rhs - compares > 0 if lhs > rhs - compares == 0 if lhs and rhs are equal / equivalent .

Cannot Find Assert.Fail And Assert.Pass Or Equivalent

Answer : The documentation includes a comparison chart including this: Fail - xUnit.net alternative: Assert.True(false, "message") (It doesn't show Assert.Pass , and I've never used that myself, but I suspect the alternative is just to return from the test. Of course that doesn't help if you want to throw it in a nested method call. My suspicion is that it's not very frequently used in NUnit, hence its absence in the comparison chart.) An alternative to Assert.Fail("messsage") suggested by xUnit docs xUnit.net alternative: Assert.True(false, "message") has a downside – its output is message Expected: True Actual: False To get rid of Expected: True Actual: False don't call Assert.True(false, "message") throw Xunit.Sdk.XunitException instead. For example, create a helper method similar to this: public static class MyAssert { public static void Fail(string message) => thro

Converting A String To A Date In JavaScript

Answer : The best string format for string parsing is the date ISO format together with the JavaScript Date object constructor. Examples of ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS . But wait! Just using the "ISO format" doesn't work reliably by itself. String are sometimes parsed as UTC and sometimes as localtime (based on browser vendor and version). The best practice should always be to store dates as UTC and make computations as UTC. To parse a date as UTC, append a Z - e.g.: new Date('2011-04-11T10:20:30Z') . To display a date in UTC, use .toUTCString() , to display a date in user's local time, use .toString() . More info on MDN | Date and this answer. For old Internet Explorer compatibility (IE versions less than 9 do not support ISO format in Date constructor), you should split datetime string representation to it's parts and then you can use constructor using datetime parts, e.g.: new Date('2011', '04' - 1, '11'

Multiline Comment Html Code Example

Example 1: commenting in html <!-- a comment in html --> Example 2: html comment <! --This is a comment in html.--> <! --You can put comments enywhere! It does not care if it is mid peice of code in a peice of code! You must put the ending arrows in or it will think everything is a comment! Note you can comment over multiple lines. Use a ! at the start arrow , this may not make sence as the rest of html uses tags where ! is at the ends.--> Example 3: how to create comments in html5 Insert a single-line , or multi-line comment. Comments are designated by the tags <! -- and --> Use the comment function to hide scripts on unsupported browsers . If you are programming in JavaScript or VBScript , you can use the comment function to hide the script on browsers that don't support it. Insert the comment at the start of the script , and end it with //--> to ensure that the script works on browsers that do support it. Example 4: multiline comment html <

Computational Complexity Of Fibonacci Sequence

Answer : You model the time function to calculate Fib(n) as sum of time to calculate Fib(n-1) plus the time to calculate Fib(n-2) plus the time to add them together ( O(1) ). This is assuming that repeated evaluations of the same Fib(n) take the same time - i.e. no memoization is use. T(n<=1) = O(1) T(n) = T(n-1) + T(n-2) + O(1) You solve this recurrence relation (using generating functions, for instance) and you'll end up with the answer. Alternatively, you can draw the recursion tree, which will have depth n and intuitively figure out that this function is asymptotically O(2 n ) . You can then prove your conjecture by induction. Base: n = 1 is obvious Assume T(n-1) = O(2 n-1 ) , therefore T(n) = T(n-1) + T(n-2) + O(1) which is equal to T(n) = O(2 n-1 ) + O(2 n-2 ) + O(1) = O(2 n ) However, as noted in a comment, this is not the tight bound. An interesting fact about this function is that the T(n) is asymptotically the same as the value of Fib(n) since both are de

Convert Image To Text Google Online Code Example

Example: google image to text On your computer, go to drive.google.com. Right-click on the desired file. Click Open with. Google Docs. The image file will be converted to a Google Doc, but some formatting might not transfer: Bold, italics, font size, font type, and line breaks are most likely to be retained

Css Display-listitem Example

The list-item keyword causes the element to generate a ::marker pseudo-element with the content specified by its list-style properties (for example a bullet point) together with a principal box of the specified type for its own contents. Syntax A single value of list-item will cause the element to behave like a list item. This can be used together with list-style-type and list-style-position . list-item can also be combined with any <display-outside> keyword and the flow or flow-root <display-inside> keywords. Note : In browsers that support the two-value syntax, if no inner value is specified it will default to flow . If no outer value is specified, the principal box will have an outer display type of block . Examples HTML < div class = " fake-list " > I will display as a list item </ div > CSS .fake-list { display : list-item ; list-style-position : inside ; } Result Specifications Specification Status CSS Display M

Youtube-dl Get Mp3 Code Example

Example 1: youtube-dl mp3 only youtube - dl - x -- audio - format mp3 < youtube - link > Example 2: linux download youtube mp3 youtube - dl -- extract - audio -- audio - format mp3 < video URL >

How To Find The Angle Of A Triangle Given 3 Sides Code Example

Example: how to find a point on a triangle with only sides known sides AB , BC , AC known points A ( x , y ) , B ( x , y ) unknown points C ( x , y ) AC² - BC² = ( ( Ax - Cx ) ² + ( Ay - Cy ) ² ) - ( ( Bx - Cx ) ² + ( By - Cy ) ² ) Goal : C . x = ? C . y = ?

Check Empty List In Python Code Example

Example 1: check if list is empty python my_list = list ( ) # Check if a list is empty by its length if len ( my_list ) == 0 : pass # the list is empty # Check if a list is empty by direct comparison ( only works for lists ) if my_list == [ ] : pass # the list is empty # Check if a list is empty by its type flexibility **preferred method** if not my_list : pass # the list is empty Example 2: check if array is empty python a = [ ] if not a : print ( "List is empty" ) Example 3: check if list is empty python if len ( li ) == 0 : print ( 'the list is empty ' ) Example 4: how to tell if a list is empty in python if not a : print ( "List is empty" ) Example 5: empty list check in python if not a : print ( "List is empty" ) Example 6: can python tell if a list is empty >> > if len ( a ) == 0 : print ( "list is empty" ) else : print ( "list is not empty" )

How To Create Whatsapp Link Code Example

Example: link whatsapp to website < ! -- link the following URL to the desired icon or button in your code : https : //wa.me/PhoneNumber (see the example below) remember to include the country code -- > < a href = 'https://wa.me/27722840005' target = '_blank' > < i class = "fa fa-whatsapp" > < / i > < / a >