Posts

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...