Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Taking new clients now

Anthony Vipond thewinterwind

💭
Taking new clients now
View GitHub Profile
@thewinterwind
thewinterwind / bootstrap3_validation.js
Last active Dec 25, 2015
Input and Textarea Validation in Twitter Bootstrap 3 (author: Anthony Vipond)
View bootstrap3_validation.js
/**
* Construct feedback html for blur event on inputs and textareas
* @param {String} icon_msg
* @param {String} icon_class
* @return {String} html
*/
function get_feedback_html(icon_msg, icon_class) {
var html =
'<span class="alert-msg"><i class="' + icon_class + '">' + icon_msg + '</i></span>';
return html;
@thewinterwind
thewinterwind / validate_url.js
Created Oct 17, 2013
Validating a URL with Javascript
View validate_url.js
// I didn't write this function, only modified it slightly. It works well though!
function valid_url(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
@thewinterwind
thewinterwind / slider-switch.js
Last active Dec 25, 2015
Adding dynamic functionality to Bootstrap 3 slider switches
View slider-switch.js
// Note! Use a radio button for this, not a checkbox!
// You need to check your database to find out the switch value
// e.g. <?php $switch_val = DB::only("SELECT switch FROM table WHERE user_id = $user_id"); ?>
// In your view/HTML
<script>
var switch = !!Number('<?php echo $switch_val ?>');
switch ? $('.slider-button').addClass('on') : $('.slider-button').removeClass('on');
@thewinterwind
thewinterwind / NumberInputHelper.blade.php.js
Last active Dec 25, 2015
HTML5 Number input helper for Laravel 4 Blade Templates with supporting Javascript
View NumberInputHelper.blade.php.js
{{ Form::label('quantity', 'Quantity') }}
{{ Form::input('number', 'quantity', 0, array('class' => 'form-control required quantity', 'data-toggle' => 'tooltip', 'data-trigger' => 'focus', 'data-placement' => 'top', 'title' => 'Enter how many tags you would like to create', 'min' => '0', 'max' => '10000', 'maxlength' => '5')) }}
@section('scripts')
<script>
var inputQuantity = [];
$(".quantity").each(function(i) {
inputQuantity[i]=this.defaultValue;
@thewinterwind
thewinterwind / grab_url_segment.js
Created Oct 23, 2013
Grab a URL segment and return it as a lowercase string, or with first character capitalized.
View grab_url_segment.js
/**
* Return the first url segment and capitalize if necessary
* @param {Boolean} flag if capitalization is needed or not
* @return {String} formatted URL segment
*/
function get_label(capitalize) {
var first_segment = window.location.pathname.split('/')[1];
if (capitalize) {
@thewinterwind
thewinterwind / check_if_integer.js
Last active Dec 26, 2015
Check if a number is an integer in Javascript using jQuery (author: Anthony Vipond)
View check_if_integer.js
/**
* Check if a number is an integer using jQuery
* @param {Number} num
* @return {Boolean}
*/
function is_integer(num) {
return $.isNumeric(num) && !(num % 1);
}
@thewinterwind
thewinterwind / .bash_profile
Created Nov 1, 2013
My ~/.bash_profile on Mac OS X Mountain Lion ***CODE FAST***
View .bash_profile
alias l='ls -lah'
alias b='cd ..'
alias bb='cd ../..'
alias bbb='cd ../../..'
alias ra='sudo apachectl restart'
alias sa='sudo apachectl start'
alias ka='sudo apachectl stop'
alias a-dir='cd /etc/apache2'
alias sites='cd ~/sites'
@thewinterwind
thewinterwind / update_query_string_value.html
Last active Dec 27, 2015
Update query string value with Javascript (author: Anthony Vipond)
View update_query_string_value.html
<select class="filter">
<option>Results Shown</option>
<option>20</option>
<option>30</option>
<option>50</option>
<option>100</option>
</select>
<script>
// This example is for a 'Results per page' dropdown
@thewinterwind
thewinterwind / queries_run.php
Created Nov 9, 2013
Helper function for viewing queries ran in Laravel 4
View queries_run.php
<?php
if (!function_exists('sql')) {
function sql($detailed = false) {
if ($detailed) {
Event::listen("illuminate.query", function($query, $bindings, $time, $name) {
$queries = DB::getQueryLog();
echo '<pre>';
foreach(end($queries) as $item) {
var_dump($item);
@thewinterwind
thewinterwind / convert-span-to-input-and-back.js
Created Nov 9, 2013
Convert span to text input for editing, then back to span upon successful save
View convert-span-to-input-and-back.js
// Icons with edit class will convert their data partner to an input
$('i.edit').click(function() {
var table = $(this).data('table');
var column = $(this).data('column');
var relation = $(this).data('relation');
var id = $(this).data('id');
var type = $(this).data('type');
var morph = $(this).data('morph');
var original_elem = $(this).siblings('span');
var original_text = original_elem.text();