Skip to content

Instantly share code, notes, and snippets.

View acodesmith's full-sized avatar
💯

Adam Smith acodesmith

💯
View GitHub Profile
@acodesmith
acodesmith / hours_dropdown.php
Last active August 29, 2015 14:03
Select Dropdown for Hours in the day. Value is ready for string to time conversion.
<select>
<?php $first = false;
for($t = 12; $t<=23; $t++): ?>
<?php for($m = 0; $m<=45; $m+=15): ?>
<?php $m = $m == 0 ? sprintf("%02s", $m): $m; ?>
<option value="<?php echo ($t == 12 && !$first ? '00' : ($t < 10 ? '0'.$t : $t)).':'.$m.':00'; ?>">
<?php echo $t > 12 ? ($t-12 == 0 ? 12 : $t-12).':'.($m).' PM' : $t.':'.$m.' AM'; ?>
</option>
<?php endfor; ?>
<?php if($t == 12 && !$first){
@acodesmith
acodesmith / jquery-hide-update.js
Created August 20, 2014 13:41
Extend jQuery .show() function to play nice with Twitter Bootstrap hidden class.
/**
* Twitter Bootstrap .hidden class can cause unexpected results
* when interacting with the jQuery .show() function.
*
* Extend the native jQuery show functionality to remove
* the hidden class when .show() is called.
**/
(function($)
{
@acodesmith
acodesmith / shopify-display-search-by-item-type.liquid
Created October 30, 2014 20:15
Shopify Search Results - Display different results based on search item
<!-- PAGE RESULT -->
{% if item.url contains '/pages/' %}
<h1>PAGE</h1>
{% endif %}
<!-- BLOG RESULT -->
{% if item.url contains '/blogs/' %}
<h1>BLOG</h1>
{% endif %}
@acodesmith
acodesmith / yii_pagination_template.scss
Created November 19, 2014 20:53
SCSS Template for stying Yii 1.0 Pagination HTML
//Yii pagination
.pager {
.yiiPager {
li {
&.page {
}
@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) ) ); ?>
@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 / 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 / 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 / yii-cgridview.scss
Created January 28, 2015 00:04
Yii 1 CGridView SCSS Template
.grid-view {
.summary {
}
.items {
thead {
@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) {