Skip to content

Instantly share code, notes, and snippets.

View Neoglyph's full-sized avatar
🧙
wizard in training since 1989

Adam Stradovnik Neoglyph

🧙
wizard in training since 1989
View GitHub Profile
@Neoglyph
Neoglyph / limit-file-upload.js
Created March 26, 2019 16:05
Limit file size on file input (basic javascript)
var imageStatus = document.getElementById('my-file-input');
// imageStatus = input[type="file"]
if (files[0].size > fileMaxSize) {
imageStatus.innerText = 'Datoteka ne sme biti večja od 5MB!';
imageUpload.value = '';
var imageUploadClone = imageUpload.cloneNode(true);
imageUpload.parentNode.replaceChild(imageUploadClone, imageUpload);
}
@Neoglyph
Neoglyph / Model.php
Created February 25, 2019 13:07
Laravel Model Events
class User extends Model
{
public static function boot()
{
parent::boot();
self::creating(function($model){
// ... code here
});
@Neoglyph
Neoglyph / resize-images-shell.sh
Created December 17, 2018 08:33
Simple shell script to resize images to specific sizes with imagemagick
shopt -s nullglob
for i in *.png; do
echo "Resizing $i"
FILE=$i
FILENAME="${FILE%%.*}"
EXT="${FILE##*.}"
convert $FILE -resize 270x "./resized/${FILENAME}-270.${EXT}"
convert $FILE -resize 320x "./resized/${FILENAME}-320.${EXT}"
convert $FILE -resize 560x "./resized/${FILENAME}-560.${EXT}"
convert $FILE -resize 800x "./resized/${FILENAME}-800.${EXT}"
@Neoglyph
Neoglyph / lazyloadbg.js
Created November 27, 2018 09:48
Lazyload background images
const loadBackgroundImage = (element) => {
if (typeof element.dataset.src === 'undefined') { return }
const src = element.dataset.src
element.style.backgroundImage = `url(${src})`
element.removeAttribute('data-src')
}
const handleIntersection = (entries, observer) => {
for(let i = 0; i < entries.length; ++i) {
loadBackgroundImage(entries[i].target)
@Neoglyph
Neoglyph / remove-remote-tag
Created October 22, 2018 11:19
GIT - Remove remote tag
git tag -d tag-name
git push origin :refs/tags/tag-name
@Neoglyph
Neoglyph / rgb2cmyk.php
Last active November 17, 2023 21:57
Convert RGB to CMYK in PHP with Imagick
<?php
$iccProfile = '../path_to_icc/Profile.icc';
$image = new Imagick();
$image->clear();
$image->readImage($imagePath);
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
return;
}
$iccCmyk = file_get_contents($iccProfile);
@Neoglyph
Neoglyph / resolve.scss
Created September 5, 2018 11:03
Mix - resolve loop import issue
@import url("~fullcalendar/dist/fullcalendar.min.css");
@Neoglyph
Neoglyph / laravel-last-login.php
Last active August 2, 2018 12:08
Laravel last login event
<?php
// thanks to: https://stevenwestmoreland.com/2017/03/recording-last-login-information-using-laravel-events.html
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@Neoglyph
Neoglyph / indesign-script-page-numbers.js
Created July 25, 2018 06:51
Set InDesign ExtendScript Page Numbers
app.activeDocument.sections[0].continueNumbering = false;
app.activeDocument.sections[0].pageNumberStart = 5;
@Neoglyph
Neoglyph / indesign-rename-tags.js
Last active July 18, 2018 09:34
InDesign script function - Rename tags
/**
*
* @prop XMLElement rootEl
* @prop string name
* @prop string replaceWith
*/
function replaceTag(rootEl, name, replaceWith) {
var elements = rootEl.xmlElements;
for(var i = 0; i < elements.length; ++i) {
if(elements[i].markupTag.name === name) {