Skip to content

Instantly share code, notes, and snippets.

View danrichards's full-sized avatar
🎯
Focusing

Dan Richards danrichards

🎯
Focusing
View GitHub Profile
@danrichards
danrichards / .danrc
Last active March 12, 2019 19:26
Productive .bashrc file for your BITNAMI LAMP server. (using with Amazon AMI-7679c91e)
# ------------------------------------------------------------------
# IF YOU EDIT THIS FILE OUTSIDE OF THE SERVER, BE SURE YOUR LINE
# ENDINGS ARE SET TO UNIX. SublimeText2 > View > Line Endings > Unix
# ------------------------------------------------------------------
# Put .danrc into the same folder as your .bashrc file
# Typically, this is /home/username/
# $ sudo nano /home/username/.bashrc
# Include in your .bashrc file
# source .danrc
# -----------------------------------------------------------------
@danrichards
danrichards / .profile
Last active August 29, 2015 14:27 — forked from tamlyn/.profile
Configs for our command line tools
# Console2 Settings can be reached by pressing Ctrl + Alt + S
# Use nano instead of vim
EDITOR=nano
# always list in long format
alias ls='ls -la --color'
# set dynamic prompt and window/tab title
PS1='\[\e]0;${PWD##*/}\a\]\n' # set window title
@danrichards
danrichards / laravel-model-unique-slug.php
Last active December 20, 2015 21:24
Retrieve a unique slug with your Laravel model.
/**
* Find a unique slug.
*
* @see https://github.com/cocur/slugify
* @param $text
*
* @return string
*/
public static function getUniqueSlug($text)
{
@danrichards
danrichards / _.default.js
Last active February 21, 2016 04:46
_.default(value, default_val) Provide a default value if param is undefined or null.
/**
* Use default vlaue
*/
_.mixin({
default: function(value, default_val) {
if (value === null && typeof value === "object") {
return default_val;
}
return _.isUndefined(value) || _.isNull(value) ? default_val : value;
}
@danrichards
danrichards / $.alert.js
Last active February 21, 2016 04:48
jQuery / Handlebars alert plugin for Bootstrap.
/**
* @author Dan Richards <drichards@shapeup.com>
*
* Assumes a compiled handlebars template is available.
* @see http://handlebarsjs.com/precompilation.html
*/
(function ($) {
$.extend({
alert: function(message, params) {
var alertContainer = $('#alerts');
@danrichards
danrichards / $.populate.js
Last active February 21, 2016 07:25
$.populate(form, obj) Provided a selector and object, set the corresponding form fields.
/**
* Provided a data Object, set the corresponding form fields.
*
* @param obj Object Your data.
* @return Array Fields updated.
*/
$.fn.populate = function(obj) {
var updated = [];
for (var field in obj) {
@danrichards
danrichards / ternaries.md
Last active June 5, 2020 02:53
PHP for those who love ternaries

PHP Ternary cheat sheet

Be careful with your ternaries, folks.

var_dump('' ?: 'empty stringy');                 // empty string
var_dump(null ?: 'nully');                       // nully
var_dump(0 ?: 'zeroy');                          // zeroy
var_dump(false ?: 'falsey'); // falsey
@danrichards
danrichards / Wizard.js
Created March 28, 2016 02:36
Javascript wizard class, uses Jquery(for AJAX), and Underscore.
/**
* SubmitWizard
*
* @returns {SubmitWizard}
* @constructor
*/
function SubmitWizard(options) {
var that = this;
/**
@danrichards
danrichards / modulo-splice.php
Last active April 7, 2016 17:35
Use dynamic modulo to incrementally splice an array.
<?php
/**
* Provided a threshold, determine modulo to keep every m-th item in the
* array where m = ceil(count($array) / $threshold)
*
* @param $arr
* @param $threshold
* @param string $round
@danrichards
danrichards / isIE.mixin.js
Created May 23, 2016 19:14
Underscore Mixin for IE (Internet Explorer) browser detection.
// https://jsfiddle.net/danrichards/16mxh9th/
_.mixin({
isIE: function(mixed) {
if (_.isUndefined(mixed)) {
mixed = [/MSIE\s7\./, /MSIE\s8\./, /MSIE\s9\./, /MSIE\s10\./, /Trident.*rv\:11\./];
} else if (_.isArray(mixed)) {
mixed = mixed.map(function(browser) {
return new RegExp('MSIE\s'+browser.toString()+'\.', 'g');
});