Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / migrateHeroicons.js
Last active March 29, 2024 11:34 — 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 / hash_array_to_csv.rb
Created June 6, 2014 04:26
Ruby hash array to CSV
class Array
def to_csv(csv_filename="hash.csv")
require 'csv'
CSV.open(csv_filename, "wb") do |csv|
csv << first.keys # adds the attributes name on the first line
self.each do |hash|
csv << hash.values
end
end
end
@christiangenco
christiangenco / download website assets
Created January 20, 2014 23:23
Use wget to download a website's assets, including images, css, javascript, and html. From http://www.linuxjournal.com/content/downloading-entire-web-site-wget
$ wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--domains website.org \
--no-parent \
www.website.org/tutorials/html/
@christiangenco
christiangenco / download_egghead_videos.md
Last active January 29, 2024 03:16 — forked from ldong/download_egghead_videos.md
download egghead videos
@christiangenco
christiangenco / hn_impersonator.rb
Created October 7, 2014 18:46
Impersonate your favorite HN commenter
require 'http'
require 'json'
require 'peach'
require 'gabbler'
require 'pry'
USERNAME = "patio11"
unless File.exists?("comments.txt")
def get_json(url)
@christiangenco
christiangenco / signup.html
Last active October 14, 2023 06:47
Bootstrap ajax email signup form for sendy.co
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js" ></script>
<title>AJAX Signup</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
@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 / 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";