Skip to content

Instantly share code, notes, and snippets.

View shritesh's full-sized avatar

Shritesh Bhattarai shritesh

View GitHub Profile
@shritesh
shritesh / nub.ex
Created October 27, 2021 00:08
NashFP nub
defmodule Nubnub do
@moduledoc """
Documentation for `Nubnub`.
"""
@doc """
## Examples
iex> Nubnub.nub([1, 2, 3, 1, 2, 3])
[1, 2, 3]
defmodule End do
defmodule Region do
defstruct name: "", population: 0, south_edge: 0
end
defp tally(lines, regions) do
Enum.reduce(lines, regions, fn line, regions ->
fields = String.split(line, "\t")
{latitude, _} = Enum.at(fields, 4) |> Float.parse()
{population, _} = Enum.at(fields, 14) |> Integer.parse()
@shritesh
shritesh / reason_p5_stopwatch.re
Last active March 19, 2020 16:13
ReasonML p5.js Stopwatch
type p5;
type sketch;
type button;
type state =
| Initializing
| NotStarted(button)
| Running(button, int)
@shritesh
shritesh / alpine_stopwatch.html
Last active November 15, 2023 03:06
Alpine.js Stopwatch
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Alpine Stopwatch</title>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js" defer></script>
</head>
<body>
@shritesh
shritesh / left_pad.js
Last active April 18, 2019 02:43
LeftPad in JS With Zig and WASM
const fs = require('fs');
const source = fs.readFileSync("./left_pad.wasm");
const sourceArray = new Uint8Array(source);
WebAssembly.instantiate(sourceArray, {}).then(result => {
const leftPad = left_pad.bind(result.instance.exports);
const paddedStr = leftPad("hello zig", 20, '*');
console.log(paddedStr);
});
@shritesh
shritesh / hostcalls.zig
Last active April 15, 2019 21:32
Fastly Zig Wasm
const std = @import("std");
const fmt = std.fmt;
extern fn hostcall_kvstore_upsert(
key_ptr: [*]const u8,
key_len: usize,
value_ptr: [*]const u8,
value_len: usize,
) bool;