Skip to content

Instantly share code, notes, and snippets.

View mikedugan's full-sized avatar

Mike Dugan mikedugan

View GitHub Profile
@mikedugan
mikedugan / phpstorm-doc.txt
Created May 14, 2014 20:36
PHPStorm automatic doc inserter - go to "File and Code Templates -> Includes -> PHP Function Doc Comment" and copy this in...automatically generates name, params, returns, throws, type, and empty description. To use: ALT+INS on Windows/Linux, CMD+N on Mac
/**
#if (${STATIC} == "static") * @type ${STATIC} #end
#if (${STATIC} != "static") * nonstatic #end
* @name ${NAME}
* @description ${CARET}
#if (${PARAM_DOC} != "") ${PARAM_DOC} #end
#if (${THROWS_DOC} != "") ${THROWS_DOC} #end
@mikedugan
mikedugan / eloquent-relations.php
Last active August 29, 2015 13:59
static and non-static functions to get relation methods of an Eloquent model
<?php
//preferably in some repository class (or the model itself)
// this assumes you prefix your relations consistently, ie 'public function relSomeRelation()'
/**
* @param string relation method delimiter
* @return array relationship methods
*/
public function getRelationMethods($delimiter)
@mikedugan
mikedugan / activate.jquery.js
Created April 1, 2014 22:15
simple html input activation/deactivation
$('.activator').click(function() {
var target = $('#'+$(this).data('target')); //returns data-target value
if(target.attr('disabled'))
{ target.removeAttr('disabled'); }
else target.attr({'disabled':'disabled'});
});
@mikedugan
mikedugan / laravel-validation.php
Created March 25, 2014 10:44
Validation with laravel and blade
//use a service - don't forget to namespace!
abstract class Validator {
protected $errors;
public function validate($input)
{
$validator = Validator::make($input, static::$rules);
if($validator->fails())
{
$this->errors = $validator->messages();
@mikedugan
mikedugan / aliases.sh
Last active August 29, 2015 13:56
zshrc, also largely compatible with bash
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias .......='cd ../../../../../..'
alias ........='cd ../../../../../../..'
alias .........='cd ../../../../../../../..'
alias ..........='cd ../../../../../../../../..'
alias .2='cd ../..'
@mikedugan
mikedugan / new_gist_file_1
Created February 15, 2014 18:21
vimrc for powerline, nerdtree, tagbar, taglist, python autocomplete
_
@mikedugan
mikedugan / Preferences.sublime-settings.json
Created February 15, 2014 18:19
sublime text preferences
{
"always_prompt_for_file_reload": true,
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_extra_top": 5,
"caret_extra_width": 2,
"caret_style": "blink",
"color_scheme": "Packages/User/Monokai (SL).tmTheme",
"draw_minimap_border": true,
"fade_fold_buttons": false,
@mikedugan
mikedugan / wpfinder.sh
Created February 7, 2014 20:32
bash script to find WordPress installations and version numbers
#! /bin/bash
for f in */
do
if [ -f $f/httpdocs/wp-includes/version.php ]; then
g=$(grep wp_version $f/httpdocs/wp-includes/version.php | tail -1)
echo $f - $g
elif [ -f $f/webshare/wp-includes/version.php ]; then
g=$(grep wp_version $f/webshare/wp-includes/version.php | tail -1)
echo $f - $g
@mikedugan
mikedugan / randomstring.php
Last active August 29, 2015 13:55
random string
/*
* @param $chars ALPHA | NUM | ALPHANUM | HEX | string
* @param $length number
* @return $rstring
*/
public function GetRandomString($chars, $length)
{
switch ($chars) {
case "ALPHA":
$chars = "abcdefghijklmnopqrstuvwxyz";
@mikedugan
mikedugan / rot13.cs
Created January 4, 2014 00:44
the rot13 is essentially the caesar transform applied with an offset of 13
static class Rot13
{
/// <summary>
/// Performs the ROT13 character rotation.
/// </summary>
public static string Transform(string value)
{
char[] array = value.ToCharArray();
for (int i = 0; i < array.Length; i++)
{