Skip to content

Instantly share code, notes, and snippets.

@degecko
degecko / asset.js
Created May 3, 2022 12:48
Hack for changing the footer content on Laravel Nova 4
Nova.booting(app => {
app.mixin({
mounted () {
// Searching for the footer component and replacing it.
if (this.$el.id !== 'nova' && (this.$el?.innerText || '').match(/Laravel LLC . by Taylor Otwell and David Hemphill/)) {
this.$el.innerHTML = `
<div class="text-center">
Copyright &copy; ${new Date().getFullYear()} Nobody
</div>
`
@degecko
degecko / calculate.php
Created January 29, 2021 06:32
Benchmark Nested Set left/right recalculation algorithm
<?php
$cats = require 'generate.php';
$catsById = $children = [];
foreach ($cats as $i => $cat) {
// $cat[0] is the ID selector.
$catsById[$cat[0]] = $cat;
// $cat[1] is the PARENT ID selector.
const puppeteer = require('puppeteer');
const fs = require('fs');
const size = {
desktop: { width: 1600, height: 900 },
mobile: { width: 360, height: 720 },
};
(async () => {
const browser = await puppeteer.launch({
args: ['--no-sandbox', `--window-size=${size.desktop.width},${size.desktop.height}`],
<?php
/**
* Scrapes free-proxy-list.net.
*
* Usage e.g.:
* Assume $fp = new FreeProxy;
*
* $fp->randomProxy(); // Returns a random proxy from anywhere around the world.
* $fp->setCountry('DE')->randomProxy(); // Returns a proxy from DE, if available.
<!-- A SematicUI Dropdown VueJS Component -->
<template>
<div :class="classes">
<div class="text" v-if="showTitle">
<img :src="selected.avatar" v-if="hasAvatar && selected">
<span v-text="title"></span>
</div>
<i class="icon" :class="{ dropdown: ! loading, loading }"></i>
<?php
if (! function_exists('get_slug')) {
/**
* Returns the requested slug part from the REQUEST_URI.
*
* E.g.:
* get_slug(1) where the URI is /app/123/edit will be equal to "app"
* get_slug(2) where the URI is /app/123/edit will be equal to "app/123"
* get_slug() where the URI is /app/123/edit will be equal to "app/123/edit"
@degecko
degecko / recursive-ids.js
Last active August 16, 2016 09:13
Recursively sets DOM tree unique ids on each child element of the given jQuery selector.
/**
* Recursively sets DOM tree unique ids
* on each child element of the given jQuery selector.
*
* E.g. Given elem = $('<div> <p> <strong></strong><strong></strong> </p> <p></p> </div>')
*
* setTreeIds(elem) will result in:
*
* <div tid="0">
* <p tid="00">
@degecko
degecko / regex.php
Created December 29, 2015 11:31
Match everything but something
<?php
$data = 'This is my data that contains SOMETHING I DON\'T WANT in it.';
preg_match('#^(?:(?!SOMETHING).)*$#', $data, $results);
<?php
/**
* Works for:
*
* isset_or($_GET['test'], false)
* and
* isset_or($_GET['test'], 'other true value', false)
*/
#!/usr/bin/env php
<?php
/* Install notes:
Copy this script onto your web server. I'll assume the location is /opt/tools/add_vhost.php
Give it the right privileges:
# chmod +x /opt/tools/add_vhost.php