Skip to content

Instantly share code, notes, and snippets.

@ibeex
ibeex / foo.log
Created August 4, 2012 13:46
Flask logging example
A warning occurred (42 apples)
An error occurred
@jaytaylor
jaytaylor / camel_case_to_snake_case.py
Created September 6, 2012 21:41
Convert camel-case to snake-case in python.
#!/usr/bin/env python
"""
Convert camel-case to snake-case in python.
e.g.: CamelCase -> snake_case
Relevant StackOverflow question: http://stackoverflow.com/a/1176023/293064
"""
@magicznyleszek
magicznyleszek / css-selectors.md
Last active March 29, 2024 01:12
CSS Selectors Cheatsheet

CSS Selectors Cheatsheet

Hi! If you see an error or something is missing (like :focus-within for few years :P) please let me know ❤️

Element selectors

Element -- selects all h2 elements on the page

h2 {
@tgarc
tgarc / example_usage
Last active March 25, 2022 13:44
Jekyll IPython notebook converter
ipython nbconvert --to markdown <notebook>.ipynb --config jekyll.py
@dsal1951
dsal1951 / Calculate Model Lift
Created July 4, 2016 05:53
Data needed for a Lift chart (aka Gains chart) for a predictive model created using Sklearn and Matplotlib
def calc_lift(x,y,clf,bins=10):
"""
Takes input arrays and trained SkLearn Classifier and returns a Pandas
DataFrame with the average lift generated by the model in each bin
Parameters
-------------------
x: Numpy array or Pandas Dataframe with shape = [n_samples, n_features]
y: A 1-d Numpy array or Pandas Series with shape = [n_samples]
@benzap
benzap / youtube2mp3.py
Last active May 3, 2022 05:39
Youtube to MP3 Downloader Script
#!/bin/env python
# Requires: youtube_dl module
# Requires: ffmpeg
# Usage:
#
# python youtube2mp3.py <URL>, ...
#
# Example:
#
# python youtube2mp3.py https://www.youtube.com/watch?v=dQw4w9WgXcQ
@mda590
mda590 / stress_test.py
Created June 8, 2018 14:07
Python script useful for stress testing systems
"""
Produces load on all available CPU cores.
Requires system environment var STRESS_MINS to be set.
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
import time
import os
@artificialsoph
artificialsoph / jupyter_ngrok.md
Last active May 30, 2024 04:24
Quickest way to get Jupyter notebook running on a remote server.

Log into your server with ssh, something like

ssh -i "my_secret.pem" ubuntu@12.123.12.123

If it's a new server, you'll need to install a few things.

Install conda with

from PIL import Image, ImageOps
def padding(img, expected_size):
desired_size = expected_size
delta_width = desired_size - img.size[0]
delta_height = desired_size - img.size[1]
pad_width = delta_width // 2
pad_height = delta_height // 2
padding = (pad_width, pad_height, delta_width - pad_width, delta_height - pad_height)
@jdbcode
jdbcode / get-hex-colors.py
Last active April 11, 2024 20:09
Get a list of n hex colors for a given matplotlib palette
# Source: https://stackoverflow.com/a/33597599/5391200
from pylab import *
cmap = cm.get_cmap('seismic', 5) # matplotlib color palette name, n colors
for i in range(cmap.N):
rgb = cmap(i)[:3] # will return rgba, we take only first 3 so we get rgb
print(matplotlib.colors.rgb2hex(rgb))
cmap = cm.get_cmap('plasma', 101)