Skip to content

Instantly share code, notes, and snippets.

View tmasjc's full-sized avatar
Strange Loop

Thomas Jc tmasjc

Strange Loop
  • Dumpling City
  • 04:55 (UTC +08:00)
View GitHub Profile
#!/usr/bin/env python3
import argparse
import configparser
import sqlite3
import openai
import pinecone
config = configparser.ConfigParser()
config.read("config.ini")
from getpass import getpass
from pprint import pprint
from neo4j import GraphDatabase
from pymongo import MongoClient
## get data from document database ----
mongodb_password = getpass("Enter Atlas password:")
client = MongoClient(
f"mongodb+srv://admin:{mongodb_password}@serverlessinstance0.9vrdx.mongodb.net"
)
@tmasjc
tmasjc / fizz_buzz.swift
Created November 26, 2022 07:37
Fizz Buzz demo in Swift
// if x is a multiple of 3 then output "fizz",
// if x is a multiple of 5 then output "buzz"
// if x is a multiple of 15 then output "fizz buzz"
// basic
func fizz_buzz_alpha(max: Int) -> () {
for number in 1...max {
if number % 15 == 0 {
print("fizz buzz")
} else if number % 3 == 0 {
library(tidyverse)
library(hrbrthemes)
library(janitor)
library(survival)
library(survminer)
library(shiny)
library(miniUI)
theme_set(theme_ipsum())
pals <- rownames(RColorBrewer::brewer.pal.info)
@tmasjc
tmasjc / project_network.R
Created July 2, 2021 04:08
Network visualization of team projects
library(tidyverse)
library(networkD3)
raw <- pins::pin_get("projects", "local")
df <- raw %>%
mutate(associate = str_split(associate, pattern = ",|、")) %>%
unnest_longer(associate) %>%
filter(!is.na(associate)) %>%
count(owner, associate)
@tmasjc
tmasjc / spacemacs-cheatsheet.md
Created February 11, 2021 05:30 — forked from davoclavo/spacemacs-cheatsheet.md
Spacemacs cheatsheet

emacs --daemon to run in the background. emacsclient.emacs24 <filename/dirname> to open in terminal

NOTE: "M-m and SPC can be used interchangeably".

  • Undo - C-/
  • Redo - C-?
  • Change case: 1. Camel Case : M-c 2. Upper Case : M-u
  1. Lower Case : M-l
@tmasjc
tmasjc / .R
Created December 23, 2020 13:27
library(tidyverse)
library(tidymodels)
sf_trees <- read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-28/sf_trees.csv")
trees_df <- sf_trees %>%
mutate(
legal_status = case_when(
legal_status == "DPW Maintained" ~ legal_status,
TRUE ~ "Other"

Primary Approaches to Local Interpretation

source: https://bradleyboehmke.github.io/HOML/iml.html

Local Interpretable Model-Agnostic Explanations

Assumptions:

  • Every model is linear on a local scale;
  • It is possible to fit a simple surrogate model around a single observation that will mimic how the global model behaves at the locality;
@tmasjc
tmasjc / sql_example.py
Last active October 20, 2020 13:31
Obtain data from SQL in Python
# %%
import configparser
import mysql.connector
from mysql.connector import Error
import pandas as pd
from openpyxl import load_workbook
from openpyxl.utils.dataframe import dataframe_to_rows
config = configparser.ConfigParser()
config.read("config.ini")
@tmasjc
tmasjc / mail_example.py
Last active October 20, 2020 13:30
Sending email with attachment thru Python
# %%
import configparser
import pandas as pd
import smtplib
from socket import gaierror
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText