Skip to content

Instantly share code, notes, and snippets.

View hidaris's full-sized avatar
🍊

John Smith hidaris

🍊
View GitHub Profile
@jvelezmagic
jvelezmagic / main.py
Created May 17, 2023 12:05
Langchain FastAPI stream with simple memory
# The goal of this file is to provide a FastAPI application for handling
# chat requests amd generation AI-powered responses using conversation chains.
# The application uses the LangChaing library, which includes a chatOpenAI model
# for natural language processing.
# The `StreamingConversationChain` class is responsible for creating and storing
# conversation memories and generating responses. It utilizes the `ChatOpenAI` model
# and a callback handler to stream responses as they're generated.
# The application defines a `ChatRequest` model for handling chat requests,
@wilbowma
wilbowma / anf-eg.rkt
Last active September 7, 2021 14:27
#lang racket
;; Adapted from Figure 9 of Flanagan et al.
(define (normalize-term M)
(normalize M (lambda (x) x)))
(define (normalize M k)
(match M
[`(lambda ,args ,body)
(k `(lambda ,args ,(normalize-term body)))]
#lang racket
(require cpsc411/compiler-lib)
(module+ a
;; Compiler style
(define (expand e)
(define (expand-expr e)
(match e
[`(and ,e1 ,e2)
#lang racket/base
; Lock-free FIFO queues, loosely based on “Simple, Fast, and Practical
; Non-Blocking and Blocking Concurrent Queue Algorithms”.
(require racket/contract
racket/future
(only-in racket/unsafe/ops unsafe-struct*-cas!))
(provide queue?
@alex-hhh
alex-hhh / tetris-5.rkt
Created March 28, 2020 02:33
Full program for the "A Game of Tetris" blog posts.
;; A tetris game -- partial implementation, part 5
;; Copyright (c) 2020 Alex Harsányi (AlexHarsanyi@gmail.com)
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the "Software"),
;; to deal in the Software without restriction, including without limitation
;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;; and/or sell copies of the Software, and to permit persons to whom the
;; Software is furnished to do so, subject to the following conditions:
#lang rosette/safe
(require rosette/lib/angelic
rosette/lib/match)
(current-bitwidth #f)
(require (only-in racket list*))
; bit operations
(define (rotate-right i x)
@philnguyen
philnguyen / redex-micro-kanren.rkt
Created November 4, 2019 03:45
Redex model of "machine" semantics for micro-kanren. May not be faithful.
#lang racket/base
(require redex)
(define-language μ-Kanren
;; Syntax
[#|Term |# t ::= x () number (t t)]
[#|Goal |# g ::= (g ∨ g) (g ∧ g) (∃ (x ...) g) (↓ f t ...) (t ≡ t)]
[#|Goal Abs|# f ::= (side-condition (name f any) (procedure? (term f)))]
[#|Variable|# x ::= variable-not-otherwise-mentioned]
@orehush
orehush / serializers.py
Last active December 18, 2023 14:23
DRF simple JWT logout flow
from django.utils.text import gettext_lazy as _
from rest_framework import serializers
from rest_framework_simplejwt.tokens import RefreshToken, TokenError
class RefreshTokenSerializer(serializers.Serializer):
refresh = serializers.CharField()
default_error_messages = {
'bad_token': _('Token is invalid or expired')
}
#lang s-exp "typecheck-lang.rkt"
(define [! : (-> Integer Integer)]
(lambda ([x : Integer]) (if (= x 0) 1 (* x (! (- x 1))))))
(! 6)
(provide !)
@rntz
rntz / MinimalNBE.hs
Last active November 21, 2023 15:17
Normalisation by evaluation for the simply-typed lambda calculus, in Agda
-- A simply-typed lambda calculus, and a definition of normalisation by
-- evaluation for it.
--
-- The NBE implementation is based on a presentation by Sam Lindley from 2016:
-- http://homepages.inf.ed.ac.uk/slindley/nbe/nbe-cambridge2016.pdf
--
-- Adapted to handle terms with explicitly typed contexts (Sam's slides only
-- consider open terms with the environments left implicit/untyped). This was a
-- pain in the ass to figure out.