Skip to content

Instantly share code, notes, and snippets.

View romach's full-sized avatar

Roman Cherepanov romach

View GitHub Profile
@romach
romach / git-pull-from-python.py
Last active April 2, 2017 19:52
Git pull from Python
import git
g = git.cmd.Git(git_dir)
g.pull()
@romach
romach / create-file-by-template.py
Created April 2, 2017 20:06
Create file by template
from string import Template
#open the file
file = open( 'foo.txt' )
#read it
template = Template( file.read() )
#document data
title = "This is the title"
subtitle = "And this is the subtitle"
list = ['first', 'second', 'third']
@romach
romach / check-if-file-exists.py
Created April 2, 2017 20:23
Check if file exists
import os.path
os.path.isfile(fname)
@romach
romach / create-file-if-not-exists.py
Created April 2, 2017 21:47
Create file if not exists, throw exception in other case
def write_content_to_file(content, file_path):
output_file = os.fdopen(os.open(file_path, os.O_CREAT | os.O_WRONLY | os.O_EXCL), "w")
output_file.write(content)
output_file.close()
@romach
romach / parameter-without-value.py
Created April 2, 2017 21:50
Create program parameter without value
parser.add_argument('-l', '--list', help='Drafts list', action='store_true')
@romach
romach / headless-browsers.md
Created April 2, 2017 22:10
Headless browsers
@romach
romach / set-tab-size-in-idea-for-java
Created April 3, 2017 11:34
Set tab size in Intellij IDEA for Java files
Settings > Editor > Code Style > Java
Set values for: Tab size, Indent, Continuation indent
@romach
romach / create-lightweight-tag.sh
Last active April 5, 2017 11:18
Create lightweight tag
git tag '1.0.0-rc1'
@romach
romach / push-git-tag.sh
Last active April 5, 2017 11:17
Push git tag
git push origin '1.0.0-rc1'
@romach
romach / change-file-extensions.sh
Created April 4, 2017 17:01
Change file extensions
# remove all .png extension from all files
for i in $(ls *.png); do mv $i ${i%.png}; done
# remove extensiosns from all files
for i in $(ls *.*); do mv $i ${i%.*}; done
# change extension from .html to .htm
for i in $(ls *.html); do mv $i ${i%.html}.htm; done