Skip to content

Instantly share code, notes, and snippets.

View vinhnx's full-sized avatar
🎯
focusing

Vinh Nguyen vinhnx

🎯
focusing
View GitHub Profile
@ole
ole / swift-has-feature.sh
Last active April 15, 2024 12:02
List Swift compiler upcoming and experimental feature flags. (Note: the second script below, swift-list-features.sh, is probably the more useful one of the two. Unfortunately, I can't reorder them.)
#!/bin/zsh
# Test if the Swift compiler knows about a particular language feature.
#
# Usage:
#
# swift-has-feature [--swift SWIFT_PATH] FEATURE
#
# The exit code signals success (= the compiler knows this feature) or failure.
#
@jrknox1977
jrknox1977 / ollama_dspy.py
Created February 9, 2024 18:06
ollama+DSPy using OpenAI APIs.
# install DSPy: pip install dspy
import dspy
# Ollam is now compatible with OpenAI APIs
#
# To get this to work you must include `model_type='chat'` in the `dspy.OpenAI` call.
# If you do not include this you will get an error.
#
# I have also found that `stop='\n\n'` is required to get the model to stop generating text after the ansewr is complete.
# At least with mistral.
@jrknox1977
jrknox1977 / dspy_tgi_mistral.py
Last active April 14, 2024 08:42
DSPy - using TGI for local model
# install DSPy: pip install dspy
import dspy
# This sets up the language model for DSPy in this case we are using mistral 7b through TGI (Text Generation Interface from HuggingFace)
mistral = dspy.HFClientTGI(model='mistralai/Mistral-7B-v0.1', port=8080, url='http://localhost')
# This sets the language model for DSPy.
dspy.settings.configure(lm=mistral)
# This is not required but it helps to understand what is happening
@jrknox1977
jrknox1977 / dspy_chain_of_thought_example.py
Created February 5, 2024 18:56
DSPy example with chain of thought.
# install DSPy: pip install dspy
import dspy
# This sets up the language model for DSPy in this case we are using GPT-3.5-turbo
turbo = dspy.OpenAI(model='gpt-3.5-turbo')
# This sets the language model for DSPy. This must be set or you get an error that is not helpful:
# --> temperature = lm.kwargs['temperature'] if temperature is None else temperature
# --> AttributeError: 'NoneType' object has no attribute 'kwargs'
@jrknox1977
jrknox1977 / basic_qa.py
Last active April 14, 2024 08:43
Simple DSPY example of BasicQA
# install DSPy: pip install dspy
import dspy
# This sets up the language model for DSPy in this case we are using GPT-3.5-turbo
turbo = dspy.OpenAI(model='gpt-3.5-turbo')
# This sets the language model for DSPy. This must be set or you get an error that is not helpful:
# --> temperature = lm.kwargs['temperature'] if temperature is None else temperature
# --> AttributeError: 'NoneType' object has no attribute 'kwargs'
@MarcoEidinger
MarcoEidinger / findRequiredReasonAPIUsage.sh
Created August 21, 2023 19:55
A shell script to find if any "required reason API" are used in Swift or Objective-C files within that folder or subfolders
#!/bin/bash
# https://developer.apple.com/documentation/bundleresources/privacy_manifest_files/describing_use_of_required_reason_api
searchTerms=(
# File timestamp APIs
"creationDate"
"modificationDate"
"fileModificationDate"
"contentModificationDateKey"
"creationDateKey"
@brettohland
brettohland / 1.0 FormatStyle in Excruciating Detail.md
Last active April 9, 2024 14:22
FormatStyle in Excruciating Detail
@atierian
atierian / README.md
Last active August 21, 2023 11:53
Allow consumers of SwiftUI UIViewRepresentable conforming Views to inject wrapped UIView delegate implementations through ViewModifiers using a ProxyDelegate.

Allow the consumer of a SwiftUI UIViewRepresentable View to inject delegate implementations for the wrapped UIView through View Modifiers by using a proxy delegate.

This can be a helpful pattern when providing a SwiftUI wrapper for a very heavy and complex UIView, where the wrapper implements many of the delegate methods of the wrapped UIView. But you want someone consuming the wrapper to have the ability to inject their own delegate method implementations to override yours, or to leverage some of the methods your not implementing.

@atierian
atierian / MyCell.swift
Created October 28, 2021 14:43
Oversimplified Example of MVVM
class MyCell: UITableViewCell {
let titleLabel = UILabel()
let subtitleLabel = UILabel()
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
required init?(coder: NSCoder) { nil }
@atierian
atierian / StateMachines.swift
Created August 31, 2021 14:14
Building State Machines in Swift
/*
Cory Benfield - Building State Machines in Swift
https://www.youtube.com/watch?v=7UC7OUdtY_Q
What is a Finite State Machine?
- Structured way to represent computation
- System can be in one of a finite number of states at any time
- Reacts to inputs by changing state, and optionally producing a side effect
- Deterministic and nondeterministic flavors
- Simple model of computation: easy to understand