Posts

Showing posts from August, 2005

Convert Datetime To Unix Timestamp And Convert It Back In Python

Answer : solution is import time import datetime d = datetime.date(2015,1,5) unixtime = time.mktime(d.timetuple()) What you missed here is timezones. Presumably you've five hours off UTC, so 2013-09-01T11:00:00 local and 2013-09-01T06:00:00Z are the same time. You need to read the top of the datetime docs, which explain about timezones and "naive" and "aware" objects. If your original naive datetime was UTC, the way to recover it is to use utcfromtimestamp instead of fromtimestamp . On the other hand, if your original naive datetime was local, you shouldn't have subtracted a UTC timestamp from it in the first place; use datetime.fromtimestamp(0) instead. Or, if you had an aware datetime object, you need to either use a local (aware) epoch on both sides, or explicitly convert to and from UTC. If you have, or can upgrade to, Python 3.3 or later, you can avoid all of these problems by just using the timestamp method instead of trying to figure out how to

Linktag Html Code Example

Example: link in html <a href= "https://example.com" >Link text goes here</a>

Calling Php Function From Javascript Code Example

Example 1: call javascript function from php // The most basic method <?php echo '<script type="text/javascript">' , 'someJsFunc();' , // Or Whatever '</script>' ; ?> // However, if what you are trying to achieve requires more complexity, // You might be better off adding the V8JS module, see link below Example 2: call php function in js < script > var phpadd = <?php echo add ( 1 , 2 ) ; ?> //call the php add function var phpmult = <?php echo mult ( 1 , 2 ) ; ?> //call the php mult function var phpdivide = <?php echo divide ( 1 , 2 ) ; ?> //call the php divide function </ script >

String Comparison In C Code Example

Example 1: how to compare strings in c if ( strcmp ( strA , strB ) != 0 ) { . . . } Example 2: see if two strings are equal in C # include <stdio.h> # include <string.h> int main ( int argc , char const * argv [ ] ) { char string1 [ ] = { "tutorials point" } ; char string2 [ ] = { "tutorials point" } ; //using function strcmp() to compare the two strings if ( strcmp ( string1 , string2 ) == 0 ) printf ( "Yes 2 strings are same\n" ) ; else printf ( "No, 2 strings are not same\n" ) ; return 0 ; } Example 3: statement o compare two strings in c # include <stdio.h> # include <string.h> int main ( ) { char str1 [ ] = "abcd" , str2 [ ] = "abCd" , str3 [ ] = "abcd" ; int result ; // comparing strings str1 and str2 result = strcmp ( str1 , str2 ) ; printf ( "strcmp(str1, str

"Control Cannot Fall Out Of Switch From Final Case Label ('default:') C# Code Example

Example: "Control cannot fall out of switch from final case label ('default:') c# default : Console . WriteLine ( "Invalid input" ) ; break ; //remember "break"

Cron Job Every 2 Minutes Code Example

Example 1: cron every 2 minutes */2 * * * * Example 2: cron every two hours 0 */2 * * *

Git Lf Will Be Replaced By Crlf Code Example

Example 1: warning: LF will be replaced by CRLF git config --global core.autocrlf true Example 2: LF will be replaced by CRLF in assets git config core.autocrlf true Example 3: lf will be replaced by crlf Linux and MacOS : use characters as in file $ git config --global core.autocrlf input Windows : deactivate the automatic conversion to CRLF $ git config --global core.autocrlf false Example 4: lf will be replaced by crlf in web/app.css. #If you are a single developer working on a windows machine , and you don't care #that git automatically replaces LFs to CRLFs , you can turn this warning off by #typing the following in the git command line git config core.autocrlf true #If you’re programming on Windows and working with people who are not ( or vice-versa ) , #you’ll probably run into line-ending issues at some point. $ git config --global core.autocrlf true #If you’re on a Linux or Mac system that uses LF line endings , then you don’t #want Git to automatically conver

Html Image Grid Generator Code Example

Example: css grid generator <div class= "grid-container" > <div class= "Container" ></div> </div>

C++: Store Read Binary File Into Buffer

Answer : I just want to mention that there is a standard way to read from a binary file into a buffer. Using <cstdio> : char buffer[BUFFERSIZE]; FILE * filp = fopen("filename.bin", "rb"); int bytes_read = fread(buffer, sizeof(char), BUFFERSIZE, filp); Using <fstream> : std::ifstream fin("filename.bin", ios::in | ios::binary ); fin.read(buffer, BUFFERSIZE); What you do with the buffer afterwards is all up to you of course. Edit: Full example using <cstdio> #include <cstdio> const int BUFFERSIZE = 4096; int main() { const char * fname = "filename.bin"; FILE* filp = fopen(fname, "rb" ); if (!filp) { printf("Error: could not open file %s\n", fname); return -1; } char * buffer = new char[BUFFERSIZE]; while ( (int bytes = fread(buffer, sizeof(char), BUFFERSIZE, filp)) > 0 ) { // Do something with the bytes, first elements of buffer. // For exa

Git Set Remote Repo And Push Code Example

Example 1: git remote add git remote add origin https : / / github . com / user / repo . git Example 2: git connect to remote repository git init git commit - m "[message]" git remote add origin "github repository link" git push - u origin master