Posts

Showing posts from August, 2003

C++ Std:.endl Code Example

Example: std ::endl # include <iostream> # include <chrono> template < typename Diff > void log_progress ( Diff d ) { std :: cout << std :: chrono :: duration_cast < std :: chrono :: milliseconds > ( d ) . count ( ) << " ms passed" << std :: endl ; } int main ( ) { std :: cout . sync_with_stdio ( false ) ; // on some platforms, stdout flushes on \n volatile int sink = 0 ; auto t1 = std :: chrono :: high_resolution_clock :: now ( ) ; for ( int j = 0 ; j < 5 ; ++ j ) { for ( int n = 0 ; n < 10000 ; ++ n ) for ( int m = 0 ; m < 20000 ; ++ m ) sink += m * n ; // do some work auto now = std :: chrono :: high_resolution_clock :: now ( ) ; log_progress ( now - t1 ) ; } }

How Many Passes Does An Insertion Sort Algorithm Consist Of? Code Example

Example: what is time complexity of insertion sort Time Complexity is : If the inversion count is O ( n ) , then the time complexity of insertion sort is O ( n ) . Some Facts about insertion sort : 1. Simple implementation : Jon Bentley shows a three - line C version , and a five - line optimized version [ 1 ] 2. Efficient for ( quite ) small data sets , much like other quadratic sorting algorithms 3. More efficient in practice than most other simple quadratic ( i . e . , O ( n2 ) ) algorithms such as selection sort or bubble sort 4. Adaptive , i . e . , efficient for data sets that are already substantially sorted : the time complexity is O ( kn ) when each element in the input is no more than k places away from its sorted position 5. Stable ; i . e . , does not change the relative order of elements with equal keys 6. In - place ; i . e . , only requires a constant amount O ( 1 ) of additional memory space Online ; i . e . , can sort a list a

Define Escape Sequences In Java? Give Two Escape Sequences. Code Example

Example: c escape characters Escape HEX in ASCII Character represented \a 07 Alert ( Beep , Bell ) ( added in C89 ) \b 08 Backspace \e 1 B Escape character \f 0 C Formfeed Page Break \n 0 A Newline ( Line Feed ) ; see notes below \r 0 D Carriage Return \t 09 Horizontal Tab \v 0 B Vertical Tab \\ 5 C Backslash \' 27 Apostrophe or single quotation mark \" 22 Double quotation mark \ ? 3F Question mark ( used to avoid trigraphs ) \nnn any The byte whose numerical value is given by nnn interpreted as an octal number \xhh… any The byte whose numerical value is given by hh… interpreted as a hexadecimal number \uhhhh none Unicode code point below 10000 hexadecimal \Uhhhhhhhh none Unicode code point where h is a hexadecimal digit

Change Timezone In Laravel

Answer : go to the file config/app.php and look for this entry: /* |-------------------------------------------------------------------------- | Application Timezone |-------------------------------------------------------------------------- | | Here you may specify the default timezone for your application, which | will be used by the PHP date and date-time functions. We have gone | ahead and set this to a sensible default for you out of the box. | */ 'timezone' => 'Asia/Tehran', //There will be default 'UTC' here As you can see, UTC is a default value for Laravel. So you can easily change it here to, like: 'timezone' => 'Asia/Tehran', - See full list PHP Supported Timezones After changes app.php you should run this command php artisan config:cache After update app.php run below command and check php artisan config:cache php artisan cache:clear You can create below type of route for clear cache in laravel Route::get(&

Android Studio Suddenly Cannot Resolve Symbol R

Answer : Most of the time it is due to a bad XML file. XML files can be layout files, value files, or the Manifest file. Please check your xml files and try to rebuild the project. Sometimes cleaning the project and rebuilding it also works. In addition, make sure you do not have a drawable with an invalid name. I had a drawable with a numeric filename and that didn't sit well with Android so it failed to compile R.java. Downgrade Your Gradle Plugin Version No amount of cleaning, rebuilding and restarting would do the trick for me. The only thing that did the trick was downgrade our Gradle version from 3.4.0-alpha02 to 3.2.1 . So, instead of: dependencies { classpath 'com.android.tools.build:gradle:3.4.0-alpha02' } We used: dependencies { classpath 'com.android.tools.build:gradle:3.2.1' } After making that change and then doing a Gradle sync, everything worked. Not sure if it's related to the alpha release or to that version or if

3 Horizontall Lines With Different Length Symbol Code Html Code Example

Example 1: horizontal line html <!-- code --> <hr> <!-- code --> Example 2: which is right or in html <hr> <!-- it represents a horizontal line break , in HTML4.0 we use <hr> , in XHTML1.0 we use <hr/> , in HTML5 ( which is the current version of HTML ) we can use both <hr> and <hr/> -->

Can I Combine Two Internet Connections Into One PC Using Only A Switch?

Answer : The easiest way to configure this would be to use a Multi-WAN router such as the Linksys RV042. Technically: yes In practice, it's an exotic and expensive configuration. You can put more than one address on an interface or use more than one interface and be multihomed . However, this is much more likely to be effective for a big server cluster in a data center. Expensive routers capable of running routing protocols will be needed and then it still would not help you with a single given TCP connection. If you try this as a single user of two retail ISPs, then you will have two different IP addresses, so incoming traffic will use the one you made the outbound connection on, and it's unlikely that any equipment you have can be configured with more than one gateway. A large site with a /24 or shorter prefix and their own ASN can actually announce a single IP address over multiple networks, but that won't work without being further upstream than a retail

Center Content In Responsive Bootstrap Navbar

Answer : I think this is what you are looking for. You need to remove the float: left from the inner nav to center it and make it a inline-block. .navbar .navbar-nav { display: inline-block; float: none; vertical-align: top; } .navbar .navbar-collapse { text-align: center; } http://jsfiddle.net/bdd9U/2/ Edit: if you only want this effect to happen when the nav isn't collapsed surround it in the appropriate media query. @media (min-width: 768px) { .navbar .navbar-nav { display: inline-block; float: none; vertical-align: top; } .navbar .navbar-collapse { text-align: center; } } http://jsfiddle.net/bdd9U/3/ The original post was asking how to center the collapsed navbar. To center elements on the normal navbar, try this: .navbar-nav { float:none; margin:0 auto; display: block; text-align: center; } .navbar-nav > li { display: inline-block; float:none; } There's another way to d

Check Array Length Python Code Example

Example 1: python get array length # To get the length of a Python array, use 'len()' a = arr.array(‘d’, [1.1, 2.1, 3.1]) len(a) # Output: 3 Example 2: find array length in python a=arr.array('d', [1.1 , 2.1 ,3.1] ) len(a)

Android Resource Linking Failed' Code Example

Example: android resource linking failed Change the following settings in build . gradle file to : classpath 'com.android.tools.build:gradle:3.4.2'

Add Stripe Bank Account Api Code Example

Example: stripe api accounts transfer to bank EDIT: On newer API versions (>= 2017-04-06), "internal transfers" are now simply known as "transfers", and "external transfers" are now known as "payouts". Cf. this doc page for more information.

Can I Create A Flow Chart (no Tree Chart) Using D3.js

Image
Answer : can I create a flowchart like this one? D3 is capable of doing it. starting form a json object using the D3.js library? Yes What should the json structure look like? Depends on how you approach the project. I'm using force layout and removing the force, so my JSON is {node: [{ id: 1, title: 'title' }], link: [{ source: 0, target: 1 }] } Have you got any example I can analyse? For your inspiration http://marvl.infotech.monash.edu/webcola/ http://www.coppelia.io/2014/07/an-a-to-z-of-extra-features-for-the-d3-force-layout/ Starting point https://github.com/mbostock/d3/wiki/Force-Layout how to wrap your text in block http://bl.ocks.org/mbostock/7555321 D3.js is not suited very well for this kind of visualization. The visualization is just too complex to do a simple mapping from data to SVG Not sure why, but IMO flowcharts are one of the simplest types of diagrams, blocks and lines that c

15000 Euro To Inr Code Example

Example: 15000 usd to bdt 1 usd = approx 80 bdt

C Split String By Space Into Array Code Example

Example 1: split string at space C char * string ; char * first ; char * second ; for ( int i = 0 ; i <= strlen ( string ) ; i ++ ) { if ( string [ i ] == ' ' ) { string [ i ] = '\0' ; first = string ; second = string + i + 1 ; break ; } } Example 2: arduino c string split by delimiter /* Original code on Stackoverflow https://stackoverflow.com/questions/29671455/how-to-split-a-string-using-a-specific-delimiter-in-arduino Example : String str = "1,2,3"; String part01 = getValue(str,';',0); // get 1 String part02 = getValue(str,';',1); // get 2 String part03 = getValue(str,';',2); // get 3 String part03 = getValue(str,';',4); // get empty string Documented by issa loubani, your average programmer :P */ // Happy coding O.O String getValue ( String data , char separator , int index ) { int found = 0 ; int strIndex [ ] = { 0 , - 1

Adding Music Html Code Example

Example: how to add Music to body html < !DOCTYPE html > < html > < head > < title > HTML background music < / title > < / head > < body > < p > The music is running in the background . < / p > < p > ( Song : Kalimba which is provided as a Sample Music in Windows ) < / p > < embed src = "/html/Kalimba.mp3" loop = "true" autostart = "true" width = "2" height = "0" > < / body > < / html >

Change CSS Variable Using JQuery

Answer : You may change the css variable using plain JavaScript elem.style.setProperty("variableName", "variableProp"); $("html").on('click', function() { $("body").get(0).style.setProperty("--color", "hotpink"); }); body { --color: blue; background-color: var(--color); } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> click me! Simplest solution IMHO: Change a class, that in turn changes the default color: html { --defaultColor: teal; } html.someOtherDefaultColor { --defaultColor: rebeccapurple; } $("#clickToChange").click(function(){ $(html).toggleClass("someOtherDefaultColor"); }); See question Setting a CSS custom property (aka CSS variable) through JavaScript or jQuery The method in question is document.body.style.setProperty($property, value); where $property is the CSS variable.

What Cout Means In C++ Code Example

Example 1: cout value c++ # include <iostream> using namespace std ; int main ( ) { int a , b ; char str [ ] = "Hello Programmers" ; /* Single insertion operator */ cout << "Enter 2 numbers - " ; cin >> a >> b ; cout << str ; cout << endl ; /* Multiple insertion operator */ cout << "Value of a is " << a << endl << "Value of b is " << b ; return 0 ; } Example 2: how to cout in c++ std :: cout << "Hello World!" << std :: endl ; //Or you can do std :: cout << "Hello World!" << ; //Only in some scenarios

Chrome Extension Id - How To Find It

Answer : Use the chrome.runtime.id property from the chrome.runtime API. You get an extension ID when you upload your extension to Google Web Store. Ie. Adblock has URL https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaibdccddilifddb and the last part of this URL is its extension ID cfhdojbkjhnklbpkdaibdccddilifddb . If you wish to read installed extension IDs from your extension, check out the managment module. chrome.management.getAll allows to fetch information about all installed extensions. If you just need to do it one-off, navigate to chrome://extensions . Enable Developer Mode at upper right. The ID will be shown in the box for each extension. Or, if you're working on developing a userscript or extension, purposefully throw an error. Look in the javascript console, and the ID will be there, on the right side of the console, in the line describing the error. Lastly, you can look in your chrome extensions directory; it stores extensions in director