Skip to content

Instantly share code, notes, and snippets.

View christiangenco's full-sized avatar

Christian Genco christiangenco

View GitHub Profile
@christiangenco
christiangenco / example_embedding.js
Created April 17, 2024 19:06
Javascript + OpenAI Embedding Example
import "dotenv/config";
import { dot, norm, add, subtract } from "mathjs";
import OpenAI from "openai";
const openai = new OpenAI({ apiKey: process.env.OPENAI_KEY });
function cosineSimilarity(array1, array2) {
const dotProduct = dot(array1, array2);
const normA = norm(array1);
const normB = norm(array2);
const cosineSimilarity = dotProduct / (normA * normB);
@christiangenco
christiangenco / snapThings.rb
Last active July 13, 2023 14:47
Convert Things database into csv and json
#!/usr/bin/env ruby
# require 'sqlite3'
require 'shellwords'
require 'json'
require 'csv'
# require 'pry'
def tasks_to_csv(sqlite3_path, dest_path)
query = 'select TASK.*, AREA.title as areaTitle, PROJECT.title as projectTitle, HEADING.title as headingTitle'
@christiangenco
christiangenco / migrateHeroicons.js
Last active September 5, 2024 07:59 — forked from PicchiKevin/migrate.sh
Heroicons v1 to v2
const fs = require("fs");
if (!fs.existsSync("package.json")) {
console.error(
"Cannot find package.json. Please run this script in your project directory."
);
process.exit(1);
}
const package = fs.readFileSync("package.json", "utf8");
@christiangenco
christiangenco / nerdle_wordlist.txt
Last active April 30, 2024 11:33
Here's my best shot at a the 17,723-long wordlist for https://nerdlegame.com/
11-2-9=0
11-3-8=0
11-4-7=0
11-5-6=0
11-6-5=0
11-7-4=0
11-8-3=0
11-9-2=0
12-2*6=0
12-3-9=0
@christiangenco
christiangenco / Example.js
Created January 29, 2022 16:46
useStripe React Hooks for Stripe Firebase extension
import { Fragment, useEffect } from "react";
import {
useProducts,
useSubscriptions,
useStripeRole,
visitPortal,
useCreateCheckoutSession,
} from "hooks/useStripe";
@christiangenco
christiangenco / process.rb
Created April 15, 2021 15:18
Crop a bunch of burst photos and stitch them together into a video
paths = Dir.glob("*.jpg")
`mkdir -p cropped`
paths.sort.each_with_index{|path, i|
cropped_path = "cropped/#{i.to_s.rjust(2, "0")}.jpg"
starting_width = 3834
starting_height = 5751
width = starting_width
height = starting_width
@christiangenco
christiangenco / Example.js
Created February 27, 2021 17:31
React hook for mousetrap
import React from "react";
import useMousetrap from "./hooks/useMousetrap";
export default function Example(){
useMousetrap({
a: () => console.log("you pressed a"),
"ctrl+space": () => console.log("you pressed ctrl+space");
});
return "lol hi";
}
@christiangenco
christiangenco / ViewController.swift
Created December 30, 2020 02:13
Minimal macOS Swift app to show webcam video in a custom NSView
import Cocoa
import AVFoundation
// inspiration: https://www.youtube.com/watch?v=1_PUdhLQsZQ
class ViewController: NSViewController {
@IBOutlet weak var videoView: NSView!
private var cameraSession = AVCaptureSession()
private var camera: AVCaptureDevice!
@christiangenco
christiangenco / OpenJournalReferencedOnThisLine.py
Created October 10, 2020 18:47
Sublime Text 3 plugin to run a terminal command based on the contents of the line that the cursor is on
import sublime
import sublime_plugin
import re
import os
class OpenJournalReferencedOnThisLineCommand(sublime_plugin.TextCommand):
def run(self, edit):
region = self.view.sel()[0]
line_range = self.view.line(region)
line = self.view.substr(line_range)
@christiangenco
christiangenco / MarkdownCheckboxes.py
Created June 3, 2020 21:39
Sublime Text 3 plugin to toggle and timestamp markdown todo checkboxes
# ~/.config/sublime-text-3/Packages/User/MarkdownCheckboxes.py
import sublime, sublime_plugin
import re
from time import strftime
def now():
return strftime("%Y-%m-%dT%H:%M:%S")
timestampRegex = r"\s*\(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\)"