Posts

Showing posts from June, 2012

Append To The End Of A List Javascript Code Example

Example 1: js add item to array const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi"); Example 2: how to push array //the array comes here var numbers = [1, 2, 3, 4]; //here you add another number numbers.push(5); //or if you want to do it with words var words = ["one", "two", "three", "four"]; //then you add a word words.push("five") //thanks for reading

Assembly - Carry Flag VS Overflow Flag

Answer : Overflow occurs when the result of adding two positive numbers is negative or the result of adding two negative numbers is positive. For instance: +127+1=? +127=0111 1111 +1=0000 0001 --------- 1000 0000 As we look at the sign bits of the two operands and the sign bit of the result, we find out that Overflow occurred and the answer is incorrect. In unsigned arithmetic, you have added 0xFB to 0x84 , i.e. 251 + 132, which indeed is larger than 8-bit, and so the carry flag is set. In the second case, you are adding +127 to 1, which indeed exceeds a signed 8-bit range, and so the overflow flag is set.

CefSharp LoadHtml

Answer : Update: CefSharp has a new LoadHtml(string html) method that loads the HTML as a base64-encoded data URI. It is more reliable that the LoadHtml(string html, string url) method described below. In LoadHtml(string html, string url) : html is your HTML string, e.g. "<html><body>Hello world</body></html>" . Actually, you can even put other content in the string, such as SVG markup, as long as Chromium can understand it. url is needed because your HTML code may contain JavaScript that tries to perform AJAX calls, and the web browser needs to understand what security restrictions apply. The scheme (e.g. "http:", "about:") and domain (e.g. "localhost", "google.com") affect behaviour such as clicking on links, AJAX requests, iframes, etc. If you want to simply render static HTML, make the url something unique such as http://rendering/ (so that the resource handler does not overlap with a

Bootstrap 4: Multilevel Dropdown Inside Navigation

Image
Answer : I use the following piece of CSS and JavaScript. It uses an extra class dropdown-submenu . I tested it with Bootstrap 4 beta. It supports multi level sub menus. $('.dropdown-menu a.dropdown-toggle').on('click', function(e) { if (!$(this).next().hasClass('show')) { $(this).parents('.dropdown-menu').first().find('.show').removeClass('show'); } var $subMenu = $(this).next('.dropdown-menu'); $subMenu.toggleClass('show'); $(this).parents('li.nav-item.dropdown.show').on('hidden.bs.dropdown', function(e) { $('.dropdown-submenu .show').removeClass('show'); }); return false; }); .dropdown-submenu { position: relative; } .dropdown-submenu a::after { transform: rotate(-90deg); position: absolute; right: 6px; top: .8em; } .dropdown-submenu .dropdown-menu { top: 0; left: 100%; margin-left: .1rem; margin-right: .1rem; } <link rel="s

Bootstrap Responsive Padding Css Code Example

Example 1: bootstrap Margin and padding Use the margin and padding spacing utilities to control how elements and components are spaced and sized. Bootstrap 4 includes a five-level scale for spacing utilities, based on a 1rem value default $spacer variable. Choose values for all viewports (e.g., .mr-3 for margin-right: 1rem), or pick responsive variants to target specific viewports (e.g., .mr-md-3 for margin-right: 1rem starting at the md breakpoint). < div class = " my-0 bg-warning " > Margin Y 0 </ div > < div class = " my-1 bg-warning " > Margin Y 1 </ div > < div class = " my-2 bg-warning " > Margin Y 2 </ div > < div class = " my-3 bg-warning " > Margin Y 3 </ div > < div class = " my-4 bg-warning " > Margin Y 4 </ div > < div class = " my-5 bg-warning " > Margin Y 5 </ div > < div class = " my-auto bg-warning &q

Codeceptjs Testing With TestCafe

Image
TestCafe (opens new window) is another alternative engine for driving browsers. It is driven by unique technology which provides fast and simple cross browser testing for desktop and mobile browsers. Unlike WebDriver or Puppeteer, TestCafe doesn't control a browser at all. It is not a browser itself, like Nightmare or Cypress. TestCafe core is a proxy server that runs behind the scene, and transforms all HTML and JS to include code that is needed for test automation. This is very smart idea. But to use TestCafe on daily basis you need to clearly understand its benefits and limitations: Pros Fast . Browser is controlled from inside a web page. This makes test run inside a browser as fast as your browser can render page with no extra network requests. Simple Cross-Browser Support. Because TestCafe only launches browsers, it can automate browser on desktop or mobile. Unlike WebDriver, you don't need special version of browser and driver to prepare to run tests. S

Arduino Due Vs Mega 2560

Answer : The 'R3' version boards and shields are compatible with 3.3V and 5V. For example the Ethernet Shield V1 version 'R3' can be used with the Due. The new Arduino Ethernet Shield 2 is also compatible with the Due. Many older shield are not compatible with the Due, but do you really need to use an old shield ? Most sensors are 3.3V, and also a SD memory card is 3.3V. That is a lot easer with the Arduino Due which runs at 3.3V. The Arduino Mega 2560 board is the only board with 10k pullup resistors at SDA and SCL, therefor it has a 5V I2C bus. When a 3.3V sensor with I2C is used, you need a I2C level shifter. When a 3.3V with SPI is used, you need more hardware. The Arduino Mega pins can drive more than 20mA, it can be used to drive 10 leds with 20mA simultaneously, the Arduino Due can't do that. My suggestion is to use an Arduino Uno for all kind of testing. It's always good to have one lying around. Start with an Arduino Uno if you want to learn

Conversion Int To String C++ Code Example

Example 1: change int to string cpp # include <string> std :: string s = std :: to_string ( 42 ) ; Example 2: convert integer to string c++ std :: to_string ( 23213.123 ) Example 3: convert int to string c++ int a = 10 ; stringstream ss ; ss << a ; string str = ss . str ( ) ;

Audio Recorder Software For Windows 10 Code Example

Example 1: audio recorder for pc 1f20cd153b2c322bf1ff9941e4e5204098abdc7da37250ce3fb38612b3e927ba Example 2: audio recorder for pc 0c14f7c6850c93b9dacc14fe66876b8dc3397d92dbd849898783a21bad1fff55

Bootstrap Vue Table: Show Details When Row Clicked

Answer : Hard to find... but just add this: @row-clicked="item=>$set(item, '_showDetails', !item._showDetails)" Explanation The $set preserves the reactivity even if _showDetails didn't exist. It's a pitty that the row object is not accessible, so toggleDetails is not an option here. As mentioned on the row details support section of the Bootstrap Vue table documentation, you can change the _showDetails property of the row item: If the record has it's _showDetails property set to true, and a row-details scoped slot exists, a new row will be shown just below the item, with the rendered contents of the row-details scoped slot. In your case, you would want something like: expandAdditionalInfo(row) { row._showDetails = !row._showDetails; }, As demonstrated in this codepen

Android Studio Lite Version Download Code Example

Example: android studio Android Studio is the official integrated development environment for Google's Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically for Android development.

8 Ft To Meter Code Example

Example: meter to feet 1 m = 3.28084 ft

Bsg Twitter Code Example

Example 1: twitter Don't relax go program and finish your projects! Example 2: twitter don't waste your time!!... keep on coding :)

Column Width Not Working In DataTables Bootstrap

Answer : When setting columns widths, you also need to set: autoWidth: false ...on the DataTable itself Would be nice to see your table in action, but I get a strong feeling that this is a pure matter of width of content. Elements with display: table-cell will try to expand in order to show as much as its content as possible without wrapping. For example, the width of the <th> that has the caption "Travel Protection", which you define as 10% - you would need a rather broad table to show "Travel Protection" within 10%. So overrule the default word-wrap and word-break settings for <th> like this : table.dataTable thead tr th { word-wrap: break-word; word-break: break-all; } a sort of demo (as said, cannot proof this to your table IRL) -> http://jsfiddle.net/9vbz7thp/ The best thing would be to adjust the content of the <th> 's so they fits to the hardcoded widths. If it is the content of the <td> 's tha

Change Cart Total Price In WooCommerce

Image
Answer : This does not answer this question. Loic's does. This is another way of doing it to show a line item of 10% off: function prefix_add_discount_line( $cart ) { $discount = $cart->subtotal * 0.1; $cart->add_fee( __( 'Down Payment', 'yourtext-domain' ) , -$discount ); } add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line' ); Since Woocommerce 3.2+ it does not work anymore with the new Class WC_Cart_Totals ... New answer: Change Cart total using Hooks in Woocommerce 3.2+ First woocommerce_cart_total hook is a filter hook, not an action hook. Also as wc_price argument in woocommerce_cart_total is the formatted price , you will not be able to increase it by 10%. That's why it returns zero. Before Woocommerce v3.2 it works as some WC_Cart properties can be accessed directly You should better use a custom function hooked in woocommerce_calculate_totals action hook this w

Center Button Under Form In Bootstrap

Answer : Remove that <p> tag and add the button inside a <div class="form-actions"> like this: <div class="form-actions"> <button type="submit" class="btn">Confirm</button> </div> an then augment the CSS class with: .form-actions { margin: 0; background-color: transparent; text-align: center; } Here's a JS Bin demo: http://jsbin.com/ijozof/2 Look for form-actions at the Bootstrap doc here: http://twitter.github.io/bootstrap/base-css.html#buttons With Bootstrap 3, you can use the 'text-center' styling attribute. <div class="col-md-3 text-center"> <button id="button" name="button" class="btn btn-primary">Press Me!</button> </div> If you're using Bootstrap 4 , try this: <div class="mx-auto text-center"> <button id="button" name="button" class=&quo

Android YouTubePlayer With Unauthorized Overlay On Top Of Player

Answer : I faced the same problem today, and for me the error in the logs was: W/YouTubeAndroidPlayerAPI﹕ YouTube video playback stopped due to unauthorized overlay on top of player. The YouTubePlayerView is not contained inside its ancestor com.google.android.youtube.player.YouTubePlayerView{42686bc8 V.E..... ........ 0,0-1200,675 #7f0a00a0 app:id/video_player}. The distances between the ancestor's edges and that of the YouTubePlayerView is: left: -10, top: -10, right: -10, bottom: -10 (these should all be positive). I fixed this by removing the padding in the YouTubePlayerView in the layout. So my layout looks like this: <com.google.android.youtube.player.YouTubePlayerView android:id="@+id/video_player" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000" /> I had the same error. Although I did the XML changes, I continued to receive the error: YouTube video p

Bring Element To Front Using CSS

Answer : Add z-index:-1 and position:relative to .content #header { background: url(http://placehold.it/420x160) center top no-repeat; } #header-inner { background: url(http://placekitten.com/150/200) right top no-repeat; } .logo-class { height: 128px; } .content { margin-left: auto; margin-right: auto; table-layout: fixed; border-collapse: collapse; z-index: -1; position:relative; } .td-main { text-align: center; padding: 80px 10px 80px 10px; border: 1px solid #A02422; background: #ABABAB; } <body> <div id="header"> <div id="header-inner"> <table class="content"> <col width="400px" /> <tr> <td> <table class="content"> <col width="400px" /> <tr>

Algorithm To Randomly Generate An Aesthetically-pleasing Color Palette

Image
Answer : You could average the RGB values of random colors with those of a constant color: (example in Java) public Color generateRandomColor(Color mix) { Random random = new Random(); int red = random.nextInt(256); int green = random.nextInt(256); int blue = random.nextInt(256); // mix the color if (mix != null) { red = (red + mix.getRed()) / 2; green = (green + mix.getGreen()) / 2; blue = (blue + mix.getBlue()) / 2; } Color color = new Color(red, green, blue); return color; } Mixing random colors with white (255, 255, 255) creates neutral pastels by increasing the lightness while keeping the hue of the original color. These randomly generated pastels usually go well together, especially in large numbers. Here are some pastel colors generated using the above method: You could also mix the random color with a constant pastel, which results in a tinted set of neutral colors. For example, using a light blue cr

How To Print Pointer Address In C Code Example

Example: how to print the address of a pointer in c int a = 42 ; printf ( "%p\n" , ( void * ) & a ) ;

Django Url Pass Parameter To View Code Example

Example 1: django slug int url mapping # in views define the int slugs then the url mapping is like this from django . urls import path , re_path from . import views urlpatterns = [ path ( 'articles/2003/' , views . special_case_2003 ) , re_path ( r '^articles/(?P<year>[0-9]{4})/$' , views . year_archive ) , re_path ( r '^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$' , views . month_archive ) , re_path ( r '^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<slug>[\w-]+)/$' , views . article_detail ) , ] Example 2: django get parameters from url message = request . GET . get ( 'message' )

Adding A Background Image To A Div Css Code Example

Example: how to add background in css body { background-image : url ( "paper.gif" ) ; background-color : #cccccc ; }