Skip to content

Instantly share code, notes, and snippets.

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
[ 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>),
}
@samrat
samrat / gist:84fdb2ffb683a9d0bc50b1b41ab265c6
Last active March 5, 2019 03:34 — forked from jdh30/gist:bc1794232ac584db9baa
List-based n-queens solver with mark-sweep GC written in C++
#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 October 12, 2018 10:18
Using hledger with an Enchive encrypted file
#!/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})