Skip to content

Instantly share code, notes, and snippets.

View vedantroy's full-sized avatar

Vedant Roy vedantroy

View GitHub Profile
@vedantroy
vedantroy / lib.rs
Created May 13, 2021 16:13
Track memory usage
//#![feature(set_stdio)]
#![feature(integer_atomics, const_fn)]
mod types;
use std::{
collections::{HashMap, HashSet},
convert::TryFrom,
fmt::Display,
};
#! /usr/bin/env python3
class Atom:
def __init__(self, typ, val):
self.typ = typ
self.val = val
def __repr__(self):
r = None
if self.typ == "string":
@vedantroy
vedantroy / test.rs
Created May 31, 2021 06:33
Macro Shenanigans
macro_rules! expected_variants_join {
($x:ident) => (stringify!($x));
($x:ident, $($y:ident),*) => { concat!(stringify!($x), " ", expected_variants!($($y),*)) };
}
macro_rules! expected_variants {
($x:ident) => { concat!("Expected: ", stringify!($x)) };
($x:ident, $($y:ident),*) => { concat!("Expected one of: ", stringify!($x), " ", expected_variants_join!($($y),*)) };
}

Keybase proof

I hereby claim:

  • I am vedantroy on github.
  • I am vedantroy (https://keybase.io/vedantroy) on keybase.
  • I have a public key ASBIUZWNIPfv0WtR_xCx00YJCZtENcK2nQT4uad5Trg9Awo

To claim this, I am signing this object:

@vedantroy
vedantroy / time_tracker.py
Created June 12, 2021 23:47
Time tracker for i3blocks
#! /usr/bin/env python3
import os
import sys
import time
import datetime
import json
from enum import Enum
@vedantroy
vedantroy / tests.js
Created June 18, 2021 20:52
test old rust / new JS compatability
const execSync = require("child_process").execSync;
const fs = require("fs")
const crypto = require("crypto")
const assert = require("assert")
function assertNewJsEqOldRust(doc) {
const bytes = Buffer.from(Automerge.save(doc)).toString("base64")
const tempFileName = `changes-${crypto.randomBytes(4).readUInt32LE(0)}.json`
const outFile = `/tmp/${tempFileName}`
//console.log(`Writing to: ${outFile}`)
@vedantroy
vedantroy / gist:b6737de470bfac12986b977ee9624993
Created November 20, 2021 22:14
Exercise_Visualization_Backup.html
<html>
<head>
<meta charset="UTF-8" />
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body {
width: 100%;
height: 100%;
}
@vedantroy
vedantroy / lib.rs
Last active November 28, 2021 17:47
Creating singleton / global state for Solana program
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod auction {
use super::*;
pub fn create_game_state(ctx: Context<CreateGameState>) -> ProgramResult {
Ok(())
}
@vedantroy
vedantroy / run_sage.py
Created January 26, 2022 19:38
Run a Python file in Sage using Docker
#! /usr/bin/python3
import sys
import os.path
fpath = sys.argv[1]
assert os.path.isfile(fpath)
abs_path = os.path.abspath(fpath)
dirname = os.path.dirname(abs_path)
fname = os.path.basename(abs_path)
@vedantroy
vedantroy / tailwind-styled.ts
Created June 10, 2022 18:00
Tailwind Styled Components-like API
import React from "react";
import { fromPairs } from "lodash-es";
import clsx from "clsx";
// This is my styled-components replacement
// Taken from:
// https://github.com/MathiasGilson/Tailwind-Styled-Component/blob/master/src/domElements.ts
const elementsArray: (keyof JSX.IntrinsicElements)[] = [
"a",
"abbr",