Skip to content

Instantly share code, notes, and snippets.

@john-sandall
john-sandall / gist:05c3abb24fc738ddc2ad
Last active August 29, 2015 14:23
dplyr::mutate with lubridate::ymd_hms seems to crash R at random
# Posted on StackOverflow: http://stackoverflow.com/questions/31010713/combining-dplyrmutate-with-lubridateymd-hms-in-r-randomly-causes-segfault
#!/usr/bin/env R
# -*- encoding:utf-8 -*-
require(lubridate)
require(dplyr)
set.seed(42)
make_some_random_datetimes = function(n) ymd("2015-01-01") + seconds(runif(n, min=0, max=60*60*24*365))
@john-sandall
john-sandall / multiprocessing_examples.ipynb
Last active December 10, 2016 22:35
Multiprocessing + pandas examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@john-sandall
john-sandall / .zshrc
Created June 24, 2019 14:45
.zshrc config for debugging zsh-autoswitch-virtualenv
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/john/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
<!DOCTYPE html>\n<html>\n<head>\n<title>\nNewspeak House\n-\nFellows and alumni\n\n</title>\n<link href=\'https://www.nwspk.com/fellowship\' rel=\'canonical\'>\n<link href=\'https://nwspk.com/humans.txt\' rel=\'author\' type=\'text/plain\'>\n<link rel="stylesheet" media="all" href="/assets/application-2390809e15d062726101ae7185d9c1b88caedf50ff88269f3c02abafca3ae4df.css" />\n<script src="/assets/application-88ed0f161404425e15bd21a8b0c950e249fb364b8edc7a799a11e01c6faa28c7.js"></script>\n<meta name="csrf-param" content="authenticity_token" />\n<meta name="csrf-token" content="iO2GG6DKdUB76QlntL8z+65lbP/DsUwAqf5fiL++L9kMRwrSQcn84wIs5C2DXAeBBYOcaJJ5P77C7HvEqt9dIA==" />\n<meta content=\'width=device-width, initial-scale=1\' name=\'viewport\'>\n\n</head>\n<body>\n<div class=\'logo\'>\n<a href="https://nwspk.com/">NEWSPEAK HOUSE</a>\n</div>\n<section class=\'page\'>\n<a class="back-link" href="/"><i class="fa fa-angle-double-left"></i></a>\n<div class=\'wrap\'>\n<h2>Newspeak House Fellowship</h2>\n<p class=\'fellowsh
@john-sandall
john-sandall / fix_broken_virtualenvs.py
Last active May 23, 2020 16:15
Fix broken virtualenv symlinks due to brew upgrade
import os
import subprocess
from pathlib import Path
path = Path("/Users/john/.virtualenvs")
list_subfolders_with_paths = [f.path for f in os.scandir(path) if f.is_dir()]
for folder in list_subfolders_with_paths:
virtualenv_name = folder.split("/")[-1]
print(f"🛠 Fixing {virtualenv_name}")
subprocess.run(["find", folder, "-type", "l", "-delete"])
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@john-sandall
john-sandall / rename_files.py
Created October 14, 2021 21:01
Rename files & folders in current directory
# In IPython, you can change the current working directory using
# %cd /path/to/some/directory/
import os
from pathlib import Path
# Directory containing folders you want to rename
here = Path(".") # "." means "the current directory"
# Loop through all the folders & files in this directory
@john-sandall
john-sandall / add_markers.py
Created September 19, 2022 23:17
Hacky solution for using Poetry to manage PyTorch installed across macOS and Linux
"""Fixes issue where Poetry ignores environment markers when using local path.
See https://github.com/python-poetry/poetry/issues/2765
Usage:
$ poetry lock
$ python add_markers.py
"""
from __future__ import annotations