Skip to content

Instantly share code, notes, and snippets.

View royteusink's full-sized avatar

Roy Teusink royteusink

View GitHub Profile
@royteusink
royteusink / change-sequence.js
Last active October 7, 2020 06:32
immutable.js - Move item in List to a specific location (change sequence, reorder)
if (action.toindex < 0) return state;
var olditem = state.get(action.index);
var newlist = state.delete(action.index).insert(action.toindex, olditem);
return newlist;
@royteusink
royteusink / styles.less
Last active January 13, 2017 11:47
Atom.io personal stylesheet
// Makes the scrollbar a little bit better to see.
atom-text-editor.editor ::-webkit-scrollbar-thumb {
background: #666 !important;
}
// Bidirectional text is broken, so let's pretend it doesn't exist.
atom-text-editor.editor .line {
unicode-bidi: bidi-override;
}
@royteusink
royteusink / add_smarty_to_laravel5.md
Last active February 20, 2019 10:09
Add Smarty Template to Laravel 5

Add (latest) Smarty Template to Laravel 5.

composer require smarty/smarty --prefer-dist dev-master

.gitignore

/storage/smarty
@royteusink
royteusink / vue-sanctum.md
Last active December 31, 2020 13:21
vue cli + laravel sanctum

CORS issues with local development setup Laravel Sanctum with Vue3 cli

app.yourdomain.test

vue app created with vue cli.

axios.create({
  baseURL: process.env.VUE_APP_API_URL,
  withCredentials: true
@royteusink
royteusink / silverstripe-template-include-viewscripe.md
Last active October 29, 2021 09:40
SilverStripe template include viewscope unqiue id

Installation

composer require ramsey/uuid

app/src/TemplateHelpers.php

<?php
@royteusink
royteusink / AppServiceProvider.php
Last active June 15, 2022 07:37
Laravel migration drop index if exists
<?php
// app/Providers/AppServiceProvider.php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
public function boot()
{
Blueprint::macro('dropIndexIfExists', function ($index) {
/** @var Blueprint $this */
@royteusink
royteusink / helpers.php
Last active August 25, 2022 14:26
Laravel PHP Unit test private and protected variable or function
<?php
if (!function_exists('testShadow')) {
/**
* Magically access a private or protected variable or methods from an instance of a class.
* Use this only in UnitTests
*
* @param mixed $instance Instance of a class
* @param string $name Name of the inaccessible variable or method
* @return mixed variable
@royteusink
royteusink / search_by_key_recursive.php
Created September 26, 2022 10:40
Search for a key in a nested array
<?php
function searchByKey(array $array, $key)
{
if (array_key_exists($key, $array)) return $array[$key];
$recursive = function($chunk) use ($key, &$recursive) {
foreach ($chunk as $k => $v) {
if ($k === $key) return $chunk[$key];
if (is_array($v) && $found = $recursive($v)) return $found;
@royteusink
royteusink / array-growsort.md
Last active February 15, 2024 15:01
Grow sort an array

Growsort

Maak een nieuwe array op basis van een groeisorteeralgoritme, begint bij de oorsprong en groeit vervolgens geleidelijk naar het begin en begin van de array.

Example use case: Loading images for a scroll animation sequence and start loading at a specific percentage

const imagesArray = [
    "image1.jpg",
    "image2.jpg",
@royteusink
royteusink / GenerateTypescriptRoutes.md
Last active November 19, 2024 19:15
Generate Laravel routes for typescript (SPA)

Laravel Command to generate route endpoints that can be used in typescript fully threeshakable.

GenerateTypescriptRoutes.php

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;