Skip to content

Instantly share code, notes, and snippets.

Avatar

Ryan Brown ryantbrown

View GitHub Profile
@ryantbrown
ryantbrown / gulp-resize-and-minify-images.js
Last active Jun 27, 2020
Gulp - Resize and Optimize / Minify Images
View gulp-resize-and-minify-images.js
/**
* Make sure Graphicsmagick is installed on your system
* osx: brew install graphicsmagick
* ubuntu: apt-get install graphicsmagick
*
* Install these gulp plugins
* glup, gulp-image-resize, gulp-imagemin and imagemin-pngquant
*
* Group images according to their output dimensions.
* (ex: place all portfolio images into "images/portfolio"
@ryantbrown
ryantbrown / gulp-zip.js
Created Mar 22, 2015
Node: Create Zip File with Gulp
View gulp-zip.js
var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')(); // Load all gulp plugins
// automatically and attach
// them to the `plugins` object
var runSequence = require('run-sequence'); // Temporary solution until gulp 4
// https://github.com/gulpjs/gulp/issues/355
@ryantbrown
ryantbrown / s3upload.sh
Created Feb 1, 2018
Bash script to Upload folder to S3
View s3upload.sh
# Set AWS credentials and S3 paramters
AWS_KEY=""
AWS_SECRET=""
S3_BUCKET=""
S3_BUCKET_PATH="/"
S3_ACL="x-amz-acl:private"
function s3Upload
{
path=$1
@ryantbrown
ryantbrown / laravel-5-dynamic-events.php
Last active Dec 10, 2019
Laravel 5: Dynamic Events
View laravel-5-dynamic-events.php
<?php
// creating new event handlers by extending Handler and
// store them in a "Handlers" directory to be read by
// the service provider, which will loop through the
// directory and Event::subscribe to each one.
// Make sure you prefix each handler method with
// "on" (ex: onUserRegister) as only these methods
// will be listened for.
@ryantbrown
ryantbrown / checkbox.css
Last active Aug 14, 2018
SVG based checkbox
View checkbox.css
.checkbox {
height: 40px;
width: 40px;
outline: none;
cursor: default;
border: 0;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
@ryantbrown
ryantbrown / time-elapsed.php
Last active Apr 30, 2018
Get days, hours and minutes that have passed from a given date
View time-elapsed.php
<?php
// get interval
// format of $datetime is "Y-m-d H:i:s"
$interval = (new \DateTime("now"))->diff(new \DateTime($datetime));
// get specific times
list($days, $hours, $minutes) = explode(" ", $interval->format("%d %h %i"));
@ryantbrown
ryantbrown / click-outside-element.js
Last active Apr 30, 2018
Handle a click outside of a parent element
View click-outside-element.js
// the parent, avoid clicks inside this element
const parent = document.getElementById('parent');
window.addEventListener('click', e => {
let elem = e.target;
// loop through the target's parent nodes to see if it matches
for ( ; elem && elem !== document; elem = elem.parentNode ) {
@ryantbrown
ryantbrown / es-nested-agg-nested-query.json
Last active Feb 27, 2018
Elastic search nested aggregate with nested query
View es-nested-agg-nested-query.json
GET influencers/_search
{
"size": 0,
"aggregations": {
"influencers": {
"nested": {
"path": "interests"
},
"aggs": {
"names": {
@ryantbrown
ryantbrown / composer.json
Created Feb 21, 2018
Private composer package
View composer.json
// main app
"repositories" : [
{
"type": "package",
"package": {
"name": "grininc/platform-shared",
"version": "dev-master",
"source": {
"url": "git://github.com/grininc/platform-shared.git",
"type": "git",
@ryantbrown
ryantbrown / magento-add-attribute-option.php
Last active Apr 10, 2016
Magento - Add attribute option
View magento-add-attribute-option.php
<?php
function addAttributeOption($attribute_code, $attribute_value) {
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;
$attribute_code = $attribute_model->getIdByCode('catalog_product', $attribute_code);
$attribute = $attribute_model->load($attribute_code);