Skip to content

Instantly share code, notes, and snippets.

Avatar

Caleb Porzio calebporzio

View GitHub Profile
View reactive-lens-utility.js
import { reactive } from '@vue/reactivity'
function lens(value) {
let lookup = {}
let current
let get = () => current
let set = (newValue) => {
View memoize.php
<?php
function memoize($target) {
static $memo = new WeakMap;
return new class ($target, $memo) {
function __construct(
protected $target,
protected &$memo,
) {}
View problem.md

Help me solve morphdom woes in Livewire

Blade "@if" statements can sometimes cause problems in Livewire.

I can eliminate those problems if I can inject markers around those conditional block like so:

@if (...)
    <div>foo</div>
@endif
View ml.html
<html>
<script src="/basic/canvas.js"></script>
<script src="/basic/ml.js"></script>
<div style="border: 1px solid black; width: 100px; height: 100px;">
<canvas width="200" height="200" id="points" style="position: absolute; width: 100px; height: 100px"></canvas>
<canvas width="200" height="200" id="line" style="position: absolute; width: 100px; height: 100px"></canvas>
</div>
<script>
View alpine-turbo-adapter.html
<script data-turbo-eval="false">
document.addEventListener('turbo:before-render', () => {
let permanents = document.querySelectorAll('[data-turbo-permanent]')
let undos = Array.from(permanents).map(el => {
el._x_ignore = true
return () => {
delete el._x_ignore
}
View utils.js
function benchmark(times, callbacks) {
let result = {}
Object.entries(callbacks).forEach(([key, value]) => {
let thing = {}
let start = performance.now()
for (let index = 0; index < times; index++) {
value()
}
View twitter_clone_tailwind2.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tailwindcss/ui@latest/dist/tailwind-ui.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
View twitter_clone_markup.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@0.7.4/dist/tailwind.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
@calebporzio
calebporzio / karabiner_vim_mode.json
Created March 27, 2020 18:13
A backup of the ideal vim mode karabiner plugin
View karabiner_vim_mode.json
{
"title": "Caleb's Vim Mode",
"author": "Caleb Porzio(calebporzio.com)",
"rules": [
{
"description": "Vim Mode [D as Trigger Key]",
"manipulators": [
{
"from": {
"key_code": "d",
@calebporzio
calebporzio / caps_lock_to_command_escape.json
Last active November 24, 2022 19:54
A Karabiner-Elements complex modification rule
View caps_lock_to_command_escape.json
{
"title": "Caps Lock To Command/Escape",
"author": "Caleb Porzio(calebporzio.com)",
"homepage": "https://gist.github.com/calebporzio/2d07cd0e3013e7eaf16f5a2ea4f594ae",
"import_url": "karabiner://karabiner/assets/complex_modifications/import?url=https://gist.githubusercontent.com/calebporzio/2d07cd0e3013e7eaf16f5a2ea4f594ae/raw/08c397b09fbaa5ec90cf161e5bca97bdb43e8c55/caps_lock_to_command_escape.json",
"rules": [
{
"description": "Caps Lock to Command/Escape",
"manipulators": [
{