Posts

Showing posts from January, 2018

Buscar Substring Php Code Example

Example 1: php string contains $mystring = 'abc' ; $findme = 'a' ; $pos = strpos ( $mystring , $findme ) ; Example 2: strpos php <?php $mystring = 'abc' ; $findme = 'a' ; $pos = strpos ( $mystring , $findme ) ; // El operador !== también puede ser usado. Puesto que != no funcionará como se espera // porque la posición de 'a' es 0. La declaración (0 != false) se evalúa a // false. if ( $pos !== false ) { echo "La cadena ' $findme ' fue encontrada en la cadena ' $mystring '" ; echo " y existe en la posición $pos " ; } else { echo "La cadena ' $findme ' no fue encontrada en la cadena ' $mystring '" ; } ?>

C++ Gcc Online Compiler Code Example

Example 1: cpp online compiler Best Site With auto compile : https : //godbolt.org/z/nEo4j7 Example 2: online compiler cpp Good cpp compilers : -- -- -- -- -- -- -- -- -- -- - repl . it / languages / cpp www . w3schools . com / cpp / trycpp . asp ? filename = demo_helloworld onlinegdb . com / online_c ++ _compiler programiz . com / cpp - programming / online - complier cpp . sh

C: How To Free Nodes In The Linked List?

Answer : An iterative function to free your list: void freeList(struct node* head) { struct node* tmp; while (head != NULL) { tmp = head; head = head->next; free(tmp); } } What the function is doing is the follow: check if head is NULL, if yes the list is empty and we just return Save the head in a tmp variable, and make head point to the next node on your list (this is done in head = head->next Now we can safely free(tmp) variable, and head just points to the rest of the list, go back to step 1 Simply by iterating over the list: struct node *n = head; while(n){ struct node *n1 = n; n = n->next; free(n1); }

Converting Milliseconds To Minutes And Seconds With Javascript

Answer : function millisToMinutesAndSeconds(millis) { var minutes = Math.floor(millis / 60000); var seconds = ((millis % 60000) / 1000).toFixed(0); return minutes + ":" + (seconds < 10 ? '0' : '') + seconds; } millisToMinutesAndSeconds(298999); // "4:59" millisToMinutesAndSeconds(60999); // "1:01" As User HelpingHand pointed in the comments the return statement should be return (seconds == 60 ? (minutes+1) + ":00" : minutes + ":" + (seconds < 10 ? "0" : "") + seconds); With hours, 0-padding minutes and seconds: var ms = 298999; var d = new Date(1000*Math.round(ms/1000)); // round to nearest second function pad(i) { return ('0'+i).slice(-2); } var str = d.getUTCHours() + ':' + pad(d.getUTCMinutes()) + ':' + pad(d.getUTCSeconds()); console.log(str); // 0:04:59 Here's my contribution if looking for h:mm:ss instead like I was: function msConversion(millis)

Youtube To M4 Code Example

Example 1: youtube to mp4 ytmp3 . cc is the best by far Example 2: youtube to mp4 flvto . biz is great for it

Java Script Array Leng Code Example

Example: array length javascript var numbers = [ 1 , 2 , 3 , 4 , 5 ] ; var length = numbers . length ; for ( var i = 0 ; i < length ; i ++ ) { numbers [ i ] *= 2 ; } // numbers is now [2, 4, 6, 8, 10]

Inherit Css Class From Another Code Example

Example: css inherit class .rounded_corners { -moz-border-radius : 8 px ; -webkit-border-radius : 8 px ; border-radius : 8 px ; } #header { .rounded_corners ; } #footer { .rounded_corners ; }

Android Check Internet Connection

Answer : This method checks whether mobile is connected to internet and returns true if connected: private boolean isNetworkConnected() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected(); } in manifest, <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> Edit: This method actually checks if device is connected to internet(There is a possibility it's connected to a network but not to internet). public boolean isInternetAvailable() { try { InetAddress ipAddr = InetAddress.getByName("google.com"); //You can replace it with your name return !ipAddr.equals(""); } catch (Exception e) { return false; } } Check to make sure it is

Shadow Box Generator Code Example

Example 1: css box shadow #example1 { box-shadow : 10 px 10 px 8 px #888888 ; } Example 2: css shadow generator border-radius : 50 px ; background : linear-gradient ( 145 deg , #e6e6e6 , #ffffff ) ; box-shadow : 20 px 20 px 60 px #d9d9d9 , -20 px -20 px 60 px #ffffff ;

Laravel Update Controller Code Example

Example 1: laravel create resource controller php artisan make : controller PhotoController -- resource Example 2: how to create controller in laravel Simple controller : php artisan make : controller nameOfController Want to create controller in a folder ? use it like this : php artisan make : controller NameOfFolder / nameOfController Resource Controller : This controller will create all CRUD methods php artisan make : controller nameOfController -- resource Example 3: laravel create resource controller php artisan make : controller PhotoController -- resource -- model = Photo Example 4: resource controller laravel Route :: resource ( 'photos' , PhotoController :: class ) ;

Conio.h Stands For Code Example

Example: what is conio.h conio . h Is a C header file used mostly by MS - DOS compilers to provide console input / output . It is not part of the C standard library or ISO C , nor it is defined by POSIX . This header declares several useful library functions for performing "console input and output" from a program .

Aggregation Of An Annotation In GROUP BY In Django

Answer : Update: Since Django 2.1, everything works out of the box. No workarounds needed and the produced query is correct. This is maybe a bit too late, but I have found the solution (tested with Django 1.11.1). The problem is, call to .values('publisher') , which is required to provide grouping, removes all annotations, that are not included in .values() fields param. And we can't include dbl_price to fields param, because it will add another GROUP BY statement. The solution in to make all aggregation, which requires annotated fields firstly, then call .values() and include that aggregations to fields param(this won't add GROUP BY , because they are aggregations). Then we should call .annotate() with ANY expression - this will make django add GROUP BY statement to SQL query using the only non-aggregation field in query - publisher . Title.objects .annotate(dbl_price=2*F('price')) .annotate(sum_of_prices=Sum('dbl_price')) .

Conversion Int To String C++ Code Example

Example 1: change int to string cpp # include <string> std :: string s = std :: to_string ( 42 ) ; Example 2: convert integer to string c++ std :: to_string ( 23213.123 ) Example 3: convert int to string c++ int a = 10 ; stringstream ss ; ss << a ; string str = ss . str ( ) ;

Scrolling=no In Html Code Example

Example: disable scroll css /* Answer to: "disable scroll css" */ /* You must set the height and overflow of the body, to disable scrolling. */ html , body { margin : 0 ; height : 100 % ; overflow : hidden }

Convert Wstring To String Encoded In UTF-8

Answer : The code below might help you :) #include <codecvt> #include <string> // convert UTF-8 string to wstring std::wstring utf8_to_wstring (const std::string& str) { std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv; return myconv.from_bytes(str); } // convert wstring to UTF-8 string std::string wstring_to_utf8 (const std::wstring& str) { std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv; return myconv.to_bytes(str); } What's your platform? Note that Windows does not support UTF-8 locales so this may explain why you're failing. To get this done in a platform dependent way you can use MultiByteToWideChar/WideCharToMultiByte on Windows and iconv on Linux. You may be able to use some boost magic to get this done in a platform independent way, but I haven't tried it myself so I can't add about this option. You can use boost's utf_to_utf converter to get char format to store in std::string. st