Skip to content

Instantly share code, notes, and snippets.

View jelc53's full-sized avatar

Julian Cooper jelc53

  • Stanford University; BCG Gamma
  • Sydney, Australia
View GitHub Profile
@jelc53
jelc53 / setup.sh
Last active March 18, 2023 18:11
setup instructions for sail server
# pseudo-setup script, obviously replace djenson with your id everywhere
# login; don't do any computation/data moving on the head node, you'll get cancelled
ssh djenson@sc.stanford.edu
# generate ssh keys (on sc head node)
# NOTE: just press enter and skip adding a password (it's fine)
# https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
ssh-keygen -t ed25519 -C "djenson@stanford.edu"
cat ~/.ssh/id_rsa.pub # copy output and add it on github: https://github.com/settings/keys
@jelc53
jelc53 / git_funcs.sh
Last active March 18, 2023 18:11 — forked from danjenson/git_funcs.sh
collection of simple git functions
#!/bin/bash
# source this file from your ~/.bashrc, i.e. `source git_funcs.sh`
# run this before making changes, otherwise you'll need to deal with merge conflicts
# usage: gitu
gitu () { git pull --rebase; }
# add it all, push it all, fuck the police
# usage: gitx
gitx () {
@jelc53
jelc53 / multiproccess.py
Last active March 20, 2023 03:07
multiprocessing script
#!/usr/bin/env python3
import argparse
import asyncio
import json
import multiprocessing as mp
import subprocess
import sys
def rage(n_cpu: int = mp.cpu_count()):
@jelc53
jelc53 / load_glob.py
Created March 20, 2023 03:06
glob load script
import torch
import os
from glob import glob
from progressbar import ProgressBar
if __name__ == '__main__':
proof_steps = glob(os.path.join('proof_steps_gnn', '**', '*.pt'), recursive=True)
# print(proof_steps)
bar = ProgressBar(max_value = len(proof_steps))
for i, filename in enumerate(proof_steps):
@jelc53
jelc53 / tab.asciidoc
Last active March 22, 2023 00:54
ascii results table 1
Ref Conv. Type Pooling Attention Embedding Accuracy (%) Correct (/237)

1

GraphSage

max

rich

integer

17.7%

42

2

GraphSage

mean

rich

integer

13.1%

31

3

GAT

max

rich

integer

11.4%

27

@jelc53
jelc53 / tab.asciidoc
Created March 22, 2023 00:52
ascii results table 2
Model Conv. Type Pooling Attention Embedding Accuracy (%) Correct (/237)

ASTactic

n/a

n/a

n/a

n/a

14.8%

35

Ref 1

GraphSage

max

rich

integer

19.4%

46

Ref 4

GAT

mean

rich

integer

17.3%

41

@jelc53
jelc53 / dataclass.py
Created March 29, 2023 17:29
python dataclass template
from typing import Generic, TypeVar
from abc import ABC, abstractmethod
from dataclasses import dataclass
import numpy as np
A = TypeVar("A") # type variable named "A"
class Distribution(ABC, Generic[A]): # abstract base class (interface)
@abstractmethod
def sample(self) -> A:
@jelc53
jelc53 / generator.py
Last active March 29, 2023 17:42
python iterator and generator abstractions
def sqrt(a: float) -> Iterator[float]:
"""
With this version, we update x at each iteration and then yield the updated value. In-
stead of getting a single value, the caller of the function gets an iterator that contains an
infinite number of iterations; it is up to the caller to decide how many iterations to evalu-
ate and when to stop.
"""
x = a / 2 # initial guess
while True:
x = (x + (a / x)) / 2
@jelc53
jelc53 / colab_memory.txt
Created April 7, 2023 18:25
hack to increase colab ram allocation
# run in colab cell
l = []
while(Ture):
l.extend("cs246")
@jelc53
jelc53 / gdb_stack.sh
Last active April 8, 2023 05:22
gdb commands to interrogate stackframe
# -----------------------------------------------------------------------------------------
# Example application of gdb to understand address logic of buffer overflow exploit
# Our exploit creates a buffer, writes to file, creates target with file as arg
# Target then reads file to a buffer and then uses the data in that file to open shell
# -----------------------------------------------------------------------------------------
# First compile everything ----------------------------------------------------------------
cd proj1/xploits/
make