Skip to content

Instantly share code, notes, and snippets.

View rcdilorenzo's full-sized avatar
🙌
Working in His Kingdom (Col 3:17)

Christian Di Lorenzo rcdilorenzo

🙌
Working in His Kingdom (Col 3:17)
View GitHub Profile
@rcdilorenzo
rcdilorenzo / covariance.py
Last active April 18, 2022 15:40
How to calculate a covariance matrix
import numpy as np
from sklearn.datasets import load_iris
from sklearn.decomposition import PCA
def covariance(M: np.ndarray) -> np.ndarray:
"""
Compute sample covariance matrix from data M.
NOTE: M is assumed to be of shape (nrows, ncols).
import numpy as np
from typing import Callable, Optional, List
from pydantic import BaseModel
from tqdm.notebook import tqdm
from math import ceil, isnan, inf
class Activation(BaseModel):
forward: Callable[[np.ndarray], np.ndarray] # input -> output
backward: Callable[[np.ndarray, np.ndarray], np.ndarray] # (dA, X) -> gradients
@rcdilorenzo
rcdilorenzo / convertToJSONSchema.test.ts
Last active November 18, 2021 00:25
Helper to convert io-ts types to JSON Schema (to be extracted to open source NPM package)
import * as t from 'io-ts';
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import { fromNullable } from 'io-ts-types/lib/fromNullable';
import convertToJSONSchema from './convertToJSONSchema';
import isoString from './isoString';
const SampleObject = t.strict(
{
aString: t.string,
@rcdilorenzo
rcdilorenzo / worldclass-save-discussions.js
Created March 16, 2019 18:34
A puppeteer script to download all discussions for a given WorldClass topic (assumes WORLDCLASS_DOMAIN environment is set)
const puppeteer = require('puppeteer');
const read = require('read');
const htmlToText = require('html-to-text').fromString;
const R = require('ramda');
const Promise = require('bluebird');
const fs = require('fs');
const download = require('@jinphen/download2');
const { CookieJar } = require('tough-cookie');
const mapSeries = R.flip(Promise.mapSeries);
@rcdilorenzo
rcdilorenzo / utils.js
Created November 16, 2018 01:11
Transpose list of objects to an object with each property as a list of the values
// ========
// Usage
// ========
// > const { transposeObjects } = require('./utils');
// undefined
// > transposeObjects([
// ... { key1: 'object1key1', key2: 'object1key2' },
// ... { key1: 'object2key1', key2: 'object2key2' }
// ... ])
// { key1: [ 'object1key1', 'object2key1' ],
@rcdilorenzo
rcdilorenzo / resize-images.sh
Created November 3, 2018 17:32
Sample code from rcd.ai blog post
#!/bin/bash
# resize-images.sh
# Preprocess Stanford Cars Dataset
# Stats for width
# ❯ ls cars_**/*.jpg |
# xargs -L1 identify -format "%w\n" |
# datamash min 1 max 1 mean 1 median 1
#
# 78 7800 700.49255483472 640
@rcdilorenzo
rcdilorenzo / eda.r
Last active July 14, 2018 19:33
Collection of helpful EDA functions in R (originally created for M.S. in Data Science assignment work at Regis University)
hist.density <- function (data, xlab = "<x>", font.main = 1,
main = "Histogram of data") {
# Calculate histogram based on these values
data.hist = hist(data, plot = FALSE)
# Determine scaling factor
multiplier = data.hist$counts / data.hist$density
# Create density function of the area
# Assumes an existing data frame called `raw`
# that is directly imported from the URL and
# has not converted the "?" values to NA's
colnames(raw) <- c("Type", "CapShape", "CapSurface", "CapColor", "Bruises",
"Odor", "GillAttachment", "GillSpacing", "GillSize",
"GillColor", "StalkShape", "StalkRoot",
"StalkSurfaceAboveRing", "StalkSurfaceBelowRing",
"StalkColorAboveRing", "StalkColorBelowRing", "VeilType",
"VeilColor", "RingNumber", "RingType", "SporePrintColor",
@rcdilorenzo
rcdilorenzo / bisynoptic_text_analysis.py
Last active December 3, 2017 01:32
Text analysis comparison between the Synoptic Gospels Matthew and Luke. Created as a part of a graduate assignment for an M.S. in Data Science from Regis University. (Simply run `python bisynoptic_text_analysis.py` from the current directory with all the files downloaded)
from word_frequency import WordFrequency
luke = WordFrequency('Luke', './Luke.txt')
matthew = WordFrequency('Matt', './Matthew.txt')
print('================================')
print('= Frequently Occurring Phrases =')
print('= Between Matthew & Luke (Max =')
print('= 4 words/phrase, Min freq 15) =')
print('================================')
@rcdilorenzo
rcdilorenzo / change-harvest-format.md
Created November 13, 2017 16:54
Change format for newer (2017) Harvest installs from the App Store

To read your settings, run:

defaults read ~/Library/Containers/com.getharvest.harvestxapp/Data/Library/Preferences/group.com.getharvest.Harvest.Documents.plist

To change the time format to HH:MM, run

defaults write ~/Library/Containers/com.getharvest.harvestxapp/Data/Library/Preferences/group.com.getharvest.Harvest.Documents.plist TimeFormat hours_minutes

Restart the Harvest App, and it should now display HH:MM (I tested this)