Skip to content

Instantly share code, notes, and snippets.

public class IntLinkedList {
public class IntNode {
public int item;
private IntNode next;
public IntNode(int i, IntNode n) {
item = i;
next = n;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@afraenkel
afraenkel / groupwise_leave_one_out.py
Created June 16, 2019 22:23
Groupwise leave one out
import pandas as pd
import numpy as np
# download data for example
from sklearn.datasets.california_housing import fetch_california_housing
d = fetch_california_housing()
df = pd.DataFrame(d['data'], columns=d['feature_names'])
@afraenkel
afraenkel / partition.py
Created May 10, 2019 07:42
PySpark: partitioning groups of events that occur within 90 days of previous.
import pyspark
from pyspark import SparkContext
from pyspark.sql import SQLContext
from pyspark.sql import functions as F
from pyspark.sql import types as T
from pyspark.sql import Window
sc = SparkContext()
sqlc = SQLContext(sc)
import os
from pathlib import Path
from subprocess import Popen
import boto3
import zipfile
# This script downloads all files from `download_bucket` to the ec2 instance (specified temp dir),
# unzips them on the instance
# creates the output bucket,
# uploads the unzipped file to the new bucket
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@afraenkel
afraenkel / start-tunnel.sh
Last active August 21, 2018 20:26
start an ssh tunnel to an ec2-instance given the name of the instance
#!/bin/bash
# need aws commandline interface installed (do "pip install awscli")
# need aws credentials set-up
# usage: start-tunnel.sh <INSTANCE-NAME>
instance_name=$1
key_name=$(aws ec2 \