Posts

Showing posts from May, 2021

Angularjs For Loop Code Example

Example 1: angular loop < li *ngFor = " let a of fakeArray; let index = index " > Something {{ index }} </ li > Example 2: angular javascript for loop content_copy < h2 > Products </ h2 > < div *ngFor = " let product of products " > </ div > Example 3: angular for loop let array = [1,2,3]; for (let i = 0; i < array.length; i++) { console.log(array[i]); } Example 4: angular for loop let array = [1,2,3]; array.forEach(function (value) { console.log(value); });

Can Gulp Overwrite All Src Files?

Answer : I can think of two solutions: Add an option for base to your gulp.src like so: gulp.src([...files...], {base: './'}).pipe(...)... This will tell gulp to preserve the entire relative path. Then pass './' into gulp.dest() to overwrite the original files. (Note: this is untested, you should make sure you have a backup in case it doesn't work.) Use functions. Gulp's just JavaScript, so you can do this: [...files...].forEach(function(file) { var path = require('path'); gulp.src(file).pipe(rename(...)).pipe(gulp.dest(path.dirname(file))); } If you need to run these asynchronously, the first will be much easier, as you'll need to use something like event-stream.merge and map the streams into an array. It would look like var es = require('event-stream'); ... var streams = [...files...].map(function(file) { // the same function from above, with a return return gulp.src(file) ... }; return

Add Days Moment Js Code Example

Example 1: moment add 30 days moment().add(30, 'days'); Example 2: moment js add day var new_date = moment(startdate, "DD-MM-YYYY").add(5, 'days'); Example 3: momentjs docs npm install moment

Bootstrap Responsive Font Size Code Example

Example 1: how to make fonts respnsive h1 { font-size : clamp ( 16 px , 5 vw , 34 px ) ; } Example 2: responsive text css /* Uses vh and vm with calc */ @media screen and ( min-width : 25 em ) { html { font-size : calc ( 16 px + ( 24 - 16 ) * ( 100 vw - 400 px ) / ( 800 - 400 ) ) ; } } /* Safari <8 and IE <11 */ @media screen and ( min-width : 25 em ) { html { font-size : calc ( 16 px + ( 24 - 16 ) * ( 100 vw - 400 px ) / ( 800 - 400 ) ) ; } } @media screen and ( min-width : 50 em ) { html { font-size : calc ( 16 px + ( 24 - 16 ) * ( 100 vw - 400 px ) / ( 800 - 400 ) ) ; } } Example 3: how to make font responsive html { font-size : calc ( 1 em + 1 vw ) ; } Example 4: bootstrap text size <p class= "h1" >h1. Bootstrap heading</p> <p class= "h2" >h2. Bootstrap heading</p> <p class= "h3" >h3. Bootstrap heading</p> <

Call Function OnPress React Native

Answer : In you're render you're setting up the handler incorrectly, give this a try; <View> <Icon name='heart' color={this.state.myColor} size= {45} style={{marginLeft:40}} onPress={this.handleClick} /> </View> The syntax you're using would make sense for declaring an anonymous function inline or something but since your handler is defined on the class, you just reference it (not call it) using this.functionName in the props. A little late to the party, but just wanted to leave this here if someone needs it export default class mainScreen extends Component { handleClick = () => { //some code } render() { return( <View> <Button name='someButton' onPress={() => { this.handleClick(); //usual call like vanilla javascript, but uses this operator }}

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

Bytes Vs Bytearray In Python 2.6 And 3

Answer : For (at least) Python 3.7 According to the docs: bytes objects are immutable sequences of single bytes bytearray objects are a mutable counterpart to bytes objects. And that's pretty much it as far as bytes vs bytearray . In fact, they're fairly interchangeable and designed to flexible enough to be mixed in operations without throwing errors. In fact, there is a whole section in the official documentation dedicated to showing the similarities between the bytes and bytearray apis. Some clues as to why from the docs: Since many major binary protocols are based on the ASCII text encoding, bytes objects offer several methods that are only valid when working with ASCII compatible data and are closely related to string objects in a variety of other ways. In Python 2.6 bytes is merely an alias for str . This "pseudo type" was introduced to [partially] prepare programs [and programmers!] to be converted/compatible with Python 3.0 where there is a

Changing The Width Of Bootstrap Popover

Image
Answer : Increase width with CSS You can use CSS to increase the width of your popover, like so: /* The max width is dependant on the container (more info below) */ .popover{ max-width: 100%; /* Max Width of the popover (depending on the container!) */ } If this doesn't work, you probably want the solution below and alter your container element. (View the JSFiddle) Twitter bootstrap Container If that doesn't work, you probably need to specify the container: // Contain the popover within the body NOT the element it was called in. $('[data-toggle="popover"]').popover({ container: 'body' }); More Info The popover is contained within the element that it is triggered in. In order to extend it "full width" - specify the container: // Contain the popover within the body NOT the element it was called in. $('[data-toggle="popover"]').popover({ container: 'body' }); JSFiddle View the JSFiddle to

Arabic Number In Arabic Text In Android

Answer : There's such issue in Google's bugtracker: Arabic numerals in arabic language intead of Hindu-Arabic numeral system If particularly Egypt locale doesn't work due to some customer's issue(I can understand it), then you can format your string to any other western locales. For example: NumberFormat nf = NumberFormat.getInstance(new Locale("en","US")); //or "nb","No" - for Norway String sDistance = nf.format(distance); distanceTextView.setText(String.format(getString(R.string.distance), sDistance)); If solution with new Locale doesn't work at all, there's an ugly workaround: public String replaceArabicNumbers(String original) { return original.replaceAll("Ù¡","1") .replaceAll("Ù¢","2") .replaceAll("Ù£","3") .....; } (and variations around it with Unicodes matching (U+0661,U+0662,...

Best Css Framework 2020 Code Example

Example: best css framework 2020 /* Answer to: "best css framework 2020" */ /* Here are a list of 10 Best CSS Frameworks in 2020. However, for more information on each Framework, go to: https://www.creativebloq.com/features/best-css-frameworks 1. Bootstrap 2. Foundation 3. UIkit 4. Semantic UI 5. Bulma 6. Tailwind 7. Picnic CSS 8. PaperCSS 9. NES.css 10. Animated.css */

Chrome Keyboard Shortcut To "close Other Tabs"?

Image
Answer : I wrote this extension so that we can assign shortcuts for closing tabs to the right / left /other tabs /pin /unpin tab. Let me know if you can use it Update 2019/06/10: Still works with Chrome 75 No keyboard shortcut i know about and checking google forums neither does anyone else. There is an extension Close Inactive Tabs this is a button which closes all other tabs except the active one No more confusing menus The shortcut key to close all other tabs is Ctrl Shift Alt W if you install Amazing Tab Shortcuts, freely available in the Chrome Web Store. I use it frequently for scripts, which I suspect is your use.         

Button Type Submit Onclick Preventdefault Code Example

Example 1: prevent button from submitting form function myFunc(e){ e.preventDefault(); } Example 2: prevent button form submit < button type = " button " > Button </ button >

Chrome Policy List On Fedora

Answer : You can remove it by the line: sudo dnf remove fedora-chromium-config Yes, I just noticed this too (and I'm pretty miffed)! Delete /etc/opt/chrome/policies/managed/00_gssapi.json

Add Build Parameter In Jenkins Build Schedule

Answer : Basically, with the 'Build periodically' option you can't schedule a Jenkins job with parameters. However, to schedule a job at different times that needs to use different environments, you have to use the parameterized-scheduler plugin or search for it in (Manage Jenkins -> Manage Plugins -> Parameterized Scheduler). Examples: # Parameter1 H/15 * * * * %Parameter1 # Parameter2 H/30 * * * * %Parameter2 Remember you have to have your parameters already setup because the plugin is visible only for jobs with parameters. The Node and Label parameter plugin can help since it allows you to select individual nodes assuming your different servers qa1 and qa2 are already configured. Hope that clarifies things for you. With the native Jenkins crontab, it's not possible. But it should be possible with this plugin: https://github.com/jwmach1/parameterized-scheduler You have to fork the repo and build this plugin + do a manual installation. Th

Aggregation Vs Composition Vs Association Vs Direct Association

Image
Answer : Please note that there are different interpretations of the "association" definitions. My views below are heavily based on what you would read in Oracle Certification books and study guides. Temporary association A usage inside a method , its signature or as a return value. It's not really a reference to a specific object. Example: I park my Car in a Garage. Composition association A so-called " STRONG relationship ": The instantiation of the linked object is often hard coded inside the constructor of the object. It cannot be set from outside the object. (Composition cannot be a many-to-many relationship.) Example: A House is composed of Stones. Direct association This is a " WEAK relationships ". The objects can live independent and there are usually setters or other ways to inject the dependent objects. Example: A Car can have Passengers. Aggregation association Very similar to a Direct as

How To Find Vector Length In Numpy Matrix Code Example

Example: numpy how to length of vector >> > x = np . zeros ( ( 3 , 5 , 2 ) , dtype = np . complex128 ) >> > x . size 30 >> > np . prod ( x . shape ) 30

Boxplot Of Multiple Columns Of A Pandas Dataframe On The Same Figure (seaborn)

Image
Answer : The seaborn equivalent of df.boxplot() is sns.boxplot(x="variable", y="value", data=pd.melt(df)) Complete example: import numpy as np; np.random.seed(42) import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = pd.DataFrame(data = np.random.random(size=(4,4)), columns = ['A','B','C','D']) sns.boxplot(x="variable", y="value", data=pd.melt(df)) plt.show() This works because pd.melt converts a wide-form dataframe A B C D 0 0.374540 0.950714 0.731994 0.598658 1 0.156019 0.155995 0.058084 0.866176 2 0.601115 0.708073 0.020584 0.969910 3 0.832443 0.212339 0.181825 0.183405 to long-form variable value 0 A 0.374540 1 A 0.156019 2 A 0.601115 3 A 0.832443 4 B 0.950714 5 B 0.155995 6 B 0.708073 7 B 0.212339 8 C 0.731994 9 C

Angular Cli Create Component In Folder Code Example

Example 1: ng cli generate component ng g c componentName Example 2: generate component angular without folder Angular: Add --flat flag. ng g c yourcomponentname --flat --flat=true|false When true, creates the new files at the top level of the current project. Default: false Example 3: auto generate component angular ng g component [directory-where-you-want-to-save-the-component]/[new-component-name] ng generate component [directory-where-you-want-to-save-the-component]/[new-component-name]

Array Initializer List Java Code Example

Example: java array initialization int [ ] data = { 10 , 20 , 30 , 40 , 50 , 60 , 71 , 80 , 90 , 91 } ; // or int [ ] data ; data = new int [ ] { 10 , 20 , 30 , 40 , 50 , 60 , 71 , 80 , 90 , 91 } ;

Can I Catch Shiny Pokémon?

Answer : Prior to March 22, there were no shiny Pokemon in the game. After this update, it was possible to catch a Shiny Magikarp, which can could later be evolved into a Shiny Gyarados. It was first reported by users on the Sylph Road Reddit, then confirmed via photographic evidence. Since then, other Shiny Pokemon have been included in the game. Here is the current list: Pikachu Raichu Magikarp Gyarados Sableye Shuppet Banette Duskull Dusclops Mawile Absol Snorunt Swablu Altaria As of right now, there have been no shiny Pokemon encountered in Pokemon GO. As the game has been release for multiple days, more than 8192 Pokemon have been encountered by the install base of multiple hundreds of thousands. Its incredibly unlikely that there are shiny Pokemon in Pokemon GO. EDIT: Here's an online list of shinies that is updated regularly: https://www.imore.com/pokemon-go-shiny Posting an updated answer since the old one is outdated. Legendaries are in italics, a

Javascript Strlen Code Example

Example 1: js string length let str = "foo" ; console . log ( str . length ) ; // 3 Example 2: javascript string lentrh var myString = "string test" ; var stringLength = myString . length ; console . log ( stringLength ) ; // Will return 11 because myString // is 11 characters long... Example 3: javascript longitud de un string cadena_primitiva = String ( "barra" ) ; // crea una Cadena primitiva cadena_primitiva = "barra" ; // crea una Cadena primitiva cadena_primitiva . length ; // 5 Example 4: javascript length var colors = [ "Red" , "Orange" , "Blue" , "Green" ] ; var colorsLength = colors . length ; //4 is colors array length var str = "bug" ; var strLength = str . length ; //3 is the number of characters in bug Example 5: length of string in javascript var str = "Hello World!" ; var n = str . length ;

Best Python Ide Mac Code Example

Example 1: best python ide PyCharm - https://www.jetbrains.com/pycharm/ # Only for python Visual Studio Code - https://code.visualstudio.com/ # Personally use and can work for tons of different languages (Highly Reccommend) IDLE # default ide comes with python, its pretty good comes with python documentation Example 2: best ide for python """Pycharm: https://www.jetbrains.com/pycharm/ ...or if you are willing to go the better, more painful, but yet better way, you should NOT use an IDE. The solution is a text editor. Good Text Editors (ranked): - Atom : https://atom.io/ - VS Code : https://code.visualstudio.com/ - Sublime Text : https://www.sublimetext.com/ """ Example 3: best ide for python Pycharm - https://www.jetbrains.com/pycharm/ Visual Studio Code - https://code.visualstudio.com/ Example 4: best code editors for micropython I prefer to use atom code editor. It supports a whole lot of languages including python, c, c++, c sharp