Skip to content

Instantly share code, notes, and snippets.

@why-not
why-not / stop-idle-azure-aws.py
Last active March 4, 2024 19:49
Automatically Shutting Down and Deallocating an AZURE or AWS VM (when idle AND no one is logged in via SSH)
#!/usr/bin/env python
# shell commands being automated.
# w
# aws ec2 stop-instances --instance-id INSTANCE_ID
# az vm deallocate --name NAME --resource-group RESOURCE_GROUP
"""
The script is the easy part, installing it into the unfriendly(imo) cron system and
@why-not
why-not / vector_intersection.md
Created December 11, 2016 05:04 — forked from hellpanderrr/vector_intersection.md
Python find intersection of two vectors using matplotlib and numpy
from numpy import dot,array,empty_like
from matplotlib.path import Path

def make_path(x1,y1,x2,y2):
    return Path([[x1,y1],[x1,y2],[x2,y2],[x2,y1]])

def perp( a ) :
    b = empty_like(a)
 b[0] = -a[1]
@why-not
why-not / README.md
Last active August 29, 2015 13:57 — forked from milroc/README.md

d3.unconf example gist. Fork it here.

@why-not
why-not / gist:5379296
Last active December 16, 2015 04:48
Given a folder full of jpegs, this gist prints out if you have a face in it which is frontal (not profile), and its ratio between face size and image size. If it finds more than one face, it treats it as if no faces were found. (Use case: profile pictures)
import sys, os
from cv import *
from cv2 import *
import glob
def detect_face(image):
"""Converts an image to grayscale and prints the ratio of face to image if _one_ face is found"""
grayscale = CreateImage((image.width, image.height), 8, 1)
CvtColor(image, grayscale, CV_BGR2GRAY)
@why-not
why-not / gist:4582705
Last active February 1, 2024 00:44
Pandas recipe. I find pandas indexing counter intuitive, perhaps my intuitions were shaped by many years in the imperative world. I am collecting some recipes to do things quickly in pandas & to jog my memory.
"""making a dataframe"""
df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
"""quick way to create an interesting data frame to try things out"""
df = pd.DataFrame(np.random.randn(5, 4), columns=['a', 'b', 'c', 'd'])
"""convert a dictionary into a DataFrame"""
"""make the keys into columns"""
df = pd.DataFrame(dic, index=[0])