Skip to content

Instantly share code, notes, and snippets.

View AndreaPasqualini's full-sized avatar
🔥
This is fine

Andrea Pasqualini AndreaPasqualini

🔥
This is fine
View GitHub Profile
@AndreaPasqualini
AndreaPasqualini / archive-git-branch.sh
Last active June 20, 2019 14:25
A set of commands to easily and safely archive Git branches after they've been merged.
git tag archive/<branch_name> <branch_name>
git push --tags
git push --delete <remote> <branch_name>
git branch -d <branch_name>
@AndreaPasqualini
AndreaPasqualini / ols.py
Created February 11, 2019 16:12
ols python
import numpy as np
import scipy.linalg as la
def ols(y, x, const=True):
n = y.shape[0]
if const: # if we want to add a constant to the regression
X = np.concatenate((np.ones((n, 1)), x), axis=1)
else:
X = x
@AndreaPasqualini
AndreaPasqualini / dta_to_csv.py
Created May 22, 2019 09:48
A CLI tool to convert a Stata .dta file into a .csv file. Relies on pandas.
"""
Title: dta_to_csv.py
Author: Andrea Pasqualini
This CLI tool converts a Stata .dta file into a .csv file. Python3 and pandas
are dependencies. It does not return anything, internally. It saves on disk a
file with CSV extension that has the same name as the input DTA file.
USAGE
-----
@AndreaPasqualini
AndreaPasqualini / kroenecker_trickery.tex
Last active July 8, 2019 15:02
A small memo about Kroenecker products and linear indexing
\documentclass{article}
\usepackage{amsmath, amsfonts, amssymb}
\title{Kroenecker Products and Linalg Trickery}
\author{Andrea Pasqualini}
\begin{document}
\maketitle
Consider two vectors, $x$ and $y$.
@AndreaPasqualini
AndreaPasqualini / gtk_webkit_url_wrapper.py
Created February 5, 2020 15:24
A simple WebKit wrapper opening a website in a GTK window, all written in Python. (tested on Ubuntu 19.10)
#!/usr/bin/env python
from gi.repository import Gtk
from gi.repository import GObject
from gi.repository import WebKit2
GObject.threads_init()
win = Gtk.Window()
bro = WebKit2.WebView()
bro.load_uri("https://www.google.com")
@AndreaPasqualini
AndreaPasqualini / gini.py
Created March 23, 2020 15:17
A function to compute the Gini coefficient, from a vector of data.
import numpy as np
def G(v):
"""
Found at https://stackoverflow.com/questions/39512260/calculating-gini-coefficient-in-python-numpy
"""
bins = np.linspace(0., 100., 11)
total = float(np.sum(v))
yvals = []
for b in bins:
@AndreaPasqualini
AndreaPasqualini / copy_gpg_key.md
Last active April 23, 2020 19:49
Steps to export and import a private GPG key.

Copy a Private GPG Key across Machines

This document shows the steps to export and then import again a private GPG key. I find this useful when I need to reinstall my OS. If the GPG key has not been compromised (e.g., theft), then this is a safe way of moving keys around.

First, obtain the ID of the private key.

gpg --list-secret-keys --keyid-format LONG
@AndreaPasqualini
AndreaPasqualini / screen_sizes.py
Created June 26, 2020 22:38
Small Python+Numpy function to compute screen sizes given aspect ratio and diagonal length.
from numpy import array, sqrt
def xy_sizes(diagonal, aspect_ratio, units='centimeters'):
r"""
This function computes the horizontal and vertical lengths of a screen
given its diagonal length and the aspect ratio. The system of equations to
be solved admits a unique feasible solution in closed form. The system is
given by these two equations:
x / y = aspect_ratio
@AndreaPasqualini
AndreaPasqualini / coding-style-guide.md
Last active March 10, 2021 20:19
An (examplary) example of a "Coding Style Guide" for Economists. All credits go to @michaelstepner.

I am reposting this wonderful ReadMe file by @michaelstepner from his healthinequality-code repository. This provides a detailed set of coding guidelines for his specific research project. It contains references to Stata and Julia. However, I believe it also represents an extensive set of arguments in favor of best practices for managing and maintaining code. As Michael correctly points out, we Economists are lagging behind software developers by at least years, if not decades. While we do not need to use complicated command-line interfaces or sophisticated systems, we still rely on automation for our research. It is important not to excessively rely on technical debt, which would otherwise entail unbearable long-term costs. This ReadMe file explains how to do so and provides a set

@AndreaPasqualini
AndreaPasqualini / install-matlab-wsl.md
Last active February 19, 2024 17:57
Instructions to install MATLAB on WSL

Installing MATLAB on WSL

This guide serves as a note to self to remember how to install MATLAB on a WSL virtual machine.

Environment

Ubuntu 20.04 on WSL2, with Windows 10.