Skip to content

Instantly share code, notes, and snippets.

View structural.ex
defmodule Structural do
@moduledoc """
This module is build around this invariance, which I call
"reconstruction property":
for all m_1, m_2: maps, let m_common = intersect(m_1, m_2),
then merge(m_common, diff(m_1, m_common)) == m_1,
and merge(m_common, diff(m_2, m_common)) == m_2.
This allows us to efficiently store a list of [m_1, m_2, ..., m_K]
View iex.exs
try do
Mix.Project.get()
catch
:exit, _ ->
Mix.install([
{:nanoid, "~> 2.0.5"},
{:jason, "~> 1.3.0"},
{:timex, ">= 0.0.0"}
])
end
@shouya
shouya / README.md
Last active March 16, 2023 05:17
Simple ChatGPT used in a Unix pipe
View README.md

To use this script, you need to install the openai package using pip. You also need to set the OPENAI_API_KEY environment variable to your OpenAI API key.

For example, to ask a natural language question, you can pipe the output of ls -al to the script like this:

ls -al | ./gpt "What are the permissions of the files?"

The script will use the OpenAI GPT-3 model to generate a response to your question with a temperature of 0.2. The response will be printed to the console.


@shouya
shouya / structural.ex
Last active May 13, 2022 01:56
Deep diff/intersect/merge
View structural.ex
defmodule Manager.Util.Structural do
@moduledoc """
This module is build around this invariance, which I call
"reconstruction property":
for all m_1, m_2: maps, let m_common = intersect(m_1, m_2),
then merge(m_common, diff(m_1, m_common)) == m_1,
and merge(m_common, diff(m_2, m_common)) == m_2.
This allows us to efficiently store a list of [m_1, m_2, ..., m_K]
@shouya
shouya / gol.org
Last active March 27, 2023 15:30
View gol.org

Monad

class Functor m => Monad m where
  pure :: a -> m a
  join :: m (m a) -> m a
  -- or
  bind :: (a -> m b) -> m a -> m b
@shouya
shouya / coroutine.rkt
Last active July 13, 2021 15:34
A toy coroutine implementation (implemented premitives: spawn, join, yield, sleep, select)
View coroutine.rkt
#lang racket
;;; global states
(define task-queue '())
(define joiners '())
(define curr-task-handle 'main)
(define halt (lambda () (display "not started yet")))
;;; queue-related functions
View netcalc.hs
import qualified Data.Text as T
import Control.Monad
import Data.List (unfoldr, intercalate)
import Data.Bits (testBit)
import Data.Function ((&))
data Node = Sat -- all 1
| Unsat -- all 0
| Mixed Node Node -- mixed (left, right)
deriving (Show)
@shouya
shouya / kubectl-exp
Last active June 3, 2021 08:54
Kubectl explain with syntax highlighting and cache
View kubectl-exp
#!/bin/bash
KUBE_EXPLAIN_CACHE_DIR=$HOME/.kube/cache/explain
p="$1"
f="$KUBE_EXPLAIN_CACHE_DIR/$p"
if [[ -z "$p" ]]; then
echo "Usage: $0 <path>"
echo "Example: $0 deploy.spec.template.spec.volumes"
View gpt3-lojban.txt
------------ (
I will show you how to translate lojban into English.
Lojban: coi rodo
English: Hi, everyone.
Lojban: mi citka lo plise
English: I eat the apple.
Lojban: lo plise cu se cikta mi
@shouya
shouya / lo-balmle-tamca.md
Last active September 7, 2020 18:44
loi selsa'a bau lo jbobau
View lo-balmle-tamca.md

ni'o loi balmle tamca

i lo xadni poi tolpinta je melbi

gi'e lo se dasni poi xunre

gi'e lo panci poi slari je titla

cu se ckaji loi balmle tamca i loi tamca