Skip to content

Instantly share code, notes, and snippets.

Avatar
🙌
Working in His Kingdom (Col 3:17)

Christian Di Lorenzo rcdilorenzo

🙌
Working in His Kingdom (Col 3:17)
View GitHub Profile
@rcdilorenzo
rcdilorenzo / convertToJSONSchema.test.ts
Created May 12, 2020
Helper to convert io-ts types to JSON Schema (from JupiterOne, to be extracted to open source NPM package)
View convertToJSONSchema.test.ts
import * as t from 'io-ts';
import convertToJSONSchema from './convertToJSONSchema';
import Ajv from 'ajv';
import { fromNullable } from 'io-ts-types/lib/fromNullable';
import isoString from './isoString';
const SampleObject = t.strict({
aString: t.string,
nullableString: fromNullable(t.string, 'a default'),
@rcdilorenzo
rcdilorenzo / worldclass-save-discussions.js
Created Mar 16, 2019
A puppeteer script to download all discussions for a given WorldClass topic (assumes WORLDCLASS_DOMAIN environment is set)
View worldclass-save-discussions.js
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 Nov 16, 2018
Transpose list of objects to an object with each property as a list of the values
View utils.js
// ========
// Usage
// ========
// > const { transposeObjects } = require('./utils');
// undefined
// > transposeObjects([
// ... { key1: 'object1key1', key2: 'object1key2' },
// ... { key1: 'object2key1', key2: 'object2key2' }
// ... ])
// { key1: [ 'object1key1', 'object2key1' ],
@rcdilorenzo
rcdilorenzo / resize-images.sh
Created Nov 3, 2018
Sample code from rcd.ai blog post
View resize-images.sh
#!/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 Jul 14, 2018
Collection of helpful EDA functions in R (originally created for M.S. in Data Science assignment work at Regis University)
View eda.r
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
View mushroom-label.r
# 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 Dec 3, 2017
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)
View bisynoptic_text_analysis.py
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 Nov 13, 2017
Change format for newer (2017) Harvest installs from the App Store
View change-harvest-format.md

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)

@rcdilorenzo
rcdilorenzo / main.go
Last active Aug 17, 2017
Golang port (for fun/school) of simple recommendation system from http://guidetodatamining.com/chapter2/
View main.go
package main
import (
"fmt"
"math"
"sort"
)
type Recommendation struct {
Name string
@rcdilorenzo
rcdilorenzo / Button.swift
Created Jul 19, 2017
Various iOS extensions for creating reusable views in code
View Button.swift
import UIKit
extension UIButton {
static func createBordered(light: Bool) -> UIButton {
let button = UIButton(type: .roundedRect)
button.contentEdgeInsets = UIEdgeInsets(top: 5, left: 7, bottom: 5, right: 7)
button.layer.cornerRadius = 5
button.translatesAutoresizingMaskIntoConstraints = false
if (light) {
button.backgroundColor = UIColor.white