Skip to content

Instantly share code, notes, and snippets.

@samrat
samrat / sdl2_stbtt.c
Last active September 4, 2023 12:30
Drawing text into a bitmap w/ stb_truetype
#include "SDL.h"
/*
Compilation:
============
gcc -g --std=c99 -o sdl2_stbtt sdl2_stbtt.c `sdl2-config --cflags --libs` -lm
Usage:
======
./sdl2_stbtt /usr/share/fonts/TTF/LiberationMono-Regular.ttf

The Debug WASM build overwrites prog with 0. This seems to be related with creating an instance of the foo struct as this behaviour does not occur when I comment out the var foo = ... line.

$ zig build-lib test2.zig -target wasm32-freestanding -dynamic
$ node test2.js

The result is 12
The result is 49
The result is 0
@samrat
samrat / shell.nix
Created October 11, 2021 22:04
Nix config for Bayes Rules
{ pkgs ? import <nixpkgs> { } }:
let
my-r-pkgs = pkgs.rstudioWrapper.override {
packages = with pkgs.rPackages; [
ggplot2
tidyverse
tidybayes
rstan
bayesrules
@samrat
samrat / zig-build.nix
Created January 27, 2021 14:08
nix env to build zig(shared by andrewrk)
with import <nixpkgs> {}; {
tmpAoeu = stdenv.mkDerivation {
name = "tmpAoeu";
hardeningDisable = [ "all" ];
buildInputs = [
cmake
llvmPackages_11.clang-unwrapped
llvm_11
lld_11
libffi
@samrat
samrat / running_pd.org
Created March 22, 2016 08:23
Running a local copy of Velleman's ProofDesigner

Running a local copy of ProofDesigner

  1. Download the jar wget http://www.cs.amherst.edu/~djv/pd/ProofDesigner.jar
  2. Create html file with contents:
<HTML>
<HEAD>
<TITLE>Proof Designer</TITLE>
<SCRIPT language="JavaScript">
function showHTML() {
[ 99%] Linking CXX executable zig0
/usr/bin/ld: zig_cpp/libzig_cpp.a(zig_clang_driver.cpp.o): in function `CreateAndPopulateDiagOpts(llvm::ArrayRef<char const*>, bool&)':
/home/samrat/code/zig/src/zig_clang_driver.cpp:275: undefined reference to `clang::driver::getDriverOptTable()'
/usr/bin/ld: /home/samrat/code/zig/src/zig_clang_driver.cpp:280: undefined reference to `clang::ParseDiagnosticArgs(clang::DiagnosticOptions&, llvm::opt::ArgList&, clang::DiagnosticsEngine*, bool, bool)'
/usr/bin/ld: zig_cpp/libzig_cpp.a(zig_clang_driver.cpp.o): in function `ZigClang_main':
/home/samrat/code/zig/src/zig_clang_driver.cpp:338: undefined reference to `clang::noteBottomOfStack()'
/usr/bin/ld: /home/samrat/code/zig/src/zig_clang_driver.cpp:347: undefined reference to `clang::driver::ToolChain::getTargetAndModeFromProgramName(llvm::StringRef)'
/usr/bin/ld: /home/samrat/code/zig/src/zig_clang_driver.cpp:458: undefined reference to `clang::TextDiagnosticPrinter::TextDiagnosticPrinter(llvm::raw_ostream&, clang::DiagnosticOp
use std::collections::HashMap;
struct Database {
objects: HashMap<String, Object>,
}
enum Object {
Tree,
Commit { tree_id: String },
}
@samrat
samrat / pager.c
Last active October 29, 2019 10:29
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <errno.h>
#include <stdlib.h>
/* Usage:
$ clang -o pager main.c
$ ./pager 200
*/
use std::path::{Path, PathBuf};
// The proper modeling of the domain would be for a Repository to own
// Status. But because some Status methods call Repository methods, I
// have had to make Repository a field in Status instead.(which I've
// marked HACKY in the code below)
// This means that the struct that owns Repository now owns a Status
// and methods in the parent struct call Repository methods look like
// `self.status.repo.some_repository_method()`
@samrat
samrat / uniq.rs
Created June 2, 2019 08:11
Minimal AST uniquify example
use std::collections::HashMap;
use std::rc::Rc;
#[derive(Debug)]
enum AST {
Symbol(Rc<String>),
Int(i32),
Let(Vec<(Rc<String>, Box<AST>)>, Box<AST>),
}