Skip to content

Instantly share code, notes, and snippets.

View tmasjc's full-sized avatar
Strange Loop

Thomas Jc tmasjc

Strange Loop
  • Singapore
  • 10:05 (UTC +08:00)
View GitHub Profile
@tmasjc
tmasjc / temp.py
Created December 22, 2024 14:55
RQI evaluation
from openai import OpenAI
from configparser import ConfigParser
import json
config = ConfigParser()
config.read("config.ini")
def read_file(filename: str) -> str:
with open(filename, 'r', encoding='utf-8') as f:
@tmasjc
tmasjc / find_unique_strings.R
Last active December 13, 2024 15:46
寻找最相似或最不相似的长字符串
library(tidyverse)
library(text2vec)
library(stopwords)
library(jsonlite)
library(listviewer)
raw <- read_csv(rstudioapi::selectFile())
preprocess <- function(x, special_keywords) {
x |>
@tmasjc
tmasjc / sankey.R
Created December 4, 2024 15:50
Transform data and draw a Sankey diagram.
library(tidyverse)
library(highcharter)
raw <- readr::read_rds("sample.rds")
weight = "XXXX" # replace with correct column
vpouch <- raw |>
select(-matches(weight)) |>
names() |>
(\(x)
#!/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"