Skip to content

Instantly share code, notes, and snippets.

View richard-to's full-sized avatar

Richard To richard-to

View GitHub Profile
@richard-to
richard-to / mesop_chat_gemini.py
Created September 4, 2024 14:43
Simple chat example using Gemini with Mesop.
import os
import google.generativeai as genai
import mesop as me
import mesop.labs as mel
genai.configure(api_key=os.getenv("GOOLGLE_API_KEY"))
SYSTEM_INSTRUCTION = "Talk like Shakespeare."
@richard-to
richard-to / timer.py
Created July 12, 2024 16:54
Simple timer context manager
@contextmanager
def timer(name):
"""Context manager for timing code blocks with custom name."""
start_time = time.time()
yield
end_time = time.time()
elapsed_time = (end_time - start_time) * 1000
print(f"{name} took {elapsed_time:.2f} ms")
@richard-to
richard-to / gist:cbab2ec06345a2d6b48c3354088ae168
Created February 21, 2021 02:23
Gitlab Collapse Markup - Details/Summary
<p>
<details>
<summary>Click this to collapse/fold.</summary>
These details <em>remain</em> <strong>hidden</strong> until expanded.
<pre><code>PASTE LOGS HERE</code></pre>
</details>
</p>
@richard-to
richard-to / gist:546a17276dceb087b5a5a3662618dc0f
Created February 21, 2021 02:22
Git reset master to origin
git checkout -B master origin/master
conda create --name name python=3.7
conda activate name
conda deactivate
alembic init
alembic revision --autogenerate -m "Migration comment"
alembic upgrade head
@richard-to
richard-to / gist:70049650cf58f1858b8cd38528c07a3c
Last active September 1, 2016 00:32
ES6 Features - based on examples from http://es6-features.org/
// Constants
const test_const = 1;
// Scoped variables - use `let` for local scope
let callbacks = [];
for (let i = 0; i < 3; ++i) {
callbacks[i] = function() { return i; };
}
// Arrow functions
@richard-to
richard-to / calendar.js
Created June 30, 2015 20:07
Random code
var CalendarViewType = {
CALENDAR: 1,
MONTH: 2,
YEAR: 3
};
var DAYS_IN_WEEK = 7;
var MONTHS_IN_YEAR = 12;
import csv
import numpy as np
from sklearn import cross_validation
from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
from sklearn.feature_selection import SelectPercentile, f_classif, chi2
from sklearn.naive_bayes import MultinomialNB, BernoulliNB
from sklearn.metrics import accuracy_score, classification_report
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline