Skip to content

Instantly share code, notes, and snippets.

View Pacheco95's full-sized avatar
🤓
Building awesome things

Michael Pacheco Pacheco95

🤓
Building awesome things
View GitHub Profile
@Pacheco95
Pacheco95 / pagination.hook.jsx
Created November 6, 2020 01:57
A hook to sync URL pagination
import React from "react";
function parsePagination() {
const searchParams = new URLSearchParams(window.location.search);
return {
page: parseInt(searchParams.get("page") || 1),
pageSize: parseInt(searchParams.get("pageSize") || 10),
};
}
@Pacheco95
Pacheco95 / urlQueryParamParser.js
Created November 7, 2020 17:07
Schema based query string parser
const assert = require("assert");
const objectify = (o, [k, v]) => ({ ...o, [k]: v });
function parseFromURL(schema, url = window.location.search) {
const searchParams = new URLSearchParams(url);
return Object.entries(schema)
.map(([par, { def }]) => [par, searchParams.get(par) ?? def ?? undefined])
.map(([par, val]) => [par, schema[par].transform?.(val) ?? val])
@Pacheco95
Pacheco95 / react-boilerplate-cra-template-error.log
Created December 8, 2020 22:47
react-boilerplate-cra-template ERESOLVE unable to resolve dependency tree
$ npx create-react-app --template cra-template-rb cra-boilerplate-ts
Need to install the following packages:
create-react-app
Ok to proceed? (y) y
Creating a new React app in /home/user/repositories/cra-boilerplate-ts.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-rb...
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void keyEventCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
// settings
const unsigned int SCR_WIDTH = 800;
@Pacheco95
Pacheco95 / terminator-config.properties
Created October 22, 2021 12:59
Terminator configuration file (copy content to ~/.config/terminator/config)
[global_config]
window_state = maximise
borderless = True
title_hide_sizetext = True
inactive_color_offset = 1.0
title_use_system_font = False
title_font = Fira Code Semi-Bold 10
[keybindings]
[profiles]
[[default]]
@Pacheco95
Pacheco95 / struct.py
Last active December 21, 2022 18:14
Python serializable type that allow dot notation access
import json
from json import JSONEncoder
from typing import Iterator, Mapping
class StructEncoder(JSONEncoder):
def default(self, o):
return o.__dict__ if isinstance(o, Struct) else super().default(o)
@Pacheco95
Pacheco95 / VulkanDoubleCallWrapper.hpp
Created November 11, 2023 00:32
Helper wrapper function to avoid the doubled calls for vulkan functions like vkEnumerateDeviceExtensionProperties
#ifndef VULKAN_DOUBLE_CALL_WRAPPER_HPP
#define VULKAN_DOUBLE_CALL_WRAPPER_HPP
#include <vulkan/vulkan.h>
#include <tuple>
#include <vector>
namespace engine {
@Pacheco95
Pacheco95 / proxy.ts
Created April 7, 2025 18:06
Typescript type safe proxy function and decorators
function isPromise(value: any): value is Promise<any> {
return (
value !== null &&
typeof value === "object" &&
typeof value.then === "function" &&
typeof value.catch === "function"
);
}
async function asyncFunction<T>(index: number, array: Array<T>) {