Skip to content

Instantly share code, notes, and snippets.

View atmd83's full-sized avatar

Andrew Markham-Davies atmd83

View GitHub Profile
@atmd83
atmd83 / menu.php
Last active December 29, 2015 17:39 — forked from oxyberg/menu.php
Function to return a class if the navigation menu is for the current url/child off in laravel 4
<?php
function menu ($url) {
if (preg_match ('#' . URL::to ($url) . '#', URL::current ())) return 'class="active"';
}
/*
* Usage
<a href="{{ URL::to ('store') }}"{{ menu ('store/*') }}>
*/
@atmd83
atmd83 / grunt-sass-watch.js
Last active January 4, 2016 02:59
Some js code for grunt to use sass and watch. just basic stuff
sass: {
dist: {
options: {
style: 'compressed'
},
files: {
'css/main.css': 'css/main.scss' // css to create : scss the css is created from
}
@atmd83
atmd83 / remove-dupes.js
Created February 3, 2014 10:35
Remove duplicates from javascript array
var myArray = [1, 2, 3, 1, 6, 3, 7, 2, 1];
myArray.filter(function(elem, pos, self) {
return self.indexOf(elem) == pos;
});
@atmd83
atmd83 / get.php
Created February 3, 2014 11:57
Get first/last chars of a string in php
$string = "This is my string";
$firstTwo = substr($string, 0, 2); // first 2 letters of $string
$lastTwo = substr($string, -2); // last 2 letters of $string
@atmd83
atmd83 / wordpress.gitignore
Last active August 29, 2015 13:56
Wordpress gitignore
# Ignores everything in wp-content except plugins and themes (this means uploads wont be checked in)
wp-content/*
!wp-content/plugins/
!wp-content/themes/
# Ignore everything in the "plugins" directory, except the plugins you declare
#Allows only plugins needed to make the site work to be stored in source control
@atmd83
atmd83 / confirmation.js
Created March 27, 2014 09:58
nice console.log styling for confirmation
console.info(
'%cSome content to log,
'background: #B3E8B4; color: #4A5249;font-weight:700;border-radius:2px;padding:1px 2px;border:1px solid #999;'
);
@atmd83
atmd83 / style.js
Created April 8, 2014 08:08
require.js module style guide
/*
* Mini style guide for require.js modules
* Dependencies should each have a new line, indented from the array literal (square brackets)
* having them on each line means its easy to see the number of dependencies you have.
* The function names (exposed by your dependencies) should also be declared on a new line,
* this makes it really easy to add new modules at a later time and its quick to check against
* your dependencies list.
* They should also be prefixed (i.e. $someModule) so that they are very easily identified as modules
* when used in your code. (Dependent on module size, this might not be required in smaller modules)
*/
"
" Plugin management via Vundle
" git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
"
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
@atmd83
atmd83 / style.js
Last active August 29, 2015 14:12
Javascript style guide
/* Javascript style guide
* Use jshint
* indent with tabs (that way people can adjust the spacing and retain alignment)
* blank lines and white space is a good thing and aids readability.
* code CAN have appropriate comments. When using sourcecontroll code shouldnt
* be commented out, implement or remove (YAGNI/DRY)
*
* N.B. These are just MY recomendations for readability, performance and maintainability.
* Ultimately consistancy is the main goal in a javascript style guide.
* ***************************************************************************************
@atmd83
atmd83 / whitelist.js
Created January 13, 2015 15:35
Checking a white list of supported browsers for javascript applications
(function (agent) {
var whiteList = { // example of a whitelist. browser name/version and a UA substring
"firefox31" : "Firefox/31.0",
"IE10" : "MSIE 10.0",
"chrome37" : "Chrome/37",
"chrome38" : "Chrome/38",
"chrome39" : "Chrome/39"
}, validBrowser = false;
for(var browser in whiteList){