Skip to content

Instantly share code, notes, and snippets.

View acodesmith's full-sized avatar
💯

Adam Smith acodesmith

💯
View GitHub Profile
@acodesmith
acodesmith / block-subs-from-wp-admin.php
Created April 10, 2015 17:34
Block Subscribers from wp-admin
function block_subs_func(){
//checks for permission
if ( ! current_user_can( 'edit_posts' ) ){
wp_redirect( site_url() );
exit;
}
} add_action('admin_init', 'block_subs_func');
@acodesmith
acodesmith / user-sub-pub.js
Created March 26, 2015 20:18
SailsJS simple sockets.io sub/pub functions for front-end javascript.
io.socket.get('/user', {}, function(users){
console.log(users);
});
io.socket.on('user', function(message){
console.log('Got Message', message);
});
@acodesmith
acodesmith / jquery.formDataObject.js
Created March 3, 2015 02:45
HTML Form to Javascript Object
$.fn.formDataObject = function()
{
if(this.is('form')){
var data = {};
for(var i = 0; i < this.serializeArray().length; i++){
var input = this.serializeArray()[i];
if(!$.isEmptyObject(input)){
@acodesmith
acodesmith / jquery.vmap.canada.js
Last active August 29, 2015 14:15
jQuery Vector Maps - Canada
/** Add Canada Map Data Points */
jQuery.fn.vectorMap('addMap', 'canada_en', {
"width": 959,
"height": 593,
"pathes": {
"bc": {
"path": "M115.002022,492.434845C114.55525999999999,492.304596,104.467079,489.16922,96.636406,486.72699C93.93566899999999,485.884613,65.318649,475.155854,53.53839899999999,470.56906200000003C51.518176999999994,469.78247100000004,49.20412499999999,468.896973,48.39602299999999,468.60135C46.52484499999999,467.91678,46.20882799999999,467.42154000000005,46.19961899999999,465.15857C46.19448099999999,463.891328,45.87146699999999,463.051514,45.163504999999994,462.464936C42.316534999999995,460.105988,41.29464999999999,458.923493,41.29464999999999,457.98791600000004C41.29464999999999,457.422608,41.10435799999999,456.96002300000004,40.87167599999999,456.96002300000004C39.68412999999999,456.96002300000004,37.971918999999986,454.35577500000005,37.671739999999986,452.09274400000004C37.185518999999985,448.42761300000006,35.55198499999999,445.23871,32.66095199999999,44
@acodesmith
acodesmith / mapModelToModal.php
Last active August 29, 2015 14:15
Map one model's values to another model. Yii 1
/**
* Map any model attribute to another model attribute
* AR hasAttribute() required vs property_exist()
* @param $model1
* @param $model2
* @param $map array('id'=>'sku') The sku of the second model would map to the id of the first model
* @return array
*/
function mapModelToModel($model1, $model2, $map) {
foreach ($map as $attr1 => $attr2) {
@acodesmith
acodesmith / yii-cgridview.scss
Created January 28, 2015 00:04
Yii 1 CGridView SCSS Template
.grid-view {
.summary {
}
.items {
thead {
@acodesmith
acodesmith / float-breakpoints.scss
Created December 18, 2014 16:27
Twitter Bootstrap Floats based on Media Query Breakpoints
/**
Reference ONLY! Variables should be included elsewhere.
$small-lower:'767px';
$medium-lower:'991px';
$large-lower:'1199px';
**/
/**
Floats Based on BreakPoints
**/
@acodesmith
acodesmith / text-align-by-media.scss
Created November 25, 2014 04:33
Twitter Bootstrap text align based on media break points
/**
Reference ONLY! Variables should be included elsewhere.
$small-lower:'767px';
$medium-lower:'991px';
$large-lower:'1199px';
**/
/**
Build Alignment Based on Breakpoints
**/
@acodesmith
acodesmith / gist:93d8d95388be404852a1
Created November 24, 2014 17:55
renderPartial every file in a certain view folder
<?php
//View Location to auto load all .php files
$viewLocation = 'admin/variantRules/options';
//PHP glob function will return array. If there is an error double check your path
foreach (glob( Yii::app()->basePath."/views/".$viewLocation."/*.php") as $filename)
{
//Render every partial and load data
$this->renderPartial('//'.$viewLocation.'/'. str_replace('.php', '', array_pop( explode('/',$filename) ) ), array() );
}
@acodesmith
acodesmith / camelCaseToReadable.php
Last active August 29, 2015 14:10
Convert a camel case string to a readable string.
<?=ucwords( implode(' ', preg_split('/(?=[A-Z])/',$str) ) ); ?>