Skip to main content

Posts

Python code: Download shared file from google drive

This python script downloads file from googledrive by using the shareable link of the file. import requests import sys def download_file_from_google_drive(id, destination): URL = "https://docs.google.com/uc?export=download" session = requests.Session() response = session.get(URL, params = { 'id' : id }, stream = True) token = get_confirm_token(response) if token: params = { 'id' : id, 'confirm' : token } response = session.get(URL, params = params, stream = True) save_response_content(response, destination) def get_confirm_token(response): for key, value in response.cookies.items(): if key.startswith('download_warning'): return value return None def save_response_content(response, destination): CHUNK_SIZE = 32768 with open(destination, "wb") as f: for chunk in response.iter_content(CHUNK_SIZE): if chunk: # filter out keep-al
Recent posts

t-test with minimum number of samples

There are two different ways to justify the use of the t-test.  Your data is normally distributed and you have at least two samples per group  You have large sample sizes in each group If either of these cases hold, then the t-test is considered a valid test. So if you are willing to make the assumption that your data is normally distributed (which many researchers who collect small samples are), then you have nothing to worry about.  However, someone might reasonably object that you are relying on this assumption to get your results, especially if your data is known to be skewed. Then the question of sample size required for valid inference is a very reasonable one.  As for how large a sample size is required, unfortunately there's no real solid answer for that; the more skewed your data, the bigger the sample size required to make the approximation reasonable. 15-20 per group is usually considered reasonable large, but as with most rules of thumb, there exist counte

Error mounting NTFS drive from Ubuntu

I came across a new problem, at least for me, in ubuntu 14.04, while trying to mount the NTFS drives. It was just saying that I did not turned off windows system properly and therefore the filesystem is corrupt. I could mount the file system in the readonly mode. sudo mount -t "ntfs" -ro "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000,dmask=0077,fmask=0177" "/dev/sda3" "/media/bidur/d" For that, I have to create a new directory beforehand i.e. "/media/bidur/d". Just now, I came across a way to deal with the problem by using ntfsfix commad: sudo ntfsfix /dev/sda3

Python Pipe

Pipes can be used in python using the popen command. os.popen(command[, mode[, bufferSize]]). The default mode is read which can also be explicitly indicated by "r" as shown in the example below. The parameter bufferSize can be 0 (no buffering), 1 (line buffering), negative(system default buffering) and positive values greater than 1 (number defines the buffer size to be used). #Open a pipe to or from command import os # shell command to show all the files in current directory with ".py" in the file name shellCommand = ' ls | grep .py' pipe = os.popen(shellCommand,"r") while True: # read each output line line = pipe.readline() if not line: break print 'outputLine: ' print line

calculate hop count in a graph using python

The following program finds out the hop count of the nodes in a connected network. Hop Count means the number of point to point connections in a graph of network. For example, in the graph shown below the hop count from node a to node b is one, node b to node c is two, etc. This program assumes the graph given above. usage : getHopCount(dictNeigh, node1,node2) Where:   dictNeigh : dictionary of list of neighbor of each node in the network node1 and node2 are the nodes for which hop count is calculated by the program Exception: if the nodes are not connected then it returns Zero import copy dictNeigh = dict() # dictNeigh defines the neighbors dictNeigh['a'] = ['b','c','d'] # neighbors of 'a' dictNeigh['b'] = ['a']# neighbors of 'b' dictNeigh['c'] = ['a','d'] dictNeigh['d'] = ['a','c','e'] dictNeigh['e'] = ['d','f'] dictN

ubuntu (10.04) apache web server not running due to port conflict

Sometimes the port assigned to apache2 may be used by some other services. In such cases, if we try to live apache2 server then it fails.  The following message is shown in ubuntu 10.04 in my case: Starting web server apache2                                                   apache2: Could not reliably determine the server's fully qualified domain name, using 0.0.0.3 for ServerName (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs Here is one of the ways to overcome this problem: 1. see who is using the port 80 : sudo lsof -i :80 2. get the pid of the services in 1. E.g.: 1577 3. kill all the services in 2. : sudo kill 1577 4. restart apache2: sudo /etc/init.d/apache2 restart

Display dynamic content in Google Earth using KML

Keyhole Markup Language (KML) is a xml standard which can be used to define what and how to present geographic data in Google Earth and Google Maps. Useful examples to start can be browsed via https://developers.google.com/kml/documentation/kml_tut . I have to display KML data in googleearth. And the KML file has to be loaded dynamically and the updates in the kml file should be shown in the googleearth on the fly. For this we have to Create a Network Link. Goto Add -> Network Link Then specify the details as shown in the figure. To specify the frequency of updating the data, go to Refresh tab. The code for dynamicKML.kml is as follows: <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.1"> <document> <networklink> <link> <href>junk.kml</href> <refreshmode>onInterval</refreshMode> <refreshinterval&g