Skip to content

Instantly share code, notes, and snippets.

View jbhoot's full-sized avatar
💭
Reading: Lords of Uncreation by Adrian Tchaikovsky

Jayesh Bhoot jbhoot

💭
Reading: Lords of Uncreation by Adrian Tchaikovsky
View GitHub Profile
// Explanation:
// In decimal system: 142 = 100 + 40 + 2 = (1 * 10^2) + (4 * 10^1) + (2 * 10^0) = 142
// In binary system: 101 = (1 * 2^2) + (0 * 2^1) + (1 * 2^0) = 4 + 0 + 1 = 5
function binaryToDecimal(v) {
const first = v[0];
const exp = v.length - 1;
const val = parseInt(first) * (2 ** exp);
if (v.length === 0) {
return NaN;
//! A zig builder step that runs "libtool" against a list of libraries
//! in order to create a single combined static library.
const LibtoolStep = @This();
const std = @import("std");
const Step = std.build.Step;
const RunStep = std.build.RunStep;
const FileSource = std.build.FileSource;
pub const Options = struct {
@jbhoot
jbhoot / four-chars-or-less.ml
Last active September 10, 2023 18:36
A very crude script to check if a domain name consists of 4 characters or less
let remove_substr str substr =
Str.global_replace (Str.regexp substr) "" str;;
let remove_substrs str substrs =
List.fold_left remove_substr str substrs;;
let get_domain_name str =
let trimmed = remove_substrs str ["https://"; "http://"; "www"] in
let domain_frags = String.split_on_char '.' trimmed in
List.find (fun frag -> String.length frag > 0) domain_frags;;
@jbhoot
jbhoot / find-unsupported-srfis.js
Last active September 3, 2023 10:32
Find number of unsupported SRFIs for each scheme on this page (https://docs.scheme.org/srfi/support/)
/*
* As of the last run (3rd Sep, 2023),
* STKlos and Gauche have implemented more SRFIs than others.
* STKlos supports (245 total - 123 unsupported = 122) SRFIs.
* Gauche supports (245 total - 124 unsupported = 121) SRFIs.
*/
/* No `let` or `const` in order to be able to paste into the browser console repeatedly. */
SchemeColumn = {
@jbhoot
jbhoot / experiments-with-event-handlers.res
Last active December 19, 2022 16:53
Experiments with typing event handlers
@val external document: Dom.document = "document"
@val external window: Dom.window = "window"
type opts = {useCapture: bool}
type ev<'t, 'ct> = {
target: 't,
currentTarget: 'ct,
}
@jbhoot
jbhoot / Demo.res
Created August 12, 2022 14:00
Rescript bindings to Hyperapp
let viewRoot = state => Main.attr()->Main.make([
Img.attr(~src="main.png", ~alt="Main image"),
"Behold the main image!"->Text.make
])
let initializeHyperapp = node => {
let _ = app({
init: initializeState->Action.NoPayload.toState,
view: viewRoot,
node: node,
@jbhoot
jbhoot / rescript-hyperapp.res
Created April 16, 2022 05:51
Rescript bindings for Hyperapp and @hyperapp/html
type action
type effect
type subscription
type dispatch = (. action) => unit
module Action = {
module NoPayload = {
external toState: ('s => 's) => action = "%identity"
external toStateWithEffect: ('s => ('s, effect)) => action = "%identity"
external toStateWithEffects2: ('s => ('s, effect, effect)) => action = "%identity"
@jbhoot
jbhoot / nix-primer.md
Last active June 24, 2021 12:25
An overview of Nix for a beginner

Disclaimer

I consider myself still at the end of the beginner phase, having barely scratched the surface. Everything below is my understanding of the Nix ecosystem. Parts of it might be incorrect or at least not pedantic.

My environment

I run nix on a non-M1 mac. My experience has been smooth, once you execute the necessary mac-specific command to allow nix-store to be installed at /nix/store (explained in the official manual.). I don't know what complexities M1 brings in.

I also run nixos on a thinkpad. nixos works very well on the happy paths (and most of the paths are happy paths). But as soon as you require a package that's not in nixpkgs, or then you have to dive deep inside the whole ecosystem. I am in the process of figuring out a few packages. For example, merlin does not provide the necessary files to vim. But I'm sold on the idea of declarative package and configuration management, so much so that I am planning to deploy nixos on my personal server when time permits.

@jbhoot
jbhoot / index.html
Created September 11, 2015 12:14
meeXYv
<div class='parent'>
<div class='child'>Hello</div>
<div class='child'>How</div>
</div>