Skip to content

Instantly share code, notes, and snippets.

@tanho63
tanho63 / scoobydoo_pivot.R
Last active September 25, 2023 19:19
pivot_longer sentinel .value - scoobydoo tidy tuesday
library(tidyverse)
scooby_data <- read.csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-07-13/scoobydoo.csv")
x <-
scooby_data %>%
select(season, title,
starts_with("caught"),
starts_with("captured"),
starts_with("unmask"),
# Setup -------------------------------------------------------------------
librarian::shelf(tidyverse, lubridate, systemfonts, ggtext, ragg,
ggbump)
scoobydoo <-
readr::read_csv(
'https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-07-13/scoobydoo.csv',
na = 'NULL'
)
library(tidyverse)
# Download Fira Sans Condensed from
# https://fonts.google.com/specimen/Fira+Sans+Condensed
high_mean <- 12
high_sd <- 4
flat_mean <- 35
flat_sd <- 12
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.
@rahimnathwani
rahimnathwani / install-gpu-gce.sh
Last active August 4, 2017 19:28
Set up a Google Cloud GPU instance for doing the exercises in course.fast.ai
#!/bin/bash
if ! dpkg-query -W cuda; then
curl -O http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
dpkg -i ./cuda-repo-ubuntu1604_8.0.61-1_amd64.deb
fi
apt-get update
apt-get -y upgrade
apt-get -y install tmux build-essential gcc g++ make binutils software-properties-common cuda unzip
modprobe nvidia
nvidia-smi
@rahimnathwani
rahimnathwani / gce-create-from-snapshot.sh
Created March 20, 2017 12:11
Create GPU instance from previously-create snapshot
gcloud compute snapshots list
gcloud compute disks create deep-learning-persistent-disk-1 --size=25GB --source-snapshot=deep-learning-snapshot-1
gcloud beta compute instances create gpu-instance-1 \
--machine-type n1-standard-1 --zone asia-east1-a \
--accelerator type=nvidia-tesla-k80,count=1 \
--image-family ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --no-restart-on-failure \
--disk=auto-delete=yes,boot=yes,name=deep-learning-persistent-disk-1
gcloud compute instances add-tags gpu-instance-1 --tags https-server
@rahimnathwani
rahimnathwani / gce-create.sh
Created March 20, 2017 12:09
Create GPU instance on Google Cloud, for course.fast.ai
gcloud beta compute instances create gpu-instance-1 \
--machine-type n1-standard-1 --zone asia-east1-a \
--accelerator type=nvidia-tesla-k80,count=1 \
--image-family ubuntu-1604-lts --image-project ubuntu-os-cloud \
--maintenance-policy TERMINATE --no-restart-on-failure \
--boot-disk-size=25GB
import math
import random
def get_random_neighbour(state):
neighbour = [house[:] for house in state] # Deep copy
i, j = random.sample(xrange(5), 2)
attr_idx = random.randint(0, 4)
neighbour[i][attr_idx], neighbour[j][attr_idx] = neighbour[j][attr_idx], neighbour[i][attr_idx]
@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward