Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / aws-get_ip-update_sublime.py
Last active August 6, 2018 03:46
When you have a Sublime Text SFTP remote folder mapping to an Amazon AWS machine, everytime you reboot you have to update your Sublime SFTP config file so it knows where the folder/files are now. This ofcourse is massively tragic and should not be permitted in a civilized society. Hence this script. It even prints a connection string, so you can…
import json
import subprocess
"""EDIT FNAME TO UPDATE WITH YOUR LOCAL FILE PATH"""
FNAME = "/PATH/To/SUBLIME/SFTP/FILE/sftp-config.json"
def update_json_file(given_ip, filename):
jsonfile = open(filename, "r") # open the json file for reading
data = json.load(jsonfile) # read the json into the buffer
@why-not
why-not / pandas_data_reader_example.py
Created September 13, 2019 03:59
pandas data reader for stock data.
# command to install this library.
# conda install pandas-datareader
# example 1
import pandas_datareader as pdr
tsla = pdr.DataReader('tsla', data_source='google', start='2017-1-1')
# example 2
# calculates the trailing stop order price, can be used for weight loss like time series as well.
@why-not
why-not / sign_verify.sh
Last active February 3, 2022 05:49
Sign and Verify Using Public/Private Keys
# generate private key
openssl genrsa -out private_key.pem 4096
# extract public key
openssl rsa -in private_key.pem -pubout > public_key.pub
# sign using private key
openssl dgst -sign private_key.pem -keyform PEM -sha256 -out VGG_ILSVRC_16_layers.caffemodel.sign -binary VGG_ILSVRC_16_layers.caffemodel
# extract using public key
@why-not
why-not / multiplication_tables.py
Last active April 15, 2022 22:54
print multiplication tables for children, with color formatting if needed. (python, pandas)
import pandas as pd
import numpy as np
def style_dataframe(df, maxvals=None):
result = df.style
result.set_properties(**{'text-align': 'center'})
result.set_properties(**{'font-family': 'monospace'})
result.set_properties(**{'font-weight': 'bold'})
result.set_table_styles([
@why-not
why-not / useful_bash_functions.sh
Created November 2, 2022 21:45
useful bash functions backup.
function addpythonpath {
PYTHONPATH=$PYTHONPATH:`pwd`
sed -i '' '/^PYTHONPATH/d' ~/.bashrc
sleep .5
echo PYTHONPATH=$PYTHONPATH >> ~/.bashrc
}
# install yt-dlp first for this to work.
# streams youtube videos via VLC.
function ytvlc {
@why-not
why-not / get_stats_youtube.py
Created March 10, 2023 02:35
Code to get basic stats from videos in a given list of playlists (youtube)
import time
import pandas as pd
from googleapiclient.discovery import build
# Enter your API key here
api_key = "API KEY HERE"
# Create a service object for the YouTube API
youtube = build('youtube', 'v3', developerKey=api_key)
@why-not
why-not / shakespeare.txt
Created July 17, 2023 01:47
shakespeare
This file has been truncated, but you can view the full file.
First Citizen:
Before we proceed any further, hear me speak.
All:
Speak, speak.
First Citizen:
You are all resolved rather to die than to famish?
All: