Skip to content

Instantly share code, notes, and snippets.

View TWithers's full-sized avatar

Tim Withers TWithers

View GitHub Profile
@TWithers
TWithers / tm-excel-import.js
Last active December 29, 2016 11:56
Angular Excel file with SheetJS and Papa Parse
(function(angular){
angular
.module('tm-directives')
.directive('tmExcelImport',tmExcelImport);
tmExcelImport.$inject=['$timeout'];
function tmExcelImport($timeout){
var directive = {
scope:{
callback:'&tmExcelCallback'
@TWithers
TWithers / GooglePlacesAutocomplete.html
Last active April 25, 2024 07:34
AlpineJS implementation of Google Places Autocomplete
<div x-data="googlePlacesAutocomplete" class="grid grid-cols-3 gap-2">
<input type="text" x-model="address.address1" x-ref="googleAutocomplete" autocomplete="chrome-off" class="col-span-3 sm:col-span-2 order-1" placeholder="Add&#8204;ress">
<input type="text" x-model="address.address2" placeholder="Apt/Ste" class="col-span-3 sm:col-span-1 order-2">
<input type="text" x-model="address.city" placeholder="Ci&#8204;ty" class="col-span-1" x-bind:class="`order-${order.locality}`">
<select x-model="address.state" placeholder="St‌ate" class="col-span-1 order-4" x-show="isUSA">
<option value="">State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
let alpineLoaded = false;
let livewireLoaded = false;
document.addEventListener('alpine:init', () => {
alpineLoaded = true;
setupLivewireErrorListener();
});
document.addEventListener('livewire:load', () => {
livewireLoaded = true;
<h1>List</h1>
<ul
x-data="{items: @entangle('items').defer, newItem:'', errors:{}}"
@validation.window="errors = $event.detail">
<template x-for="(item, index) in items">
<li x-bind:class="errors['item.'+index'] ? 'text-danger' : ''">
<span x-text="item"></span>
<i x-show="errors['item.'+index']"
x-text="errors['item.'+index] ? errors['item.'+index].join(' ') : ''"
>
<script>
document.addEventListener('alpine:init', () => {
Alpine.data('flatpickr', () => ({
selectedDate: '',
init() {
const fp = new window.flatpickr(this.$refs.picker, {});
if (typeof window.flatpickrInputs === 'undefined') {
window.flatpickrInputs = [];
}
window.flatpickrInputs.push(fp);
@TWithers
TWithers / arrayToCsv.php
Created December 6, 2022 01:51
Laravel - 2D Array to CSV string
function arrayToCsv(array $data) {
retun collect($data) // turn into collection
->map(fn ($i) => collect($i)) // turn next layer into collection
->pipe(fn ($c) => $c->prepend($c->first()->keys())->map->values()) //grab keys from firt item in the array and prepend them and return only the array values
->pipe(function($c){ // format fields for CSV: escape " with another ", wrap fields with new lines, commas, and double quotes with a quote
return $c->map->map(function($i){
if(Str::contains($i,'"')) {
return '"'.str_replace('"', '""', $i).'"';
} elseif (Str::contains($i,[',',"\n"])){
return '"'.$i.'"';
import {ray, Ray} from "node-ray/web";
const colors = ['green', 'orange', 'red', 'purple', 'blue', 'gray'];
const componentMap = new Map();
let colorIndex = 0;
const Payload = class {
constructor() {
this.remotePath = null;
this.localPath = null;
@TWithers
TWithers / HandlesStringTrimming.php
Created May 13, 2024 16:56
String Trimming For Livewire
<?php
namespace App\Livewire;
use App\Livewire\Attributes\DontTrim;
use App\Livewire\Attributes\Trim;
trait HandlesStringTrimming
{
public bool $trimsAllStrings = true;