Skip to content

Instantly share code, notes, and snippets.

View yuhangwang's full-sized avatar

StevenW yuhangwang

View GitHub Profile
@madagra
madagra / torch_func_opt_example.py
Created May 7, 2023 14:14
Fitting a function with functional PyTorch
import numpy as np
import torch
from torch import nn
from torch import Tensor
from torch.func import functional_call
import torchopt
import matplotlib.pyplot as plt
class SimpleNN(nn.Module):
@alahijani
alahijani / Euclid.idr
Last active March 31, 2021 12:55
Proof of Euclid's Lemma in Idris - Number Theory Algorithms
module Euclid
import Syntax.PreorderReasoning
%default total
Divides : (divisor, dividend : Nat) -> Type
Divides d n = (q : Nat ** (n = q * d))
data Direction = LTR | RTL
@xkortex
xkortex / entry.sh
Last active April 6, 2025 12:49
dockerfile entrypoint for activating conda environment
#!/bin/bash
## Entrypoint for docker RUN directives as well as ENTRYPOINT with conda env
## Enable by adding:
## COPY entry.sh ./
## SHELL ["/entry.sh", "/bin/bash", "-c"]
##
## Optionally, set the following env to select a conda env to run in
## ENV CONDA_DEFAULT_ENV=foo
## You may also want to add something like
## RUN conda init bash && echo 'conda activate "${CONDA_TARGET_ENV:-base}"' >> ~/.bashrc
@unclechu
unclechu / algebraic_data_types_experiment.nim
Last active March 14, 2025 17:10
Nim: algebraic data types (Maybe and Either), kinda Eq typeclass instances, kinda functors
type
MaybeKind = enum Just, Nothing
Maybe[T] = object
case kind: MaybeKind
of Just: value: T
of Nothing: discard
EitherKind = enum Left, Right
Either[L, R] = object
case kind: EitherKind
@spacejam
spacejam / rr-with-rust.md
Last active August 11, 2025 18:21
using rr with rust

using rust with rr

rr is a great debugging tool. it records a trace of a program's execution, as well as the results of any syscalls it executes, so that you can "rewind" while you debug, and get deterministic forward and reverse instrumented playback. it works with rust, but by default if you try it out, it could be pretty ugly when you inspect variables. if this bothers you, configure gdb to use a rust pretty-printer

rr is probably in your system's package manager.

usage

@zaiste
zaiste / rst_to_md.sh
Created February 5, 2017 18:54
Convert RST to Markdown using Pandoc
FILES=*.rst
for f in $FILES
do
filename="${f%.*}"
echo "Converting $f to $filename.md"
`pandoc $f -f rst -t markdown -o $filename.md`
done
@tdudgeon
tdudgeon / conf_gen.py
Created April 22, 2016 09:42
Conformer generation using RDKit
import sys
from rdkit import Chem
from rdkit.Chem import AllChem, TorsionFingerprints
from rdkit.ML.Cluster import Butina
def gen_conformers(mol, numConfs=100, maxAttempts=1000, pruneRmsThresh=0.1, useExpTorsionAnglePrefs=True, useBasicKnowledge=True, enforceChirality=True):
ids = AllChem.EmbedMultipleConfs(mol, numConfs=numConfs, maxAttempts=maxAttempts, pruneRmsThresh=pruneRmsThresh, useExpTorsionAnglePrefs=useExpTorsionAnglePrefs, useBasicKnowledge=useBasicKnowledge, enforceChirality=enforceChirality, numThreads=0)
return list(ids)
@DavidEGrayson
DavidEGrayson / README.md
Last active November 28, 2024 18:11
Getting started with midipix
@CMCDragonkai
CMCDragonkai / projection.hs
Last active December 10, 2016 20:30
Haskell: Tensor Dimensional Projection (like Numpy's Tuple Selection Objects)
-- with regards to: http://stackoverflow.com/questions/32630035/replicating-numpys-advanced-indexing-slicing-in-haskell
-- let's create some tensors:
-- 5 rows, 4 columns
two_d_matrix =
[
[
0
| _ <- [0..3]]
@ohanhi
ohanhi / frp.md
Last active September 23, 2025 16:12
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Editorial note