Skip to content

Instantly share code, notes, and snippets.

View janfreyberg's full-sized avatar

Jan Freyberg janfreyberg

View GitHub Profile
@janfreyberg
janfreyberg / sample_groups.R
Created February 19, 2022 12:15
Sample groups in a tidy data frame.
sample_groups <- function(.data, ..., n, prop) {
slice_size <- dplyr:::check_slice_size(n, prop)
.data %>%
dplyr::group_by(...) %>%
tidyr::nest() %>%
dplyr::ungroup() %>%
{
if (slice_size$type == "n") {
dplyr::slice_sample(., n=slice_size$n)
} else {
@janfreyberg
janfreyberg / talk.ipynb
Created September 16, 2019 15:18
superintendent-pycon-2019-lightning
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@janfreyberg
janfreyberg / docker-compose.yml
Created July 17, 2019 08:36
Pydata superintendent talk
# Use postgres/example user/password credentials
version: '3.1'
services:
db:
image: postgres
restart: always
environment:
POSTGRES_USER: superintendent
@janfreyberg
janfreyberg / __init__.py
Created April 1, 2019 20:46
Gist for blogpost: revgrad
from .functional import revgrad
from torch.nn import Module
class RevGrad(Module):
def __init__(self, *args, **kwargs):
"""
A gradient reversal layer.
This layer has no parameters, and simply reverses the gradient
in the backward pass.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@janfreyberg
janfreyberg / dash-app.css
Created October 18, 2017 14:15
some css for a skeleton plotly app
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #FAFAFA;
font-size: 1.1rem;
line-height: 1.3;
}
* {
@janfreyberg
janfreyberg / matlab-example.ipynb
Last active March 3, 2017 14:05
Ipython notebooks
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from psychopy import data
import random
stairs = data.MultiStairHandler(conditions=[{'label': str(size),
'size': size,
'startVal': 10,
'stepType': 'lin',
'nTrials': 20,
'nUp': 1,
'nDown': 1,
import numpy as np
import re # regular expressions
import csv
from matplotlib import pyplot as pl
from scipy.stats.stats import pearsonr
def parse_dms(dms):
parts = re.split('[^\d\w]+', dms)
lat = dms2dd(parts[0], parts[1], parts[2])