Skip to content

Instantly share code, notes, and snippets.

View chirag-v's full-sized avatar

Chirag Vora chirag-v

View GitHub Profile
@chirag-v
chirag-v / readfile.py
Last active December 12, 2015 13:39
reading file old try/finally way
try:
f = open('/home/user/acetylene.xyz')
while True:
line = f.readline()
if len(line) == 0:
break
print(line, end=' ')
finally:
f.close()
print('file is closed now!')
@chirag-v
chirag-v / readfile2.py
Last active December 12, 2015 13:39
with open file as file_stream: (Prefered way)
with open('/home/user/acetylene.xyz','r') as a_file:
print(a_file.read())
if a_file.closed is True:
print("You won't see this")
if a_file.closed is True:
print ("file is closed now!")
@chirag-v
chirag-v / filecopy-shutil.py
Last active December 12, 2015 14:09
copying content of file into a new file using shutil
import shutil
with open('/home/user/acetylene.xyz','r') as fsrc:
with open('/home/user/acetylene-copy.xyz','w') as fdst:
shutil.copyfileobj(fsrc, fdst)
@chirag-v
chirag-v / acetylene.xyz
Last active December 12, 2015 14:39
Cartesian coordinate of acetaldehyde from avogadro
0 1
C -1.20326 2.85220 0.25234
H -0.37439 3.51897 0.03795
C -1.82835 2.05722 -0.84623
O -1.62242 2.75455 1.39418
H -1.31730 2.27626 -1.80702
H -2.90224 2.32334 -0.93775
H -1.73531 0.97336 -0.62482
@chirag-v
chirag-v / Z-matrix
Created February 13, 2013 01:13
Z-matrix of acetaldehyde created using avogadro
0 1
C
H 1 1.08515
C 1 1.49318 2 120.10198
O 1 1.22026 2 119.76319 3 180.02562
H 3 1.11007 1 109.81648 2 359.97438
H 3 1.11015 1 109.75404 2 240.10815
H 3 1.11015 1 109.75404 2 119.89178
@chirag-v
chirag-v / elisp-delete.el
Last active December 12, 2015 19:09
elisp [delete] key
;; Use [Delete] key to delete selected characters
(global-set-key [delete] 'delete-char)
@chirag-v
chirag-v / .emacs.el
Last active December 12, 2015 21:49
.emacs file
;; Convert "yes or no" prompts to "y or n" instead
(fset 'yes-or-no-p 'y-or-n-p)
;; [Home] & [End] key will take you to beginning & end of line
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
;; displays the time in the status bar
(display-time)
import shutil
shutil.copy('/home/user/acetylene.xyz', '/home/user/backup/')
## if you want to preserve the meta-data of acetylene.txt
## then you should use shutil.copy2()
#!/usr/bin/python
#Show how to make and save a simple line plot with labels, title and grid
#modified from matplotlib official tutorial @ http://www.scipy.org/Plotting_Tutorial
#Run directly on iPython shell
import numpy
import pylab
pylab.interactive(True)
pylab.show()
@chirag-v
chirag-v / isnan.py
Last active December 14, 2015 05:49
isnan function in python
import math as m
x=float('nan')
m.isnan(x) # True