Posts

Showing posts from August, 2009

Append Html In Javascript Code Example

Example 1: JavaScript append text to div var div = document . getElementById ( 'myElementID' ) ; div . innerHTML += "Here is some more data appended" ; Example 2: how to appendChild in the begin of the div javascript var element = document . getElementById ( "div1" ) ; element . insertBefore ( para , element . firstChild ) ; Example 3: how to append in javascript var list = [ 1 , 2 , 3 , 4 , 5 ] ; list . push ( 6 ) ; // .push allows you to add a value to the end of a list Example 4: JavaScript append HTML let app = document . querySelector ( '#app' ) ; app . append ( 'append() Text Demo' ) ; console . log ( app . textContent ) ;

Best Practice For Android MVVM StartActivity

Answer : The answer to your question is what is your goal? If you want to use MVVM for separation of concerns so that you can unit test your Viewmodel then you should try to keep everything that requires a Context separate from your Viewmodel . The Viewmodel contains the core business logic of your app and should have no external dependencies. However I like where you are going :) If the decision which Activity is opened lies in the View, then it is very very hard to write a JUnit test for it. However you can pass an object into the Viewmodel which performs the startActivity() call. Now in your Unit test you can simply mock this object and verify that the correct Activity is opened The way I do it is, in your ViewModel: val activityToStart = MutableLiveData<Pair<KClass<*>, Bundle?>>() This allows you to check the class of Activity started, and the data passed in the Bundle. Then, in your Activity, you can add this code: viewModel.activityToStart.

Bootstrap Datepicker Value Format Code Example

Example: bootstrap datepicker format < input type = "text" class = "form-control" value = "02-16-2012" >

Any Way To Get Mappings Of A Label Encoder In Python Pandas?

Answer : You can create additional dictionary with mapping: from sklearn import preprocessing le = preprocessing.LabelEncoder() le.fit(data['name']) le_name_mapping = dict(zip(le.classes_, le.transform(le.classes_))) print(le_name_mapping) {'Tom': 0, 'Nick': 1, 'Kate': 2} The best way of doing this can be to use label encoder of sklearn library. Something like this: from sklearn import preprocessing le = preprocessing.LabelEncoder() le.fit(["paris", "paris", "tokyo", "amsterdam"]) list(le.classes_) le.transform(["tokyo", "tokyo", "paris"]) list(le.inverse_transform([2, 2, 1])) A simple & elegant way to do the same. cat_list = ['Sun', 'Sun', 'Wed', 'Mon', 'Mon'] encoded_data, mapping_index = pd.Series(cat_list).factorize() and you are done , check below print(encoded_data) print(mapping_index) print(mapping_index.get_loc("

Angular 4 Pipe Filter

Answer : Here is a working plunkr with a filter and sortBy pipe. https://plnkr.co/edit/vRvnNUULmBpkbLUYk4uw?p=preview As developer033 mentioned in a comment, you are passing in a single value to the filter pipe, when the filter pipe is expecting an array of values. I would tell the pipe to expect a single value instead of an array export class FilterPipe implements PipeTransform { transform(items: any[], term: string): any { // I am unsure what id is here. did you mean title? return items.filter(item => item.id.indexOf(term) !== -1); } } I would agree with DeborahK that impure pipes should be avoided for performance reasons. The plunkr includes console logs where you can see how much the impure pipe is called. The transform method signature changed somewhere in an RC of Angular 2. Try something more like this: export class FilterPipe implements PipeTransform { transform(items: any[], filterBy: string): any { return items.filter(item =&

90 Degrees To Radians Code Example

Example 1: degrees to radians radians = degrees * pi / 180 ; Example 2: degrees to radians double radians = Math . toRadians ( degrees ) ;

How To Return A Array In C++ Code Example

Example 1: return array from function c++ # include <iostream> using namespace std ; int * fun ( ) { int * arr = new int [ 100 ] ; /* Some operations on arr[] */ arr [ 0 ] = 10 ; arr [ 1 ] = 20 ; return arr ; } int main ( ) { int * ptr = fun ( ) ; cout << ptr [ 0 ] << " " << ptr [ 1 ] ; return 0 ; } Example 2: cpp return array int * fillarr ( int arr [ ] , int length ) { for ( int i = 0 ; i < length ; ++ i ) { // arr[i] = ? // do what you want to do here } return arr ; } // then where you want to use it. int main ( ) { int arr [ 5 ] ; int * arr2 ; arr2 = fillarr ( arr , 5 ) ; } // at this point, arr & arr2 are basically the same, just slightly // different types. You can cast arr to a (char*) and it'll be the same. Example 3: c++ function return array # include <iostream> # include <c

Bootstrap 4 Media Queries For Responsive Code Example

Example 1: bootstrap media query breakpoints // Extra small devices (portrait phones, less than 576px) @media (max-width: 575.98px) { ... } // Small devices (landscape phones, 576px and up) @media (min-width: 576px) and (max-width: 767.98px) { ... } // Medium devices (tablets, 768px and up) @media (min-width: 768px) and (max-width: 991.98px) { ... } // Large devices (desktops, 992px and up) @media (min-width: 992px) and (max-width: 1199.98px) { ... } // Extra large devices (large desktops, 1200px and up) @media (min-width: 1200px) { ... } Example 2: bootstrap media queries /* Large desktops and laptops */ @media (min-width: 1200px) { } /* Landscape tablets and medium desktops */ @media (min-width: 992px) and (max-width: 1199px) { } /* Portrait tablets and small desktops */ @media (min-width: 768px) and (max-width: 991px) { } /* Landscape phones and portrait tablets */ @media (max-width: 767px) { } /* Portrait phones and smaller */ @media (max-width: 480px) { } Examp

93 In Binary Code Example

Example: 10 binary to denary binary 10 = 2 denary

Break Whitespace Css Code Example

Example 1: css remove whitespace around element body { margin:0px; } header { border:1px black solid; } Example 2: how to have white space in css #HTML_code < h1 > My text < span > Here my white space </ span > </ h1 > #Css_Code h1 span::before { content: "\A"; white-space:pre; }

Border-radius Circle Code Example

Example 1: css circle border .circle { background-color : #fff ; border : 1 px solid red ; height : 100 px ; border-radius : 50 % ; -moz-border-radius : 50 % ; -webkit-border-radius : 50 % ; width : 100 px ; } <div class= "circle" ></div> Example 2: css border radius -webkit-border-radius : 5 px ; -moz-border-radius : 5 px ; border-radius : 5 px ;

Bootstrap 4 Vertical Carousel Multiple Items Code Example

Image
Example: bootstrap 4 carousel multiple items responsive Previous Next

Accessing Kotlin Extension Functions From Java

Answer : All Kotlin functions declared in a file will be compiled by default to static methods in a class within the same package and with a name derived from the Kotlin source file (First letter capitalized and ".kt" extension replaced with the "Kt" suffix). Methods generated for extension functions will have an additional first parameter with the extension function receiver type. Applying it to the original question, Java compiler will see Kotlin source file with the name example.kt package com.test.extensions public fun MyModel.bar(): Int { /* actual code */ } as if the following Java class was declared package com.test.extensions class ExampleKt { public static int bar(MyModel receiver) { /* actual code */ } } As nothing happens with the extended class from the Java point of view, you can't just use dot-syntax to access such methods. But they are still callable as normal Java static methods: import com.test.extensions.ExampleKt; MyMod

Bootstrap With JQuery Validation Plugin

Image
Answer : for total compatibility with twitter bootstrap 3, I need to override some plugins methods: // override jquery validate plugin defaults $.validator.setDefaults({ highlight: function(element) { $(element).closest('.form-group').addClass('has-error'); }, unhighlight: function(element) { $(element).closest('.form-group').removeClass('has-error'); }, errorElement: 'span', errorClass: 'help-block', errorPlacement: function(error, element) { if(element.parent('.input-group').length) { error.insertAfter(element.parent()); } else { error.insertAfter(element); } } }); See Example: http://jsfiddle.net/mapb_1990/hTPY7/7/ For full compatibility with Bootstrap 3 I added support for input-group , radio and checkbox , that was missing in the other solutions. Update 10/20/2017 : Inspected suggestions of the other answers and added ad

Calculating Password Entropy?

Answer : There are equations for when the password is chosen randomly and uniformly from a given set; namely, if the set has size N then the entropy is N (to express it in bits, take the base-2 logarithm of N ). For instance, if the password is a sequence of exactly 8 lowercase letters, such that all sequences of 8 lowercase characters could have been chosen and no sequence was to be chosen with higher probability than any other, then entropy is N = 26 8 = 208827064576 , i.e. about 37.6 bits (because this value is close to 2 37.6 ). Such a nice formula works only as long as uniform randomness occurs, and, let's face it, uniform randomness cannot occur in the average human brain. For human-chosen passwords, we can only do estimates based on surveys (have a look at that for some pointers). What must be remembered is that entropy qualifies the password generation process , not the password itself. By definition, "password meter" applications and Web sites do

Cat6 CCA Or Cat5e Pure Copper

Answer : Including aluminum in conductors decreases cost for the manufacturer. If the cable meets the various specifications for impedance, crosstalk, etc and the cable is run within spec (bend radius, proximity to interference, strain) then the materials utilized for the conductor don't matter. The physical difference between cat5e and cat6 has to do with the number of twists per inch and, potentially, the inclusion of shielding. The result of these changes is that the cable can (minimally) support higher bandwidth, specifically 10GE in this case. The other cable (5e) isn't rated to support these kinds of speeds but very well might work in practice. If you're looking to future-proof for 10GE (or more) then go for 6a or 7. If you're just setting up basic 100M or GE then it doesn't make much difference. 5e and 6 are fairly close in price. The distances involved are quite low, which renders any difference theoretical at best. In summary? There won'

Doubly Circular Linked List Program In C Code Example

Example 1: circular linked list in c # include <stdio.h> # include <string.h> # include <stdlib.h> # include <stdbool.h> struct node { int data ; int key ; struct node * next ; } ; struct node * head = NULL ; struct node * current = NULL ; bool isEmpty ( ) { return head == NULL ; } int length ( ) { int length = 0 ; //if list is empty if ( head == NULL ) { return 0 ; } current = head -> next ; while ( current != head ) { length ++ ; current = current -> next ; } return length ; } //insert link at the first location void insertFirst ( int key , int data ) { //create a link struct node * link = ( struct node * ) malloc ( sizeof ( struct node ) ) ; link -> key = key ; link -> data = data ; if ( isEmpty ( ) ) { head = link ; head -> next = head ; } else { /

Pypi Tkinter Code Example

Example: python tkinter import tkinter as tk obj = tk . Tk ( ) # Creates a tkinter object label = tk . Label ( obj , text = "This is a text button" )

Box Shadow Codepen Code Example

Example: material box shadow .card-1 { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); transition: all 0.3s cubic-bezier(.25,.8,.25,1); } .card-1:hover { box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22); } .card-2 { box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23); } .card-3 { box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23); } .card-4 { box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22); } .card-5 { box-shadow: 0 19px 38px rgba(0,0,0,0.30), 0 15px 12px rgba(0,0,0,0.22); }

Pow Function In Python Code Example

Example 1: power function python # There are two ways of computing x ^ y in python : >> > 3 * * 4 81 >> > pow ( 3 , 4 ) 81 Example 2: how to power in python 2 * * 3 == 8 Example 3: python pow pow ( x , y ) # == x ^ y Example 4: power in python # The ouptut will be x ^ y x * * y

Filmora 9 Watermark Remover Code Example

Example 1: how to remove filmora watermark Here How To Get Filmora 9 For Free WITHOUT Watermark [ Filmora X is Available Also ] 0. Disable Anti Virus Cuz You Gotta Install . DLL Files 1. Download and Setup Filmora 9 2. Watch The Video Video 3. Downlaod The Files in Desc Do as it Says 4. Login or Sign up and Make a Filmora Account 5. Enjoy Your Filmora WITHOUT The Watermark YouTube Video : https : //www.youtube.com/watch?v=78dC55fduQU Cracked Files : https : //drive.google.com/file/d/1qC9UfD3ixW5iMaYfP50W8IwSZybToel8/view Thank me On Discord : Rigby# 9052 Example 2: how to remove filmora watermark for free thanks my dude it worked

AngularJS Folder Structure

Image
Answer : Sort By Type On the left we have the app organized by type. Not too bad for smaller apps, but even here you can start to see it gets more difficult to find what you are looking for. When I want to find a specific view and its controller, they are in different folders. It can be good to start here if you are not sure how else to organize the code as it is quite easy to shift to the technique on the right: structure by feature. Sort By Feature (preferred) On the right the project is organized by feature. All of the layout views and controllers go in the layout folder, the admin content goes in the admin folder, and the services that are used by all of the areas go in the services folder. The idea here is that when you are looking for the code that makes a feature work, it is located in one place. Services are a bit different as they “service” many features. I like this once my app starts to take shape as it becomes a lot easier to manage for me. A well written blog

Bootstrap Card Image Width Code Example

Example 1: bootstrap card change image .card-img-top { width: 100%; height: 15vw; object-fit: cover; } Example 2: bootstrap + cards < div class = " card " style = " width : 18 rem ; " > < img class = " card-img-top " src = " ... " alt = " Card image cap " > < div class = " card-body " > < h5 class = " card-title " > Card title </ h5 > < p class = " card-text " > Some quick example text to build on the card title and make up the bulk of the card's content. </ p > < a href = " # " class = " btn btn-primary " > Go somewhere </ a > </ div > </ div >

Mongo Restart Ubuntu Code Example

Example 1: how to restart mongodb server in ubuntu sudo systemctl restart mongodb # it will restarts running mongodb server Example 2: mongodb restart command ubuntu sudo systemctl restart mongod Example 3: start mongodb service ubuntu sudo systemctl start mongod sudo systemctl stop mongod Example 4: ubuntu start mongodb sudo mongod -- fork -- config / etc / mongod . conf

Integer.max Value Java Code Example

Example 1: java max integer Integer . MAX_VALUE //== 2147483647, once you increment past that, you //"wrap around" to Integer.MIN_VALUE Example 2: max in array java // Initializing array of integers Integer [ ] num = { 2 , 4 , 7 , 5 , 9 } ; // using Collections.min() to find minimum element // using only 1 line. int min = Collections . min ( Arrays . asList ( num ) ) ; // using Collections.max() to find maximum element // using only 1 line. int max = Collections . max ( Arrays . asList ( num ) ) ; Example 3: integer max value java //Integer.MAX_VALUE (MAX_VALUE Method In Integer Wrapper Class) - 2 , 147 , 483 , 648 //(Value) In Java , the integer ( long ) is also 32 bits , but ranges from - 2 , 147 , 483 , 648 to + 2 , 147 , 483 , 647. Example 4: java max int value public class Test { public static void main ( String [ ] args ) { System . out . println (

Bluetooth Speaker Connected But Not Listed In Sound Output

Answer : One way to solve the problem is to: unpair the device run the following command on terminal: sudo pkill pulseaudio and then pair again the speaker via bluetooth. The speaker is now displayed on the output audio list, which needs to selected for obtaining output sound. Remember to, under Sound Settings, change Mode to High Fidelity Playback (A2DP Sink) . This is what is working for me for Bose QuietComfort 35 on Ubuntu 16.04. pauvcontrol didn't do it for me, and neither did the numerous settings changes and module loadings recommended elsewhere. So give this a try: Install blueman sudo apt install blueman Delete the paired device in the bluetooth settings. Run these commands in terminal: $ sudo pkill pulseaudio $ sudo /etc/init.d/bluetooth restart Turn off headphones. Turn on headphones, and press green/go until headphones notification voice says "Ready to pair." Launch blueman, and from the upper right menu, right-click the icon to b