Skip to content

Instantly share code, notes, and snippets.

@graymic
graymic / Array String Pos
Created March 24, 2014 14:38
Allows for multiple delimiters in a string pos function.
$str_pos_array = function ($haystack, $needles=[], $offset=0) {
$characters = [];
foreach($needles as $needle) {
$res = strpos($haystack, $needle, $offset);
if ($res !== false) {
$characters[$needle] = $res;
}
@graymic
graymic / domSelector.js
Last active August 29, 2015 13:59
JQuery based dom selector part 1.
(function (){
var newcss = ".mouseOn{background-color: #bcd5eb !important;outline: 2px solid #5166bb !important;}";
if ('\v'=='v') /* ie only */ {
document.createStyleSheet().cssText = newcss;
} else {
var tag = document.createElement('style');
tag.type = 'text/css'; document.getElementsByTagName('head')[0].appendChild(tag);
tag[ (typeof document.body.style.WebkitAppearance=='string') /* webkit only */ ? 'innerText' : 'innerHTML'] = newcss;
}
@graymic
graymic / post-receive.sh
Created June 4, 2014 09:33
The purpose of this script is to allow Atlassian Stash to send post-receive hooks to PHPCI
#!/bin/bash
# Author: Michael Gray
# Description: The purpose of this script is to allow Atlassian Stash to send post-receive hooks to PHPCI
# using the external post-receive POST hook request.
# Email: hello@graymic.co.uk
(
PROJECT_ID=$1
PHPCI_URL="http://path.to.ci.server.com"
echo "Script name: $0"
echo "Positional arguments: ${@}"
@graymic
graymic / install_git.sh
Created June 10, 2014 15:53
Installs Git 1.8.3.4
#!/bin/bash
wget http://git-core.googlecode.com/files/git-1.8.3.4.tar.gz
wget -O git-manpages-1.8.3.4.tar.gz http://code.google.com/p/git-core/downloads/detail?name=git-manpages-1.8.3.4.tar.gz&can=2&q=
sudo yum install zlib-devel perl-CPAN gettext
tar xvfz git-1.8.3.4.tar.gz
cd git-1.8.3.4
./configure
@graymic
graymic / php_mamp_bin_export
Last active August 29, 2015 14:05
Setting PHP to MAMP binaries
echo "export PATH=/Applications/MAMP/bin/php/php5.*.*/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile
@graymic
graymic / deploy.sh
Last active August 29, 2015 14:06
Capistrano Deploy Shell
#!/usr/bin/env bash
command -v gem >/dev/null 2>&1 || { echo >&2 "Gem not installed, exiting."; exit 1; }
command -v cap >/dev/null 2>&1 || {
echo >&2 "Capistrano is required for deployments. Installing capistrano now...";
gem install capistrano
}
if [ ! -d ".deploy" ]; then
echo ".deploy directory has not been setup. Please run the cap installer."
@graymic
graymic / Gulpfile.js
Last active August 29, 2015 14:07
Example Gulpfile - Foundation5, SASS, Laravel5
var gulp = require('gulp'),
sass = require('gulp-sass'),
minify = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
notify = require('gulp-notify'),
growl = require('gulp-notify-growl'),
phpunit = require('gulp-phpunit'),
prefix = require('gulp-autoprefixer'),
@graymic
graymic / environment.php
Last active September 25, 2015 09:48
environments - dotenv Laravel5
<?php
// You can ofc ignore this and load it in from the default .env file, however I prefer this method for load dot files.
// Dotenv::load(__DIR__.'/../');
// Dotenv::require('APP_ENV');
$dotenv = function () {
$env = getenv('APP_ENV') ?: 'local';
if (file_exists(__DIR__.'/../')) {
Dotenv::load(__DIR__.'/../', '.env.' . $env);
}
@graymic
graymic / EloquentRepository.php
Created October 23, 2014 15:30
Laravel 4 Eloquent Repository Abstract
<?php namespace app\Acme\Repositories;
/**
* Class EloquentRepository
* @package app\Acme\Repositories
*/
abstract class EloquentRepository {
/**
* @var $model \Eloquent;
@graymic
graymic / PolymorphicModelNamespaces.php
Last active August 29, 2015 14:09
Polymorphic Model Namespaces
<?php Some\Extended\Models\Namespace;
class MyBespokeModel extends Some\Other\Parent\Namespace\Model {
/**
* As this class is \App\Api\Models - Map the polymorphic relationship to this model
* so that it can be accessed either by Common\Models or Api\Models.
*
* @var string
*/