Skip to content

Instantly share code, notes, and snippets.

@gzagatti
gzagatti / kill_port.sh
Created June 27, 2016 15:57
Kill process using port 3000
lsof -t -i :3000 | xargs kill -9
@gzagatti
gzagatti / ipython_session.md
Created June 29, 2016 15:26
Start an ipython console with linked with an existing notebook

When you start the ipython notebook in the terminal, it will output something like this:

2015-03-26 13:05:52.772 [NotebookApp] Kernel started: 4604c4c3-523b-4373-bfdd-222eb1260156 Then start the ipython console like this:

ipython console --existing 4604c4c3

@gzagatti
gzagatti / sh
Last active November 12, 2016 16:42
Installing Fiona and Basemap with Anaconda in Linux
# `Fiona` and `Basemap` have conflicting `libgdal` dependencies.
# To solve the issue the `libgdal` version has to be fixed to version `2.0.0=0`.
conda install -c conda-forge fiona=1.7.0
conda install gdal basemap libgdal=2.0.0=0
conda install krb5
conda install shapely
pip install geopandas
pip install rasterio
conda install -c conda-forge fiona=1.7.0
@gzagatti
gzagatti / gista.md
Last active March 14, 2017 19:10
Removing and Purging Files from Git History

Rewriting history in git

From Removing and purging files from git history

Remove directories added to .gitignore

To remove files which have been recently added to .gitignore.

git ls-files --ignored --exclude-standard | xargs git rm --cached
@gzagatti
gzagatti / git_file_size.md
Last active February 1, 2018 15:42
'Finding Big Files From Git History'

Source

Finding Big Files From Git History

On a recent grails project, we're using a git repo that was originally converted from a SVN repo with a ton of large binary objects in it (lots of jar files that really should come from an ivy/maven repo). The .git directory was over a gigabyte in size and this made it very cumbersome to clone and manipulate.

We decided to leverage git's history rewriting capabilities to make a much smaller repository (and kept our previous repo as a backup just in case).

Here are a few questions/answers that I figured out how to answer with git and some shell commands:

@gzagatti
gzagatti / docker_decktape.md
Last active May 5, 2017 19:35
Using decktape docker image on a Mac

Decktape offers a Docker image in order to run their presentation converter. If you want to convert a presentation from an instance running on localhost on a Mac, it is necessary to do some work around.

Decktape's Github Page suggests that we run the following command to save a presentation deployed locally:

>> docker run --rm --net=host -v `pwd`:/slides astefanutti/decktape http://localhost:8000 slides.pdf

However when running the docker from a Mac, Docker is actually running behind a virtual machine and has no access to the localhost. Thus the option --net=host leads to a connection refused error.

@gzagatti
gzagatti / testing_shell.sh
Last active June 9, 2017 14:54
'Testing exit values in the shell.'
failure() {
return 1
}
success() {
return 0
}
success
RET_SUCESS=$?
@gzagatti
gzagatti / selecting_dependencies_conda.sh
Created August 2, 2017 15:26
'Select all the dependencies of a conda package using jq.'
conda info --json r-essentials | jq -r ' ."r-essentials"[] | select(.version == "1.5.2" and .build == "r3.3.2_0") | .depends[] '
@gzagatti
gzagatti / uninstall_conda_package_and_dependencies.sh
Created August 2, 2017 15:34
Uninstall a conda package and its dependencies.
conda info --json r-essentials | jq -r ' ."r-essentials"[] | select(.version == "1.5.2" and .build == "r3.3.2_0") | .depends[] ' | awk '{print $1;}' | grep -E '^r-' | xargs -J {} conda uninstall {}
@gzagatti
gzagatti / spss_to_csv.r
Created August 3, 2017 02:35
Converting a list of SPSS files (.sav) to CSV using magrittr
library('magrittr')
library('memisc')
# get all .sav files from directory
files <- list.files('.', pattern='.sav$', recursive=FALSE)
# get the dataframes
dfs <- list.files('.', pattern='.sav$', recursive=FALSE) %>%
lapply(spss.system.file) %>%
lapply(as.data.set) %>%