Skip to content

Instantly share code, notes, and snippets.

View jflam's full-sized avatar

John Lam jflam

View GitHub Profile
@jflam
jflam / Copy Paste Clipboard Snippet
Last active March 23, 2024 17:13
Create a new snippet from a blank template.
name: Blank snippet
description: Create a new snippet from a blank template.
host: EXCEL
api_set: {}
script:
content: |
$("#copy").on("click", () => tryCatch(copy));
$("#paste").on("click", () => tryCatch(paste));
async function copy() {
@jflam
jflam / mittens.py
Created January 24, 2023 04:59
Character Chess: GPT 3.5 and Stockfish team up!
import base64, chess.svg, re, stockfish, openai, os
import streamlit as st
from streamlit_chat import message
from langchain.prompts import PromptTemplate
chess_move_regex = re.compile(r"([KQBNR]?[a-h]?[1-8]?x?[a-h][1-8])([+#]?|=[QBNR])")
CHARACTER = "Yoda"
house_prompt = PromptTemplate(
input_variables=["character", "my_move", "your_move"],
@jflam
jflam / citations_bing.py
Created January 21, 2023 17:05
Citations Needed with Bing and Azure Open AI
# Updated version which uses Bing Search API (you'll need to sign up - free
# tier available) It also uses the Azure OpenAI service.
import streamlit as st
import json, os, requests, openai
from langchain.prompts import PromptTemplate
# You'll only need this for public OpenAI endpoint
openai.api_key = os.environ["OPENAI_API_KEY"]
@jflam
jflam / deepwrangler.py
Created January 17, 2023 19:27
Prompt engineering with pandas and GPT-3
import inspect
import pandas as pd
from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI
from IPython.display import display, Markdown
llm = OpenAI(temperature=0.2, max_tokens=1000)
prompt = PromptTemplate(
input_variables=[
"df_name",
@jflam
jflam / app.py
Created January 16, 2023 02:55
Citations needed
# To run you'll need some secrets:
# 1. SERPAPI_API_KEY secret in env var - get from https://serpapi.com/
# 2. OPENAI_API_KEY secret in env var - get from https://openai.com
import streamlit as st
import json, os
from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI
from serpapi import GoogleSearch
@jflam
jflam / 1_Historical_Federal_Revenues_And_Outlays.ipynb
Created October 9, 2017 21:25
Historical Federal Revenues and Outlays
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jflam
jflam / outlook_macros.vb
Last active January 27, 2016 17:13
Use quick access toolbar in Outlook to accelerate mail handling via ALT-1, ALT-2 etc. keybindings.
' How to setup this macro:
'
' Assumes you have 3 folders setup called Archives, Followup P1 and Followup P2
' To setup key bindings:
' 1. Hit ALT-F11 to open the VBA Window
' 2. Right-click on Project1 and select Insert/New Module
' 3. Paste this gist into the Module and save
' 4. Right-click on the top-most toolbar in VS (above the File/Home/Send ... menu) - this is called the Quick Access Toolbar
' 5. The Outlook Options dialog appears. On the Choose commands from: dropdown, select Macros. You'll see your macros there.
' 6. Add the macros to the toolbar by clicking on the Add >> button. The first macro on the list is bound to ALT-1, second ALT-2 etc.
@jflam
jflam / invoke.cs
Created January 15, 2011 00:17
Dynamic Invocation via DLR
static object InvokeInstanceMethod(object thisParameter, string methodName, Type[] typeArguments, params object[] args) {
CSharpArgumentInfo[] parameterFlags = new CSharpArgumentInfo[args.Length + 1];
Expression[] parameters = new Expression[args.Length + 1];
var thisParameterFlags = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null);
parameterFlags[0] = thisParameterFlags;
parameters[0] = Expression.Constant(thisParameter);
for (int i = 0; i < args.Length; i++) {
parameterFlags[i + 1] = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null);
parameters[i + 1] = Expression.Constant(args[i]);
}
@jflam
jflam / invoke_dynamic.cs
Created January 13, 2011 08:21
Dynamic invocation with C# binder and the ET compiler
using System;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using Microsoft.CSharp.RuntimeBinder;
namespace ConsoleApplication1 {
class MyTarget {
public int Foo() { return 1; }
public int Foo(int x) { return x; }
public int Foo(int x, string y) { return x; }
using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Media;
using System.Xml.Linq;
using Microsoft.Maps.MapControl;
namespace Map
{
public partial class MainPage : UserControl