Skip to content

Instantly share code, notes, and snippets.

from typing import Tuple
import mmap
import struct
import os
from pathlib import Path
import re
from collections import Counter, defaultdict
#include <iostream>
#include <cmath>
#include <vector>
#include <cassert>
#include <memory>
enum NodeOp {
OP_CONST,
OP_ADD,
OP_MUL,
@sir-wabbit
sir-wabbit / Reasoning Tools.clj
Last active October 15, 2024 22:57
Reasoning Tools
;; stage :: (name : String) -> (description : String) -> Stage
;; principle :: (name : String) -> (description : String) -> Principle
;; strategy :: (name : String) -> (description : String) -> (parent_principles: List String) -> Strategy
;; tactic :: (name : String) -> (description : String) -> (parent_strategies_and_principles: List String) -> Tactic
; The Principle-Strategy-Tactic axis represents a hierarchical framework for reasoning and problem-solving, moving from abstract, foundational beliefs to concrete, actionable steps.
; **Principles** are the most abstract level, representing foundational beliefs or philosophies that guide reasoning and decision-making across various contexts. They are timeless and universal, providing a conceptual framework from which strategies and tactics can be developed. Principles are not directly actionable but serve as the bedrock for strategic thinking and tactical execution.
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import matplotlib.pyplot as plt
##########################################################
# Generating training and validation data
import geocoder
import geopy.distance
import requests
import time
import json
def now():
from datetime import timezone
import datetime
dt = datetime.datetime.now(timezone.utc)
sealed class StableName[A] extends Serializable
object StableName {
private[this] final class RefInstance[A <: AnyRef](val value: A) extends StableName[A] {
override def clone(): AnyRef = this
override def equals(obj: Any): Boolean = obj match {
case that: RefInstance[_] => that.value eq this.value
case _ => false
}
#include <iostream>
#include <cmath>
#include <vector>
#include <cassert>
#include <memory>
enum NodeOp {
OP_CONST,
OP_ADD,
OP_MUL,
@numba.jit("i4(i4, i4)", nopython=True, nogil=True)
def gcd(a, b):
while True:
if a == 0: return b
if b == 0: return a
if a == b: return a
if b > a:
a, b = a, b % a
else:
a, b = a % b, b
sealed trait Free[+F[_], A]
object Free {
def eval[F[_], A](fa: Free[F, A])(implicit F: Monad[F]): F[A] = {
type State = (Free[F, Any], List[Any => Free[F, Any]])
def go(s: State): F[Either[State, Any]] = s match {
case (current, stack) =>
current match {
case Done(a) =>
stack match {
case Nil =>
///////////////////////////////////////////////////////////////////
// STEP 1 - Evaluation by need monad
///////////////////////////////////////////////////////////////////
import scala.annotation.unchecked.{ uncheckedVariance => uV }
final class Need[+A](private[this] var thunk: Need.Thunk[A @uV]) { A =>
import Need._
def value: A = thunk match {
case Done(x) => x