Posts

Showing posts from February, 2010

Angular 2 NgModelChange Old Value

Answer : This might work (ngModelChange)="onModelChange(oldVal, $event); oldVal = $event;" or (ngModelChange)="onModelChange($event)" oldValue:string; onModelChange(event) { if(this.oldValue != event) { ... } this.oldValue = event; } Just for the future we need to observe that [(ngModel)]="hero.name" is just a short-cut that can be de-sugared to: [ngModel]="hero.name" (ngModelChange)="hero.name = $event". So if we de-sugar code we would end up with: <select (ngModelChange)="onModelChange()" [ngModel]="hero.name" (ngModelChange)="hero.name = $event"> or <[ngModel]="hero.name" (ngModelChange)="hero.name = $event" select (ngModelChange)="onModelChange()"> If you inspect the above code you will notice that we end up with 2 ngModelChange events and those need to be executed in some order. Summing up: If you place ngModelChange befor

Can I Use An Xbox 360 Controller To Play Xbox One?

Answer : The Xbox One cannot directly accept input from an Xbox 360 controller - however, with Windows 10, there is a work around. Windows 10 allows you to set up your Xbox One to stream to your computer. While streaming to your computer, you are directed to connect the controller into the computer, not the Xbox One. In this form, Xbox 360 controllers will work for playing Xbox One games. You can directly plug in a wired controller, or use an adapter, if you are using the wireless controllers.

Pure CSS Background Animation CodePen Code Example

Example: background image animation css codepen Refer to this link for many options https : //codepen.io/collection/Iolmb?cursor=ZD0xJm89MSZwPTEmdj0z

Crawling Multiple URLs In A Loop Using Puppeteer

Answer : map , forEach , reduce , etc, does not wait for the asynchronous operation within them, before they proceed to the next element of the iterator they are iterating over. There are multiple ways of going through each item of an iterator synchronously while performing an asynchronous operation, but the easiest in this case I think would be to simply use a normal for operator, which does wait for the operation to finish. const urls = [...] for (let i = 0; i < urls.length; i++) { const url = urls[i]; await page.goto(`${url}`); await page.waitForNavigation({ waitUntil: 'networkidle2' }); } This would visit one url after another, as you are expecting. If you are curious about iterating serially using await/async, you can have a peek at this answer: https://stackoverflow.com/a/24586168/791691 The accepted answer shows how to serially visit each page one at a time. However, you may want to visit multiple pages simultaneously when the task is embarrassingly pa

Queues And Stacks Hackerrank Solution In Java Code Example

Example: queue using two stacks hackerrank solution # include <stack> # include <iostream> using namespace std ; int main ( ) { stack < int > Front , Rear ; int Q ; cin >> Q ; while ( Q -- ) { int type , x ; cin >> type ; if ( type == 1 ) { cin >> x ; Rear . push ( x ) ; } else { if ( Front . empty ( ) ) { // move all the elements from "Rear" stack to "Front" stack while ( ! Rear . empty ( ) ) { Front . push ( Rear . top ( ) ) ; Rear . pop ( ) ; } } if ( ! Front . empty ( ) ) { if ( type == 2 ) Front . pop ( ) ; if ( type == 3 ) cout << Front . top ( ) << endl ; } }

Angular Material Customize Tab

Answer : In your component, set ViewEncapsulation to None and add the styles in your component.css file. Changes in Typescript code: import {Component, ViewEncapsulation} from '@angular/core'; @Component({ .... encapsulation: ViewEncapsulation.None }) Component CSS: /* Styles for tab labels */ .mat-tab-label { min-width: 25px !important; padding: 5px; background-color: transparent; color: red; font-weight: 700; } /* Styles for the active tab label */ .mat-tab-label.mat-tab-label-active { min-width: 25px !important; padding: 5px; background-color: transparent; color: red; font-weight: 700; } /* Styles for the ink bar */ .mat-ink-bar { background-color: green; } Demo Update To customize tab background and ink bar, you can define your own theme then use the theme options on the tab group: <div class="my-theme"> <mat-tab-group [backgroundColor]="'primary'" [color]="&

Contenteditable Change Events

Answer : I'd suggest attaching listeners to key events fired by the editable element, though you need to be aware that keydown and keypress events are fired before the content itself is changed. This won't cover every possible means of changing the content: the user can also use cut, copy and paste from the Edit or context browser menus, so you may want to handle the cut copy and paste events too. Also, the user can drop text or other content, so there are more events there ( mouseup , for example). You may want to poll the element's contents as a fallback. UPDATE 29 October 2014 The HTML5 input event is the answer in the long term. At the time of writing, it is supported for contenteditable elements in current Mozilla (from Firefox 14) and WebKit/Blink browsers, but not IE. Demo: document.getElementById("editor").addEventListener("input", function() { console.log("input event fired"); }, false); <div contenteditable="true

Disable Chrome Extension Js Code Example

Example: disable javascript chrome 1 . Ctrl+Shift+I 2 . Ctrl+Shift+P 3 . Type 'javascript' 4 . Select '[Debugger] Disable Javascript'

Using Map Arduino Code Example

Example 1: map arduino Syntax map ( value , fromLow , fromHigh , toLow , toHigh ) Parameters value : the number to map . fromLow : the lower bound of the value’s current range . fromHigh : the upper bound of the value’s current range . toLow : the lower bound of the value’s target range . toHigh : the upper bound of the value’s target range . Example : map ( val , 0 , 255 , 0 , 1023 ) ; Example 2: arduino map function long map ( long x , long in_min , long in_max , long out_min , long out_max ) { return ( x - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min ; }

Cron Guru Every 30 Minutes Code Example

Example: crontab every 30 minutes in specific minute // every 30 minutes */30 * * * * // it depends on the crontab version you are using // example: every 30 minutes at number '5' // mode 1 5,35 * * * * // mode 2 5/30 * * * *

Media Query In W3school Code Example

Example 1: css media queries @media only screen and ( max-width : 1200 px ) { /*Tablets [601px -> 1200px]*/ } @media only screen and ( max-width : 600 px ) { /*Big smartphones [426px -> 600px]*/ } @media only screen and ( max-width : 425 px ) { /*Small smartphones [325px -> 425px]*/ } Example 2: media query @media only screen and ( max-width : 600 px ) { body { background-color : lightblue ; } } Example 3: media query in css @media screen and ( min-width : 374 px ) { section #rent_sectionn { padding : 0 20 px !important ; } }

Bootstrap Scrollbar Code Example

Example 1: custom scrollbar body ::-webkit-scrollbar { width : 12 px ; /* width of the entire scrollbar */ } body ::-webkit-scrollbar-track { background : orange ; /* color of the tracking area */ } body ::-webkit-scrollbar-thumb { background-color : blue ; /* color of the scroll thumb */ border-radius : 20 px ; /* roundness of the scroll thumb */ border : 3 px solid orange ; /* creates padding around scroll thumb */ } Example 2: bootstrap overflow hidden <div class= "overflow-auto" >...</div> <div class= "overflow-hidden" >...</div> Example 3: make a container scrollable bootstrap .anyClass { height : 150 px ; overflow-y : scroll ; } Example 4: custom scrollbar ::-webkit-scrollbar { /* 1 */ } ::-webkit-scrollbar-button { /* 2 */ } ::-webkit-scrollbar-track { /* 3 */ } ::-webkit-scrollbar-track-piece { /* 4 */ } ::-we

How To Use Filter Blur In Css Code Example

Example 1: image blur css filter : blur ( 8 px ) ; -webkit-filter : blur ( 8 px ) ; Example 2: blur css .mydiv { filter : grayscale ( 50 % ) } /* Graut alle Bilder um 50% aus und macht sie um 10px unscharf */ img { filter : grayscale ( 0.5 ) blur ( 10 px ) ; }

Materialize Css Form Template Code Example

Example 1: materialize css form file input <form action= "#" > <div class= "file-field input-field" > <div class= "btn" > <span>File</span> <input type= "file" > </div> <div class= "file-path-wrapper" > <input class= "file-path validate" type= "text" > </div> </div> </form> Example 2: fix materialize form label not working input :-webkit-autofill + label { font-size : 0.8 rem ; transform : translateY ( -140 % ) ; }

Montserrat Font Free Download Code Example

Example: montserrat font <link rel= "preconnect" href= "https://fonts.gstatic.com" > <link href= "https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel= "stylesheet" >

Android:fitsSystemWindows Not Working

Answer : Use CoordinatorLayout as root for your view, it worked for me. <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> My problem was most likely related to multiple/nested fitsSystemWindows attributes which does not work as I found out later. I solved my problem by applying the attribute to one view, and then copy the paddings to other views that need them via an ViewTreeObserver.OnGlobalLayoutListener . That is an ugly hack, but does its job for now. I meet the same problem in Android 4.4 My problem is <item name="android:windowTranslucentStatus">true</item> conflict with <item name="android:fitsSystemWindows">true</item> My way is remove

Crontab Every 5 Seconds Code Example

Example: crontab every 5 minutes */5 * * * *

Arduino Split String Code Example

Example: 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 } ; int maxIndex = data . length ( ) - 1 ; for ( int i = 0 ; i <= maxIndex && found <= index ; i ++ ) { if ( data . charAt ( i ) == separator || i == maxIndex ) { found ++ ; strIndex [ 0 ] = strIndex [ 1 ] + 1 ; strIndex [ 1 ] = ( i ==

Css Stretch Image To Fill Div Code Example

Example 1: css image fit in div with aspect ratio img { width : 100 % ; height : 100 % ; object-fit : contain ; } Example 2: image to fill div .fill { display : flex ; justify-content : center ; align-items : center ; overflow : hidden } .fill img { flex-shrink : 0 ; min-width : 100 % ; min-height : 100 % } Example 3: is there an img cover body { margin : 0 ; } img { display : block ; width : 100 vw ; height : 100 vh ; object-fit : cover ; } Example 4: how to contain image size overflow : 'hidden' , backgroundSize : 'contain' , Example 5: make image stretch to fit div Just apply without any changing any code img { width : 100 % ; }

Advantages Of Using Arrays Instead Of Std::vector?

Answer : In general, I strongly prefer using a vector over an array for non-trivial work; however, there are some advantages of arrays: Arrays are slightly more compact: the size is implicit. Arrays are non-resizable; sometimes this is desirable. Arrays don't require parsing extra STL headers (compile time). It can be easier to interact with straight-C code with an array (e.g. if C is allocating and C++ is using). Fixed-size arrays can be embedded directly into a struct or object, which can improve memory locality and reducing the number of heap allocations needed. Because C++03 has no vector literals. Using arrays can sometime produce more succinct code. Compared to array initialization: char arr[4] = {'A', 'B', 'C', 'D'}; vector initialization can look somewhat verbose std::vector<char> v; v.push_back('A'); v.push_back('B'); ... I'd go for std::array available in C++0x instead of plain arrays which can

Can I Use Pagespeed Insights For My Local Host Website Or Offline?

Answer : Yes. Use the "Lighthouse" tab from your google chrome dev tools. This is a great starter tutorial on how to do that: https://www.youtube.com/watch?v=5fLW5Q5ODiE Edit: user izogfif pointed out the "Audit" tab was replaced by "Lighthouse".