Skip to content

Instantly share code, notes, and snippets.

@cdsaenz
cdsaenz / index.html
Created August 19, 2022 14:11
Demo Alpine JS and Fetch from Remote API
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alpine Ajax test</title>
</head>
<body>
<h1>Users API Retrieval Test</h1>
@BinaryKitten
BinaryKitten / toRawSql.php
Last active January 22, 2023 21:52
toRawSql.php
<?php
declare(strict_types=1);
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder as QueryBuilder;
QueryBuilder::macro(
'toRawSql',
function () {
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@JeffreyWay
JeffreyWay / recaptcha.blade.php
Last active August 1, 2023 15:52
Recaptcha Example using Laravel, Blade Components, and Alpine
<div
x-data="recaptcha()"
x-init="init"
@recaptcha.window="execute"
></div>
@push('scripts')
<script src="https://www.google.com/recaptcha/api.js?render=explicit"></script>
<script>
@AlexVanderbist
AlexVanderbist / fn-live-template-phpstorm.xml
Created July 22, 2020 13:58
PhpStorm arrow function live template
<template name="fn" value="fn ($TYPE$ $INSTANCE$) =&gt; $INSTANCE$$END$" description="Arrow function" toReformat="false" toShortenFQNames="true">
<variable name="TYPE" expression="completeSmart()" defaultValue="" alwaysStopAt="true" />
<variable name="INSTANCE" expression="concat(&quot;$&quot;, camelCase(TYPE))" defaultValue="" alwaysStopAt="false" />
<context>
<option name="PHP Expression" value="true" />
<option name="PHP Statement" value="true" />
</context>
</template>
@jacobshenning
jacobshenning / app.js
Last active April 23, 2024 16:39
An alpine datatable
// Alpine JS datatable
window.datatable = function (data) {
return {
source: data,
data: data,
// Pagination
current_page: 0,
items_per_page_value: 5,
@KevinBatdorf
KevinBatdorf / add-alpine-js-to-tailwind-ui.js
Last active May 2, 2024 11:36
Auto copy the Alpine code from Tailwind UI's copy button
// ==UserScript==
// @name Add AlpineJs to Tailwind UI
// @namespace http://tampermonkey.net/
// @version 3.0
// @description Add Alpine JS code to Tailwind Ui copy/paste
// @author https://gist.github.com/KevinBatdorf/8bd5f808fff6a59e100dfa08a7431822
// @match https://tailwindui.com/components/*
// @grant none
// ==/UserScript==
@premek
premek / mv.sh
Last active March 5, 2024 17:43
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
@mattstauffer
mattstauffer / example.html
Created March 3, 2020 15:46
Example of logging Laravel Livewiure component state
<script src="{{ asset('js/app.js') }}"></script>
<script>
let logComponentsData = function () {
window.livewire.components.components().forEach(component => {
console.log(component.name);
console.log(component.data);
});
};
document.addEventListener("livewire:load", function(event) {
@JacobBennett
JacobBennett / problem.php
Created December 31, 2019 17:20
A little mess I had on my hands today
<?php
$start = Carbon::parse('2019-12-24');
$end = Carbon::parse('2020-01-04');
$birthDate = Carbon::parse('1985-12-24')->addDays(random_int(0,6));
// figure out if month and day of birthDate is between the $start and $end