Skip to content

Instantly share code, notes, and snippets.

View jvkersch's full-sized avatar

Joris Vankerschaver jvkersch

View GitHub Profile
@jvkersch
jvkersch / backup_script.py
Last active June 9, 2017 18:08
Python wrapper around to rsync to facilitate backup
#!/usr/bin/env python
"""
A simple wrapper around rsync for backup.
Usage: create a text file with on each line a resource that you wish to
backup. Paths should be relative to the user's home directory. Entries
starting with '#' are ignored, as are blank lines. Call this script via
python backup_script.py -i [backup_files.txt] [rsync_target_folder]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jvkersch
jvkersch / browser.py
Created September 10, 2014 09:37
Quickly open a web page to display a variable in IPython
import webbrowser
from tempfile import NamedTemporaryFile
from IPython.core.magic import Magics, magics_class, line_magic
@magics_class
class BrowserMagics(Magics):
@line_magic
@jvkersch
jvkersch / bad.c
Last active March 29, 2020 10:05
Bug in Apple's vecLib (OS X < 10.10)
/* proof-of-concept incorrect */
""" Obtain a quote of the Dow Jones Industrial Average from Bloomberg.
"""
import json
from bs4 import BeautifulSoup
import requests
url = 'http://www.bloomberg.com/quote/INDU:IND'
#include <math.h>
#include <stdio.h>
#include <Python.h>
#include "numpy/npy_math.h"
/* Comparing numpy's fallback implementation of log1p with that of the C
standard library.
Compile with
diff --git a/Modules/getpath.c b/Modules/getpath.c
index de96d47..8487208 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -7,7 +7,7 @@
#include <string.h>
#ifdef __APPLE__
-#include <mach-o/dyld.h>
+#include <dlfcn.h>
@jvkersch
jvkersch / ssh_auth_sock.md
Last active March 23, 2024 14:59
Updating SSH_AUTH_SOCK in an already established tmux session

I found this information somewhere on StackOverflow but I forgot exactly where. I'm paraphrasing what I learned here, for future reference.

SSH uses a Unix socket to communicate with other processes. The socket's path can be found by looking at the environment variable $SSH_AUTH_SOCK. When you re-connect to a tmux session that was started during a previous SSH session, this variable will contain the path of the previous SSH auth socket, and this will cause processes that try to connect to your authentication agent to fail. To fix this, we have to

  1. Create a symlink from the auth socket to a fixed path somewhere, so that we can refer to it later on. In ~/.ssh/rc, add
if test "$SSH_AUTH_SOCK"; then
	ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi
@jvkersch
jvkersch / mem_usage.py
Created October 21, 2015 17:30
Aggregate memory usage of a process and its children.
"""Aggregate memory usage of a process and its children.
This utility measures the resident set size of a process and its children, and
returns the result either in bytes or formatted in a more convenient
format. Note: this "total resident size" is often an inflated measure of how
much memory a process group uses, as it will double-count e.g. memory used by
dynamic libraries and shared memory. It serves well as (a) a conservative
estimate, and (b) when sampled over time, to estimate changes in memory usage.
Requires psutil.
#!/usr/bin/env python
# -*- coding: utf-8
""" A script to check whether shows listed on SBS have Korean subtitles.
"""
import argparse
import logging
import re