Skip to content

Instantly share code, notes, and snippets.

View breandan's full-sized avatar
📖
I may be slow to respond.

breandan breandan

📖
I may be slow to respond.
View GitHub Profile
@knewjade
knewjade / HATETRIS_289lines.md
Last active May 8, 2024 00:47
Reached 289 lines in HATETRIS using Neural Networks

HATETRISで289 linesに到達するまでの記録

こんにちは、knewjadeです。 今回、HATETIRSで289 linesまで到達することができました。動画はこちら(2022-11-26時点のWorld Recordでした。現在では更新されています。 → David&Felipeの記事

ここでは、その結果を得るためのアプローチを説明していきたいと思います。

「そもそもHATETRISとは?」という方は、こちらをご参照ください。

はじめに: この文章について

@ttesmer
ttesmer / AD.hs
Last active July 22, 2024 05:21
Automatic Differentiation in 38 lines of Haskell using Operator Overloading and Dual Numbers. Inspired by conal.net/papers/beautiful-differentiation
{-# LANGUAGE TypeSynonymInstances #-}
data Dual d = D Float d deriving Show
type Float' = Float
diff :: (Dual Float' -> Dual Float') -> Float -> Float'
diff f x = y'
where D y y' = f (D x 1)
class VectorSpace v where
zero :: v
@moyix
moyix / CodeGen_GPTJ_Conversion.md
Last active January 5, 2024 12:50
How to convert the SalesForce CodeGen models to GPT-J

Using Linear Algebra to Convert a Large Code Model

Background

The SalesForce CodeGen models are a family of large language models trained on a large amount of natural language data and then fine-tuned on specialized datasets of code. Models of size 350M, 2B, 6B, and 16B parameters are provided in three flavors:

  • nl, the base model trained on The Pile, a large natural language dataset compiled by EleutherAI
  • multi, which is fine-tuned from the nl model on a dataset of code in multiple languages, scraped from GitHub, and
  • mono, which is fine-tuned from the multi model on Python code only.

I did a bunch of work months ago on the polynomial and rational function namespaces; now they can both participate in all of the generic functions, including derivatives and all arithmetic.

I realized today that I could use an ACTUAL polynomial instance in that wacky "find-path" example from pages 22-23 of SICM. Everything is way faster and makes more sense, since find-path returns an actual polynomial.

This function generates a polynomial by passing the (identity) polynomial into the Lagrange interpolation code:

@mapio
mapio / z3.ipynb
Created December 27, 2021 21:19
Solving Alphametics with z3
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Motivation

Swift’s type system supports a number of different ways of taking a function or type and abstracting it. Usually, this is done by adding a generic parameter and an associated set of constraints. Similarly, a function that takes a particular type of argument can be abstracted to any number of those arguments by making it variadic with triple-dot (...) syntax. Today, both of these features are permitted separately: you can define a generic function that takes a variable number of arguments, such as

func debugPrint<T>(_ items: T...) 
  where T: CustomDebugStringConvertible
{   
  for (item: T) in items {
    stdout.write(item.debugDescription)
#https://twitter.com/officialmcafee/status/1397568860082122752
#https://twitter.com/ahakcil/status/1397888724936105987
import random
import copy
RST = '\033[0m'
def rand_data(size):
d = []

Program Analysis, a Big Happy Family

The idea behind program analysis is simple, right? You just want to know stuff about your program before it runs, usually because you don't want unexpected problems to arise (those are better in movies.) Then why looking at Wikipedia gives you headaches? Just so many approaches, tools, languages 🤯

In this article I would like to give a glimpse of an overarching approach to program analysis, based on ideas from abstract interpretation. My goal is not to pinpoint a specific technique, but rather show how they have common core concepts, the differences being due mostly to algorithmic challenges. In other words, static analysis have a shared goal, but it's a challenge to make them precise and performant.

Code is meant to be executed by a computer. Take the following very simple function:

fun cantulupe(x) = {
@norswap
norswap / Combinators.java
Last active January 19, 2023 09:12
Handwritten JSON Parser with Parser Combinators
// Code for lecture [7. Parsing Combinators]
// https://www.youtube.com/watch?v=3Cfq4i6754s&list=PLOech0kWpH8-njQpmSNGSiQBPUvl8v3IM&index=7
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.Scanner;
import java.util.function.Supplier;
@senderle
senderle / hand-modify-pdf.md
Created September 23, 2020 15:03
So you want to modify the text of a PDF by hand

So you want to modify the text of a PDF by hand...

If you, like me, resent every dollar spent on commercial PDF tools, you might want to know how to change the text content of a PDF without having to pay for Adobe Acrobat or another PDF tool. I didn't see an obvious open-source tool that lets you dig into PDF internals, but I did discover a few useful facts about how PDFs are structured that I think may prove useful to others (or myself) in the future. They are recorded here. They are surely not universally applicable --
the PDF standard is truly Byzantine -- but they worked for my case.