Skip to content

Instantly share code, notes, and snippets.

@ken333135
ken333135 / genSankey
Created May 8, 2019 07:57
Wrapper Function to create Sankey Diagram from DataFrame
def genSankey(df,cat_cols=[],value_cols='',title='Sankey Diagram'):
# maximum of 6 value cols -> 6 colors
colorPalette = ['#4B8BBE','#306998','#FFE873','#FFD43B','#646464']
labelList = []
colorNumList = []
for catCol in cat_cols:
labelListTemp = list(set(df[catCol].values))
colorNumList.append(len(labelListTemp))
labelList = labelList + labelListTemp
@nikolas
nikolas / lerp-color.js
Last active June 29, 2023 14:12 — forked from rosszurowski/lerp-color.js
Linear interpolation for hexadecimal colors.
/**
* A linear interpolator for hex colors.
*
* Based on:
* https://gist.github.com/rosszurowski/67f04465c424a9bc0dae
*
* @param {Number} a (hex color start val)
* @param {Number} b (hex color end val)
* @param {Number} amount (the amount to fade from a to b)
*
@Teque5
Teque5 / popm2rb.py
Last active June 5, 2024 15:51
This script adds ratings from flac and mp3 files to Rhythmbox format while preserving the existing database. Rhythmbox uses XML database to store its music files, together with rating. However, it does not read the ID3 rating frame of a music file if it exists, making it harder for people transferring rated music from other player to this one (f…
#!/usr/bin/env python3
"""
popm2rhythmBox
Convert saved audio file rating formats
┌──────┐ ┌─────────┐
│Winamp├───►RhythmBox│
└──────┘ └─────────┘
inspired by https://github.com/shatterhand19/RhythmboxPOPM
@nabilfreeman
nabilfreeman / lambda-redirect-to-trailing-slash.js
Last active March 7, 2023 20:31
Redirect to trailing slashes on CloudFront with AWS Lambda. (all this because S3 uses 302 redirects instead of 301)
'use strict';
const path = require('path')
const redirect = new_url => {
return {
status: '301',
statusDescription: 'Moved Permanently',
headers: {
location: [{
@shospodarets
shospodarets / Chrome headless Puppeteer- capture DOM element screenshot using
Last active January 17, 2023 18:52
Chrome headless Puppeteer- capture DOM element screenshot using
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Adjustments particular to this page to ensure we hit desktop breakpoint.
page.setViewport({width: 1000, height: 600, deviceScaleFactor: 1});
await page.goto('https://www.chromestatus.com/samples', {waitUntil: 'networkidle'});
@crittermike
crittermike / wget.sh
Last active March 26, 2024 22:49
Download an entire website with wget, along with assets.
# One liner
wget --recursive --page-requisites --adjust-extension --span-hosts --convert-links --restrict-file-names=windows --domains yoursite.com --no-parent yoursite.com
# Explained
wget \
--recursive \ # Download the whole site.
--page-requisites \ # Get all assets/elements (CSS/JS/images).
--adjust-extension \ # Save files with .html on the end.
--span-hosts \ # Include necessary assets from offsite as well.
--convert-links \ # Update links to still work in the static version.
@bdkent
bdkent / createFullWidthMasonry.jsx
Last active February 10, 2019 21:46
react-virtualized <AutoSizer> + <Masonry>
var DEFAULT_CELL_HEIGHT = 250;
var DEFAULT_CELL_SPACING = 10;
function createFullWidthMasonry(props) {
var cellSpacing = props.cellSpacing || DEFAULT_CELL_SPACING;
var cellHeight = props.cellHeight || DEFAULT_CELL_HEIGHT;
var keyMapper = props.keyMapper || _.identity();
@mmoehrlein
mmoehrlein / s3-dropzone-upload.php
Created March 8, 2017 12:10
s3 upload with dropzone.js
<?php
// AWS data
$bucketName = "BUCKET-NAME";
$AWSAccessKeyId = "XXXXXXXXXXXXXXXXXXXX";
$AWSSecretAccessKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$date = date("Y-m-d");
$dateISO = date("Ymd");
$validTill = date('Y-m-d\TH:i:s.000\Z', time() + (60 * 60 * 4)); // 4 hours
@dalgu90
dalgu90 / count_ckpt_param.py
Last active September 8, 2022 00:40
Count the number of parameter in a TensorFlow checkpoint file. (Usage: python count_ckpt_param.py path-to-ckpt)
#!/usr/bin/env python
import sys
import tensorflow as tf
import numpy as np
if len(sys.argv) == 2:
ckpt_fpath = sys.argv[1]
else:
print('Usage: python count_ckpt_param.py path-to-ckpt')
@jlongster
jlongster / immutable-libraries.md
Last active May 6, 2024 12:37
List of immutable libraries

A lot of people mentioned other immutable JS libraries after reading my post. I thought it would be good to make a list of available ones.

There are two types of immutable libraries: simple helpers for copying JavaScript objects, and actual persistent data structure implementations. My post generally analyzed the tradeoffs between both kinds of libraries and everything applies to the below libraries in either category.

Libraries are sorted by github popularity.

Persistent Data Structures w/structural sharing