Skip to content

Instantly share code, notes, and snippets.

View jharrilim's full-sized avatar
🐚
conchious

Joe jharrilim

🐚
conchious
View GitHub Profile
@jharrilim
jharrilim / option.ts
Last active July 17, 2023 18:43
Javascript Option
/**
* Usage:
* let a = Option.of(someNullableValue);
*
* for (let value of a) { // access value safely only if it exists
* console.log('a not null/undefined value: ', value);
* }
*
*/
class Option<T> {
@jharrilim
jharrilim / checkpoint_allocator.rs
Created May 20, 2023 21:50
Index based regional allocator
#[derive(Debug)]
pub struct Idx<T> {
idx: usize,
_ty: PhantomData<T>
}
impl<T> Clone for Idx<T> {
fn clone(&self) -> Self {
*self
}
use rand::prelude::{SliceRandom, ThreadRng};
use std::{
fmt,
io::{stdin, stdout, Write},
time::Duration,
};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
pub fn blackjack() -> Result<(), Box<dyn std::error::Error>> {
@jharrilim
jharrilim / index.js
Created March 30, 2023 19:40
Scala contextual _, but in javascript
/**
* By using JS Proxy, we can emulate how Scala uses _
* in function arguments, like:
* val names = people_list.map(_.name)
*/
let _ = new Proxy({}, {
get(_target, prop, _receiver) {
return m => typeof m[prop] === 'function'
? m[prop]()
@jharrilim
jharrilim / .dockerignore
Created September 30, 2022 23:08
Helix editor in Docker
target
.direnv
helix-term/rustfmt.toml
helix-syntax/languages/
result
runtime/grammars/**
.github
.vscode
*.png
*.md
@jharrilim
jharrilim / main.java
Created July 16, 2022 19:50
Java developer: Mom can we have pattern matching? Mom: We have pattern matching at home
public class Main {
public static void main(String[] args) {
try {
Parser.parse("yo");
} catch (StringType s) {
System.out.println(s.value);
} catch (IntegerType i) {
System.out.println(i.asString());
} catch (Type _t) {
System.out.println("unknown type");
@jharrilim
jharrilim / github_strategy.rb
Created July 3, 2022 22:08
Homebrew private github repo strategy. As of July 2022, this doesn't exist in Homebrew (it hasn't for a few years actually). Instructions in comment.
# GitHubPrivateRepositoryDownloadStrategy downloads contents from GitHub
# Private Repository. To use it, add
# `using: GitHubPrivateRepositoryDownloadStrategy` to the URL section of
# your formula. This download strategy uses GitHub access tokens (in the
# environment variables `HOMEBREW_GITHUB_API_TOKEN`) to sign the request. This
# strategy is suitable for corporate use just like S3DownloadStrategy, because
# it lets you use a private GitHub repository for internal distribution. It
# works with public one, but in that case simply use CurlDownloadStrategy.
#
# Example Formula:
@jharrilim
jharrilim / query-builder.ts
Created February 11, 2021 01:15
Typescript query builder or something idk
type Query<T extends string, Prev extends string> = `${Prev}\n${T}`;
class QueryBuilder<T extends string, Prev extends string> {
constructor(private part: T, private prev: Prev) { }
with<NT extends string>(part: NT) {
return new QueryBuilder(part, this.get());
}
get(): Query<T, Prev> {
@jharrilim
jharrilim / api.js
Last active May 24, 2020 00:32
di.js
import Axios from 'axios';
import { inject } from './container';
export class Api {
constructor(baseURL) {
this._axios = Axios.create({ baseURL });
this._baseURL = baseURL;
}
toString() { return this._baseURL; }
}
@jharrilim
jharrilim / event-namespacing.js
Created December 1, 2019 03:56
constants with namespacing
class Events {
static Container = class Container {
static get ContainerCreated() { return Events.Container + ':created' };
static toString() {
return Events + ':container';
}
}
static toString() {
return 'events';