Skip to content

Instantly share code, notes, and snippets.

@zzeleznick
zzeleznick / socket_cli.py
Created September 23, 2023 17:21
Socket Server and CLI
import argparse
import os
import socket
import subprocess
import time
from socket_lib import attach_cleanup_handler
from socket_lib import cleanup_server
host = 'localhost'
@zzeleznick
zzeleznick / ResumeableThread
Last active September 13, 2020 20:26
Resumable Threads with Timer
Name of the gist
@zzeleznick
zzeleznick / main.py
Created March 11, 2018 22:59
Unix Socket Server
import click
# Add this to avoid the annoying warning: http://click.pocoo.org/5/python3/
click.disable_unicode_literals_warning = True
import sys
from select import select
# Internal modules
from sockets import SocketServer, ThreadedSocketServer, SocketClient
def main():
@zzeleznick
zzeleznick / nested_env.py
Created October 20, 2017 18:40
Nested Virtualenvs
import sys
import os
import pip
import imp
import pkg_resources
from os.path import join, expanduser, dirname, realpath
import virtualenv
def check_venv(expected_path):
"""Check if we are running in a virtual env"""
@zzeleznick
zzeleznick / cloner.py
Created November 3, 2016 04:45
Clones repos for student projects to be graded
import os, sys
import subprocess
# Internal Python Modules
from get_urls import URLS
DEST = "repos"
class FileManager(object):
dest = DEST
@zzeleznick
zzeleznick / closest_points.py
Last active September 13, 2016 10:13
Finds the closest points (and minimum distance) from an array of points.
from __future__ import print_function
import time
import numpy as np
from scipy.spatial.distance import cdist
# from scipy.spatial.distance import euclidean
from bisect import bisect_left
import argparse
zprint = globals()['__builtins__'].print
@zzeleznick
zzeleznick / delta.py
Last active September 13, 2016 06:13
String Comparisons
from __future__ import print_function
import time
import math
import numpy as np
import argparse
FFT = np.fft.fft
IFFT = np.fft.ifft
zprint = globals()['__builtins__'].print
@zzeleznick
zzeleznick / piazza_hotkeys.js
Created September 6, 2016 16:39
Provides hotkey support for piazza. Paste into the Chrome Dev Console for use.
var piazza_hotkeys = function() {
/*
Provides hotkey support for navigating many posts on piazza.
1) a + alt: archives the current post and navigates to the previous post
2) i + alt: marks the current post as unread and navigates to the previous post
3) up + alt: navigates to the more recent post from current
4) down + alt: navigates to the older post
*/
// keycodes: https://css-tricks.com/snippets/javascript/javascript-keycodes/
const A = 65;
@zzeleznick
zzeleznick / GreedyDict.py
Last active August 9, 2016 16:33
Steals away keys from children
from collections import OrderedDict
"""Q: How do we define a data structure that makes it easy
to determine which keys should be passed to children
and which should be passed to report summaries.
And which keys should be promoted?
## Thoughts:
- CAPS_AND_UNDERSCORE signify importance
- Optional updates
- All keys should be passed to children by default
@zzeleznick
zzeleznick / buttons.swift
Last active March 6, 2016 23:37
A simple function to make buttons programmatically in swift
// MARK: - Storyboard Connections
@IBOutlet weak var letterContainer: UIView! // the UIView that will contain the buttons
// ... stuff
// MARK: Place method call in ViewDidLoad
func makeButtons(content: [String], margin: CGFloat, bottom: CGFloat) {
for i in 0...content.count-1 {
let button: UIButton = UIButton(type: UIButtonType.System)
button.setTitle(content[i], forState: UIControlState.Normal)