Skip to content

Instantly share code, notes, and snippets.

View cyyeh's full-sized avatar
🎯
Focusing

Chih-Yu Yeh cyyeh

🎯
Focusing
View GitHub Profile
@cyyeh
cyyeh / test_ollama.py
Created May 21, 2024 00:03
Test Ollama using OpenAI compatible API
from openai import OpenAI
client = OpenAI(
api_key='ollama',
base_url="http://localhost:11434/v1",
)
# this will fail, showing openai.NotFoundError: 404 page not found
data = client.embeddings.create(
input='hi',
@cyyeh
cyyeh / all.sql
Last active November 3, 2023 03:15
長庚poc
{% if context.params.rectype != 'PETscan' and
context.params.rectype != 'PETreport' and
context.params.rectype != 'PETprepare' and
context.params.rectype != 'PETinj' %}
{% error "rectype should be PETscan, PETreport, PETprepare or PETinj" %}
{% endif %}
{% set body = {"body": {"chtno": context.params.chtno, "deptNo": context.params.deptno, "recType": context.params.rectype}} %}
select
@cyyeh
cyyeh / README.md
Last active March 14, 2023 10:21
geospatial data analysis
@cyyeh
cyyeh / bugs_and_fixes.md
Last active March 20, 2024 17:46
97 things every programmer should know

Bugs and Fixes

Check Your Code First Before Looking to Blame Others, Allan Kelly

  • Assuming that the tools are widely used, mature, and employed in various technology stacks, there is little reason to doubt the quality. Of course, if the tool is an early release, or used by only a few people worldwide, or a piece of seldom downloaded, version 0.1, open source software, there may be good reason to suspect the software. (Equally, an alpha version of commercial software might be suspect.)
  • All the usual debugging advice applies, so isolate the problem, stub out calls, and surround it with tests; check calling conventions, shared libraries, and version numbers; explain it to someone else; look out for stack corrup- tion and variable type mismatches; and try the code on different machines and different build configurations, such as debug and release.
  • Question your own assumptions and the assumptions of others.
  • Multithreaded problems are another source of bugs that turn hair gray and induce screaming
@cyyeh
cyyeh / bad_smells_in_code.md
Last active May 26, 2022 12:11
bad smells in code
@cyyeh
cyyeh / design-twitter.py
Created May 23, 2020 11:00
Design Twitter
class Twitter:
def __init__(self):
"""
Initialize your data structure here.
"""
self.tweets = []
self.following_dict = {}
self.followed_dict = {}
@cyyeh
cyyeh / monte_carlo_101.py
Created December 14, 2019 13:22
monte carlo 101
import numpy as np
from matplotlib import pyplot as plt
# helper function to check if (x, y) is in red section
# x and y may be a single point or a numpy array
def is_in_quarter_section(x, y):
return x*x + y*y <= 1
def approximate_pi(sample_size=10000):
# initialization
@cyyeh
cyyeh / leet_code_sharing.md
Last active March 21, 2019 06:49
Leet Code Discussion

Leet Code Sharing

Stack

Easy

  • 682. Baseball Game
    • 葉致煜
      • Runtime: 40 ms, faster than 52.00% of Python3 online submissions for Baseball Game
  • Memory Usage: 12.9 MB, less than 5.15% of Python3 online submissions for Baseball Game.
@cyyeh
cyyeh / swift-protocols.swift
Created February 28, 2019 07:00
Swift Protocols
/*
Referenced from Stanford CS193p
#: important
##: very important
##Protocols
- Protocol Syntax
- Property Requirements
- Method Requirements