Skip to content

Instantly share code, notes, and snippets.

View readme.md

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 Oct 11, 2021
Nix config for Bayes Rules
View shell.nix
{ 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 Jan 27, 2021
nix env to build zig(shared by andrewrk)
View zig-build.nix
with import <nixpkgs> {}; {
tmpAoeu = stdenv.mkDerivation {
name = "tmpAoeu";
hardeningDisable = [ "all" ];
buildInputs = [
cmake
llvmPackages_11.clang-unwrapped
llvm_11
lld_11
libffi
View gist:9c7aaa5c92e0ba5ad2ea03027d84276c
[ 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
View mult_load.rs
use std::collections::HashMap;
struct Database {
objects: HashMap<String, Object>,
}
enum Object {
Tree,
Commit { tree_id: String },
}
View pager.c
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <errno.h>
#include <stdlib.h>
/* Usage:
$ clang -o pager main.c
$ ./pager 200
*/
View minimal_repo.rs
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 Jun 2, 2019
Minimal AST uniquify example
View uniq.rs
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>),
}
@samrat
samrat / gist:84fdb2ffb683a9d0bc50b1b41ab265c6
Last active Mar 5, 2019 — forked from jdh30/gist:bc1794232ac584db9baa
List-based n-queens solver with mark-sweep GC written in C++
View gist:84fdb2ffb683a9d0bc50b1b41ab265c6
#include <vector>
#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include "Allocator.h"
#include "MarkSweep.h"
#define OPTIMIZED
#define SHADOWSTACK
@samrat
samrat / hl.sh
Last active Oct 12, 2018
Using hledger with an Enchive encrypted file
View hl.sh
#!/bin/bash
JOURNAL_DIR=~/code/ledger
JOURNAL_PATH=${JOURNAL_DIR}/hledger.journal
ENC_JOURNAL_PATH=${JOURNAL_PATH}.enchive
echo "Decrypting journal file..."
enchive extract $ENC_JOURNAL_PATH
digest_before=$(md5 ${JOURNAL_PATH})