Skip to content

Instantly share code, notes, and snippets.

View ryantbrown's full-sized avatar

Ryan Brown ryantbrown

  • GRIN
  • Sacramento, CA
View GitHub Profile
@ryantbrown
ryantbrown / s3upload.sh
Created February 1, 2018 07:25
Bash script to Upload folder to S3
# 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 / gulp-resize-and-minify-images.js
Last active August 30, 2022 14:07
Gulp - Resize and Optimize / Minify Images
/**
* 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 March 22, 2015 23:08
Node: Create Zip File with Gulp
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 / laravel-5-dynamic-events.php
Last active December 10, 2019 00:24
Laravel 5: Dynamic Events
<?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 August 14, 2018 10:04
SVG based checkbox
.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 April 30, 2018 08:56
Get days, hours and minutes that have passed from a given date
<?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 April 30, 2018 08:56
Handle a click outside of a parent element
// 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 February 27, 2018 19:39
Elastic search nested aggregate with nested query
GET influencers/_search
{
"size": 0,
"aggregations": {
"influencers": {
"nested": {
"path": "interests"
},
"aggs": {
"names": {
@ryantbrown
ryantbrown / composer.json
Created February 21, 2018 17:18
Private composer package
// 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 April 10, 2016 07:24
Magento - Add attribute option
<?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);