Skip to content

Instantly share code, notes, and snippets.

Avatar

Marcos Oliveira macoj

View GitHub Profile
@macoj
macoj / stroke_same_as_fill.py
Last active August 29, 2015 14:26
(python) Creates a new QML file (QGIS style format) with the colors of the strokes equals to the shape fills.
View stroke_same_as_fill.py
import re
def stroke_same_as_fill(file_name, output_file_name):
"""
Creates a new QML file (QGIS style format) with the colors of the strokes equals to the shape fills.
stroke_same_as_fill("/home/marcos/Downloads/teste.qml", "/home/marcos/Downloads/teste2.qml")
:param file_name: filename of QML input file
:param output_file_name: output
"""
with open(file_name, 'r') as input_file, open(output_file_name, 'w') as output_file:
lines = input_file.readlines()
@macoj
macoj / git_rm_dir.sh
Created August 1, 2015 22:57
removes dir from git and never adds again
View git_rm_dir.sh
git rm --cached -r .idea
@macoj
macoj / git.sh
Last active August 29, 2015 14:27
git-related command
View git.sh
git config --global url."https://yourusername@github.com".insteadOf "https://github.com"
git config --global credential.helper 'cache --timeout=28800'
git config remote.origin.url https://{USERNAME}:{PASSWORD}@github.com/{USERNAME}/{REPONAME}.git
git config -l
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"
@macoj
macoj / links_color.tex
Created August 12, 2015 19:03
setting the color of the references
View links_color.tex
@macoj
macoj / encode.py
Created December 7, 2015 17:06
dirty fix to quickly print names with different encodes
View encode.py
print name.encode('ascii', 'ignore')
print name.encode('utf-8', 'ignore')
@macoj
macoj / get_projection.py
Created May 25, 2016 14:20
trying to get the projection of a shapefile
View get_projection.py
from osgeo import ogr, osr
driver = ogr.GetDriverByName('ESRI Shapefile')
dataset = driver.Open(r'tabblock2010_25_pophu.shp')
# from Layer
layer = dataset.GetLayer()
spatialRef = layer.GetSpatialRef()
print spatialRef
# from Geometry
feature = layer.GetNextFeature()
geom = feature.GetGeometryRef()
@macoj
macoj / howto.md
Last active September 18, 2016 22:32
how to merge many points of a scatterplot made with matplotlib
View howto.md

Approach A

  1. Export the plot as SVG
   plt.savefig("plot.svg")
  1. Open plot.svg with an editor and include in the definitions the following:
<defs>
   <filter id="shadow">
      <feOffset dx="0" dy="0"/>
@macoj
macoj / guerry_balbi_quetelet.bibtex
Last active October 28, 2016 14:47
bibtex for old criminology literature: Guerry, Balbi, and Quetelet. (adapted from: http://www.datavis.ca/gallery/guerry/)
View guerry_balbi_quetelet.bibtex
@BOOK{quetelet1833recherches,
address = {Brussels, Belgium},
author = {Quetelet, A},
pages = {87},
publisher = {M. Hayez},
title = {{Recherches sur le penchant au crime aux diff{\'{e}}rens {\^{a}}ges}},
url = {https://books.google.com/books?id=ZNEiAAAAMAAJ},
year = {1833}
}
@macoj
macoj / symbols.tex
Created November 22, 2016 15:48
symbols of all types in latex
View symbols.tex
%http://www.ctan.org/tex-archive/info/symbols/comprehensive/symbols-a4.pdf
\usepackage{latexsym} % needs this to have on latex2e
$\bullet$
@macoj
macoj / colorblind_palette.md
Last active November 23, 2016 18:45
colorblind palette
View colorblind_palette.md

Colorblind palette!

Colors from From: Wong, Bang. "Points of view: Color blindness." Nature methods 8.6 (2011): 441-441. in RGB:

color_names = ["Black", "Orange", "Sky blue", "Bluish green", "Yellow", "Blue", "Vermillion", "Reddish purple"]
colors_colorblind_safe = [(0, 0, 0), (230, 159, 0), (86, 180, 233), (0, 158, 115), (240, 228, 66), (0, 114, 178), (213, 94, 0), (204, 121, 167)]
colors_colorblind_safe = ['#%02x%02x%02x' % (c[0], c[1], c[2]) for c in colors_colorblind_safe]
colors = dict(zip(color_names, colors_colorblind_safe))
three_colors = colors['Blue'], colors['Vermillion'], colors['Bluish green']