Skip to content

Instantly share code, notes, and snippets.

View shouya's full-sized avatar

shouya

View GitHub Profile
@shouya
shouya / ternary.rs
Last active February 29, 2024 07:24
// playground for ternary arithmetic
// {-1, 0, 1} are represented by {0b10, 0b00, 0b01} respectively
// 0b11 is unused.
use prettytable::table;
use rand::seq::SliceRandom;
fn main() {
test_add_1();
test_add_32(1000);
use std::{fs::File, io::Read, path::Path};
use pathfinding::prelude::dijkstra;
const PART1_MAX_STRAIGHT: usize = 3;
const PART2_MIN_STRAIGHT: usize = 4;
const PART2_MAX_STRAIGHT: usize = 10;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum Dir {
@shouya
shouya / gol.org
Last active March 27, 2023 15:30

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
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]
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

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.


Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shouya
shouya / structural.ex
Last active May 13, 2022 01:56
Deep diff/intersect/merge
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 / commands.sh
Created July 25, 2014 12:17
gfw dns solution
#!/bin/sh
# this script is only written for gentoo
# if you're using other distro, modify part of it as needed
#
# please run this script run once, as su
sh dns.sh
iptables-save > /etc/iptables-local
cat > /etc/local.d/iptables-restore <<<EOF
#!/bin/sh
@shouya
shouya / coroutine.rkt
Last active July 13, 2021 15:34
A toy coroutine implementation (implemented premitives: spawn, join, yield, sleep, select)
#lang racket
;;; global states
(define task-queue '())
(define joiners '())
(define curr-task-handle 'main)
(define halt (lambda () (display "not started yet")))
;;; queue-related functions