Skip to content

Instantly share code, notes, and snippets.

View InToSSH's full-sized avatar

Jarda T. InToSSH

  • Czech Republic
View GitHub Profile
@InToSSH
InToSSH / Autocomplete.vue
Last active July 26, 2023 20:32
PrimeVue AutoComplete wrapper to accept array of objects for items with 'label' and 'value' props and return only the 'value' prop value in the v-model. It now also supports the multiple version - return an array of values (IDs) and also accepts array of values as v-model and converts them back to objects for the OG Autocomplete
<template>
<div class="field">
<label :for="id" :class="{'p-error':(v && v.$invalid && v.$dirty)}">{{ label }} {{ v && 'required' in v ? '*' : ''}}</label>
<AutoComplete
:model-value="modelItem"
@update:modelValue="(selected) => valueUpdated(selected)"
:suggestions="filteredItems"
@complete="searchItems($event)"
:dropdown="true"
@InToSSH
InToSSH / eloquent_macro.php
Last active June 17, 2023 00:33
Laravel Eloquent - Order By Relation macro
<?php
Builder::macro('orderByRelation', function(string $searchColumn, string $dir) {
list($relation, $column) = explode('.', $searchColumn);
$relation_table = $this->getRelation($relation)->getModel()->getTable();
$relation_foreign_key = $this->getRelation($relation)->getForeignKeyName();
$query_table = $this->getModel()->getTable();
$this->select($query_table . '.*')
->join($relation_table, $query_table . '.' . $relation_foreign_key, '=', $relation_table . '.id')
->orderBy($relation_table . '.' . $column, $dir);
@InToSSH
InToSSH / swift_mailer_image_replacer.php
Last active November 17, 2020 11:08
This function looks up images in the HTML email body content that are encoded in Base64, attaches them to the Swift_Message, replaces the Base64 with CID and returns modified body.
protected function replaceBase64ImagesWithCid($content, Swift_Message $message)
{
return preg_replace_callback(
"/(<img[^>]*src *= *[\"']?)([^\"']*)/i",
function ($matches) use ($message) {
$is_base64 = preg_match("/data:([a-z]+\/[a-z]+);base64,(.*)/i", $matches[2], $image_data);
if ($is_base64) {
$contentType = $image_data[1];
list($type, $ext) = explode("/", $contentType);
@InToSSH
InToSSH / esphome_venetian_blind.yaml
Last active March 29, 2024 12:22
ESPHome - Venetian Blind example with time-based cover control and tilt with Shelly2.5
# This is an example yaml config file for ESPHome to control Venetian blinds with one motor, where turning on the motor in 'up' direction first fully tilts open the blind then starts moving up, and vice versa, in 'down' direction first tilts blind closed, then starts moving down.
# AUTHOR: InToSSH - github.com/InToSSH
substitutions:
device_name: Living Room Cover
esphome:
name: living_room_blind
platform: ESP8266
board: esp01_1m