Posts

Showing posts from November, 2007

53 Cm To Inches Code Example

Example: cm to inch 1 cm = 0.3937 inch

Arraylist Javadoc Code Example

Example: arraylist java //requires either one of these two imports, both work. import java . util . ArrayList ; //--or-- import java . util . * ArrayList < DataType > name = new ArrayList < DataType > ( ) ; //Defining an arraylist, substitute "DataType" with an Object //such as Integer, Double, String, etc //the < > is required //replace "name" with your name for the arraylist

Android: How To Determine Network Speed In Android Programmatically

Answer : Determining your Network Speed - (Slow Internet Speed) Using NetworkInfo class, ConnectivityManager and TelephonyManager to determine your Network Type. Download any file from the internet & calculate how long it took vs number of bytes in the file. ( Only possible way to determine Speed Check ) I have tried the below Logic for my projects, You have also look into this, Hope it helps you. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); //should check null because in airplane mode it will be null NetworkCapabilities nc = cm.getNetworkCapabilities(cm.getActiveNetwork()); int downSpeed = nc.getLinkDownstreamBandwidthKbps(); int upSpeed = nc.getLinkUpstreamBandwidthKbps(); Check internet speed for mobile network to use this code ConnectivityManager connectivityManager = (ConnectivityManager)this.getSystemService(CONNECTIVITY_SERVICE); Ne

Android Camera Preview Stretched

Image
Answer : I'm using this method -> based on API Demos to get my Preview Size: private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) { final double ASPECT_TOLERANCE = 0.1; double targetRatio=(double)h / w; if (sizes == null) return null; Camera.Size optimalSize = null; double minDiff = Double.MAX_VALUE; int targetHeight = h; for (Camera.Size size : sizes) { double ratio = (double) size.width / size.height; if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue; if (Math.abs(size.height - targetHeight) < minDiff) { optimalSize = size; minDiff = Math.abs(size.height - targetHeight); } } if (optimalSize == null) { minDiff = Double.MAX_VALUE; for (Camera.Size size : sizes) { if (Math.abs(size.height - targetHeight) < minDiff) {

Android.preference.PreferenceManager' Is Deprecated Code Example

Example 1: preferencemanager is deprecated //You can use AndroidX support library version of PreferenceManager androidx . preference . PreferenceManager //not android . preference . PreferenceManager //remember to add the following to your build.gradle if needed implementation 'androidx.preference:preference:1.1.1' Example 2: anroid preference manager deprecated substiotuion implementation "androidx.preference:preference-ktx:1.1.0"

How To Use Malloc To Create Array In C Code Example

Example 1: malloc int array c int array_length = 100 ; int * array = ( int * ) malloc ( array_length * sizeof ( int ) ) ; Example 2: how to dynamically allocate array size in c // declare a pointer variable to point to allocated heap space int * p_array ; double * d_array ; // call malloc to allocate that appropriate number of bytes for the array p_array = ( int * ) malloc ( sizeof ( int ) * 50 ) ; // allocate 50 ints d_array = ( int * ) malloc ( sizeof ( double ) * 100 ) ; // allocate 100 doubles // use [] notation to access array buckets // (THIS IS THE PREFERED WAY TO DO IT) for ( i = 0 ; i < 50 ; i ++ ) { p_array [ i ] = 0 ; } // you can use pointer arithmetic (but in general don't) double * dptr = d_array ; // the value of d_array is equivalent to &(d_array[0]) for ( i = 0 ; i < 50 ; i ++ ) { * dptr = 0 ; dptr ++ ; } Example 3: c malloc array # define ARR_LENGTH 2097152 int * arr = mallo

Aggregate Unique Values From Multiple Columns With Pandas GroupBy

Answer : Use groupby and agg , and aggregate only unique values by calling Series.unique : df.astype(str).groupby('prop1').agg(lambda x: ','.join(x.unique())) prop2 prop3 prop4 prop1 K20 12,1,66 travis,leo 10.0,4.0 L30 3,54,11,10 bob,john 11.2,10.0 df.astype(str).groupby('prop1', sort=False).agg(lambda x: ','.join(x.unique())) prop2 prop3 prop4 prop1 L30 3,54,11,10 bob,john 11.2,10.0 K20 12,1,66 travis,leo 10.0,4.0 If handling NaNs is important, call fillna in advance: import re df.fillna('').astype(str).groupby('prop1').agg( lambda x: re.sub(',+', ',', ','.join(x.unique())) ) prop2 prop3 prop4 prop1 K20 12,1,66 travis,leo 10.0,4.0 L30 3,54,11,10 bob,john 11.2,10.0

Comentário Em Html Code Example

Example 1: comentar en html <!-- Esto es un comentario --> < p > Esto es un párrafo HTML </ p > <!-- Esto es otro comentario --> Example 2: comentário html <!--comentário--> Example 3: comentário html <!--comentario-->

App Corse Npm Code Example

Example 1: cors express var allowedOrigins = [ 'http://localhost:3000' , 'http://yourapp.com' ] ; app.use ( cors ( { origin: function ( origin, callback ) { // allow requests with no origin // ( like mobile apps or curl requests ) if ( ! origin ) return callback ( null, true ) ; if ( allowedOrigins.indexOf ( origin ) == = -1 ) { var msg = 'The CORS policy for this site does not ' + 'allow access from the specified Origin.' ; return callback ( new Error ( msg ) , false ) ; } return callback ( null, true ) ; } } )) ; Example 2: cors package install npm var express = require ( 'express' ) var cors = require ( 'cors' ) var app = express ( ) app.get ( '/products/:id' , cors ( ) , function ( req, res, next ) { res.json ( { msg: 'This is CORS-enabled for a Single Route' }

Wordpress - Checking If Database Table Exists

Answer : If you use "IF NOT EXISTS" then the dbdelta script will not upgrade your database with delta's appeared after the initial creation of the database. (assuming you want to re-use the same sql script) at least... that is what i think DISCLAIMER : I'm not a WordPress Guru, only a MySQL DBA If you want to user a different query, try this SELECT COUNT(1) FROM information_schema.tables WHERE table_schema='dbname' AND table_name='tbname'; It will either return 0 (if table does not exist) or 1 (if table does exist) Try this one: global $wpdb; $table_name = $wpdb->base_prefix.'custom_prices'; $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) ); if ( ! $wpdb->get_var( $query ) == $table_name ) { // go go }

Chart.js Canvas Resize

Answer : I had a lot of problems with that, because after all of that my line graphic looked terrible when mouse hovering and I found a simpler way to do it, hope it will help :) Use these Chart.js options: // Boolean - whether or not the chart should be responsive and resize when the browser does. responsive: true, // Boolean - whether to maintain the starting aspect ratio or not when responsive, if set to false, will take up entire container maintainAspectRatio: false, What's happening is Chart.js multiplies the size of the canvas when it is called then attempts to scale it back down using CSS, the purpose being to provide higher resolution graphs for high-dpi devices. The problem is it doesn't realize it has already done this, so when called successive times, it multiplies the already (doubled or whatever) size AGAIN until things start to break. (What's actually happening is it is checking whether it should add more pixels to the canvas by changing the DOM a

Change Color Of Font Awesome Icons Code Example

Example 1: css change font awesome icon color < a href = " /users/edit " > < i class = " fa fa-cog " style = " color : black !important ; " > </ i > Edit profile </ a > Example 2: css change font awesome icon color .fa { color: red !important; } Example 3: css change font awesome icon color . < fa-icon-class > { color: red !important; } Example 4: how to change color of font awesome icons < a href = " /users/edit " > < i class = " icon-cog " > </ i > Edit profile </ a >

Animal Crossing .nca .nsp .xci Code Example

Example: Animal Crossing .nca .nsp .xci Illegal!!!!!!!

Android Spinner Dropdown Arrow Not Displaying

Answer : This works for me, much simpler as well: <Spinner android:id="@+id/spinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Light" android:spinnerMode="dropdown" /> And in your class file: spinner = (Spinner) view.findViewById(R.id.spinner); ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.spinner_data, android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); Hope this helps ;) Try this one: <Spinner android:id="@+id/spinnPhoneTypes" android:layout_width="0dp" style="@android:style/Widget.Spinner.DropDown" android:layout_height="@dimen/thirtyFive" android:layout_marginLeft="10dp" android:layout_weight="1&q

Error: Void Value Not Ignored As It Ought To Be| Code Example

Example: void value not ignored as it ought to be you ' re trying to capture the return value of a function for which the return type is void .

Borders In Bootstrap 4 Code Example

Example 1: bootstrap border color < span class = " border border-primary " > </ span > < span class = " border border-secondary " > </ span > < span class = " border border-success " > </ span > < span class = " border border-danger " > </ span > < span class = " border border-warning " > </ span > < span class = " border border-info " > </ span > < span class = " border border-light " > </ span > < span class = " border border-dark " > </ span > < span class = " border border-white " > </ span > Example 2: border radius bootstrap Border-radius Add classes to an element to easily round its corners. < img src = " ... " alt = " ... " class = " rounded " > < img src = " ... " alt = " ... " class = " r

Check If Typeof Array Javascript Code Example

Example 1: if object is array javascript Array . isArray ( object ) ; Example 2: javascript determine array type var data = [ 'a' , 'b' , 'c' ] var isArray = Array . isArray ( data ) console . log ( isArray ) Example 3: javascript typeof array Array . isArray ( arr )

23 Inch To Cm Code Example

Example: inch to cm 1 inch = 2.54 cm

C++ - Does Resetting Stringstream Not Reset The Get Position Or Clear Flags?

Answer : As @Someprogrammerdude suggests: simply move your istringstream inside your while loop (which you can change to a for loop to keep in in the loop as well): for (string in; cin >> in;) { istringstream word(in); int number; if (!(word >> number)) { cerr << "Failed to read int" << endl; return 1; } cout << in << ' ' << number << endl; } that way it's re-created each loop. While you're at it, move number in there too (unless you use it outside the loop, of course). If you look at the state of the stream, this should be a bit clearer. int main() { std::vector<std::string> words = { "10", "55", "65" }; std::istringstream word; for (const auto &in : words) { word.str(in); std::cout << "stream state:" << (word.rdstate() & std::ios::badbit ? "

Ansible Recursive Directory Copy

Answer : file module is not for copying the files, but for setting attributes of files on the target. copy module is for copying. Providing some additional information to the accepted answer.. Recursive copy using directory paths has the following disadvantages: you cannot get changed state information per file copied so --check and --check --diff flags won't show anything you cannot include/exclude specific files/directories to/from the recursion performing corrective changes after the bulk copy will never produce a state with changed=0 and could also affect files that already existed on remote host. There seems to be a more powerful way to perform a recursive copy, which is to use with_filetree combined with when - name: "create-remote-dirs" file: path: /dest/dir/{{item.path}} state: directory mode: '0775' with_filetree: sourceDir/ when: item.state == 'directory' - name: "copy-files" copy: src

Bootstrap-wysiwyg Cdn Code Example

Example: bootstrap cdn for jquery < script src = " https://code.jquery.com/jquery-3.3.1.slim.min.js " integrity = " sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo " crossorigin = " anonymous " > </ script > < script src = " https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js " integrity = " sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1 " crossorigin = " anonymous " > </ script > < script src = " https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js " integrity = " sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM " crossorigin = " anonymous " > </ script >

Clear Cookies Js Code Example

Example 1: clear cookies js function deleteAllCookies ( ) { var cookies = document . cookie . split ( ";" ) ; for ( var i = 0 ; i < cookies . length ; i ++ ) { var cookie = cookies [ i ] ; var eqPos = cookie . indexOf ( "=" ) ; var name = eqPos > - 1 ? cookie . substr ( 0 , eqPos ) : cookie ; document . cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT" ; } } deleteAllCookies ( ) ; Example 2: javascript delete cookie function deleteCookie ( name ) { document . cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;' ; } Example 3: how to delete a cookie in js //set the vvalue to EMPTY, and the date to an already PASSED one. document . cookie = "cookiename= ; expires = Thu, 01 Jan 1970 00:00:00 GMT" Example 4: clearing cookie in js document . cookie . split ( ";" ) . forEach ( function ( c ) { document