Skip to content

Instantly share code, notes, and snippets.

View haf's full-sized avatar
💹
currently succeeding...

Henrik Feldt haf

💹
currently succeeding...
View GitHub Profile
@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.
@smurfix
smurfix / wrap.py
Last active February 14, 2024 18:15
Trio: results-gathering nursery wrapper
#!/usr/bin/python3
import trio
import outcome
from contextlib import asynccontextmanager
class StreamResultsNursery:
def __init__(self, max_buffer_size=1):
self.nursery = trio.open_nursery()
self.max_buffer_size = max_buffer_size
import asyncio
from contextvars import ContextVar
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import get_tracer, SpanKind
from opentelemetry.context import attach, detach
from opentelemetry.propagate import extract
@davidfowl
davidfowl / Program.cs
Last active December 26, 2021 00:27
A minimal fully asynchronous C# ASP.NET Core 3.0 application with routing (learn more about ASP.NET Core here https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-3.0)
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
public class Program
{
public static void Main(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
@masterdezign
masterdezign / convex-hull.hs
Last active January 21, 2022 00:28
Convex hull algorithm in Haskell
-- Worth reading http://www.geeksforgeeks.org/convex-hull-set-2-graham-scan/
import Text.Printf
import Data.List
type Point = (Double, Double)
-- Euclidean distance
dist :: (Double, Double) -> (Double, Double) -> Double
dist (x1, y1) (x2, y2) = sqrt (f x1 x2 + f y1 y2)
@isaksky
isaksky / gist:ceceeb64a5d7cf666c4a18991403f97a
Last active April 19, 2017 06:05
Things I'd like to see in a .NET (F#) web framework

Some things I'd like to see in a F# web framework, inspired from experience using Phoenix in Elixir.

  • Top knotch integrated i18n support, on par with gettext in Elixir.
    • Not sure if this is possible in F#, because of the lack of metaprogramming features. The Elixir solution is based on macros, so that one can extract .pot translation files at compile time.
  • Standard way to talk to databases suitable for most apps (Elixir example: Ecto)
  • Standard way to do database migrations suitable for most apps (Elixir example: Ecto)

This is more ecosystem related, but I'll include them anyway, because I think they are important to overall productivity:

  • Standardized, extensible project build/scripting tool already on my path. Examples:
@mrange
mrange / data_performance.md
Last active January 4, 2020 10:16
On the topic of data locality and performance

On the topic of data locality and performance

Full source code can be found here

It is well-known that a hard disk has a long delay from that we request the data to that we get the data. Usually we measure the hard disk latency in milliseconds which is an eternity for a CPU. The bandwidth of a hard disk is decent good as SSD:s today can reach 1 GiB/second.

What is less known is that RAM has the same characteristics, bad latency with good bandwidth.

You can measure RAM latency and badndwidth using Intel® Memory Latency Checker. On my machine the RAM latency under semi-high load is ~120 ns (The 3r:1w bandwidth is 16GiB/second). This means that the CPU on my machine has to wait for ~400 cycles for data, an eternity.

module RuleIt =
type Navigator = Navigator of (unit -> unit)
type UserIdentity = UserIdentity of uint64
type ResourceIdentity = ResourceIdentity of uint64
type UserAction =
| Create of ResourceIdentity
| Read of ResourceIdentity
| Update of ResourceIdentity
| Delete of ResourceIdentity
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@thinkbeforecoding
thinkbeforecoding / LogaryMetrics.fs
Created September 7, 2016 13:26
Sample to report timing metrics
open Hopac
open Hopac.Infixes
open NodaTime
open Logary
open Logary.Metrics.Reservoirs
open Logary.Configuration
open Logary.Targets
open Metric
module PointName =