Skip to content

Instantly share code, notes, and snippets.

View djalmajr's full-sized avatar

Djalma Júnior djalmajr

View GitHub Profile
@djalmajr
djalmajr / README.md
Last active December 29, 2024 12:43
Iconify for react-native

Motivation: oktaysenkan/monicon#54 (comment)

// ./node_modules/metro/src/node-haste/DependencyGraph.js

// https://github.com/facebook/metro/issues/330
getSha1(filename) {
  const sha1 = this._fileSystem.getSha1(filename);
  if (!sha1) {
 function getFileHash(file) {
@djalmajr
djalmajr / generate-routes.ts
Last active July 31, 2024 12:06
File-based routes for React Router following Remix conventions
import type { Obj } from "help-es";
import { createElement, isValidElement } from "react";
import { Outlet, type RouteObject } from "react-router-dom";
type RO = RouteObject & { _path?: string };
const findRoute = (path: string, routes: RO[]) => {
return routes.find((r) => r.path === path || r._path === path);
};
@djalmajr
djalmajr / images_to_pdf.rb
Last active April 21, 2024 19:12
Converts images in a directory to pdf
#!/usr/bin/env ruby
###############################################################################
# Pre-requirements
#
# - sudo apt update & sudo apt install imagemagick libmagick++-dev
# or
# - brew install imagemagick
#
# - gem install mini_magick prawn
import { html, render } from 'https://cdn.skypack.dev/uhtml@3';
import { effect, signal } from 'https://cdn.skypack.dev/[email protected]';
const todos = signal([]);
const add = () => {
const uuid = crypto.randomUUID();
const text = `Item ${uuid.split('-')[1]}`;
todos.value = todos.value.concat({ uuid, text });
};
@djalmajr
djalmajr / createStore.js
Last active April 14, 2023 15:37
Reactive Store
const typeOf = (v) => ({}.toString.call(v).slice(8, -1).toLowerCase());
const isObj = (v) => ["array", "object"].includes(typeOf(v));
const isFn = (v) => "function" === typeOf(v);
function handler(callback) {
return {
get(obj, prop) {
if (prop === "_isProxy") return true;
let d = Object.getOwnPropertyDescriptor(obj, prop);
let ok = isObj(obj[prop]) && !obj[prop]._isProxy && d?.writable;
@djalmajr
djalmajr / html.js
Last active April 14, 2023 16:43
Simple HTML Renderer
const prefix = "δ";
const isAttr = /([^\s\\>"'=]+)\s*=\s*(['"]?)$/;
const hasPfx = (str) => str.search(prefix) !== -1;
const create = (tag, cfg) => Object.assign(document.createElement(tag), cfg);
export function html(strings, ...values) {
const tmpl = values.reduce((r, _, i) => {
return `${r}${isAttr.test(r) ? prefix + i : `<!--${prefix + i}-->`}${strings[i + 1]}`;
}, strings[0]);
@djalmajr
djalmajr / rename.sh
Created October 27, 2022 15:04 — forked from szeidner/rename.sh
Shell script for renaming an Android package and app name.
#!/bin/sh
set -e
PROGNAME=$(basename $0)
WORKING_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
OLD_TITLE="DTStart"
OLD_PACKAGE="old.package.name"
die() {
echo "$PROGNAME: $*" >&2
@djalmajr
djalmajr / capitalize.js
Created March 4, 2022 19:49
Capitalize Test
/**
* capitalize.js
*
* @param {string} str
* @returns string
*/
function capitalize(str) {
}
module.exports = { capitalize };
@djalmajr
djalmajr / get.js
Last active March 4, 2022 19:54
Get Test
/**
* get.js
*
* @param {string | string[]} path
* @param {object} data
* @returns unknown
*/
function get(path, data) {
}
// Exemplo de padrão modular usando IIFE
var contador = (function () {
var num = 0;
return {
incrementar: function () {
return ++num;
},
resetar: function () {