Skip to content

Instantly share code, notes, and snippets.

View thewinterwind's full-sized avatar

Anthony Vipond thewinterwind

View GitHub Profile
@thewinterwind
thewinterwind / slider-switch.js
Last active December 25, 2015 18:49
Adding dynamic functionality to Bootstrap 3 slider switches
// 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 / bootstrap3_validation.js
Last active December 25, 2015 06:29
Input and Textarea Validation in Twitter Bootstrap 3 (author: Anthony Vipond)
/**
* 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 / demo.php
Created December 1, 2014 10:01
Get next id in table using Laravel
<?php
// select min(id) as id from `property` where `id` > 1;
DB::table($table)->select(DB::raw('min(id) as id'))->where('id', '>', $id)->id;
@thewinterwind
thewinterwind / art.php
Last active August 29, 2015 14:02
Artisan Files for Streak Counting Tutorial (2 files combined here)
// this is /app/start/artisan.php
<?php
/*
|--------------------------------------------------------------------------
| Register The Artisan Commands
|--------------------------------------------------------------------------
|
| Each available Artisan command must be registered with the console so
<?php
use Leads\Repos\LeadRepoInterface;
use Illuminate\Foundation\Application;
class ExchangeController extends BaseController {
private $lead;
private $app;
@thewinterwind
thewinterwind / add-primary-key-to-existing-table.sql
Created May 8, 2014 09:10
Add primary key after table already exists (MySQL)
ALTER TABLE XXX add column id INT NOT NULL AUTO_INCREMENT FIRST, ADD primary KEY Id(id)
@thewinterwind
thewinterwind / remove-duplicate-rows-from-mysql-table.sql
Last active August 29, 2015 14:01
How to remove duplicate rows from a MySQL table
-- For example, a members table that has duplicate emails
-- Needs unique id field to work
create temporary table tmpTable (id int);
insert tmpTable
(id)
select id
from members m
where exists
@thewinterwind
thewinterwind / log_laravel_db_queries_to_console.php
Created May 4, 2014 05:59
Log Laravel 4 Database Queries to the Console
@if (App::environment() == 'local')
@foreach (DB::getQueryLog() as $query)
<script>console.log(' {{ $query['query'] . ' (' . $query['time'] . ' secs)' }} ')</script>
@endforeach
@endif
@thewinterwind
thewinterwind / php-snippets.xml
Last active August 29, 2015 13:58
Sublime Text 2 Laravel 4 Snippet Collection
<overview>
pf = new function
comm = new function comment
fopen = open a form
fclose = close a form
</overview>
<snippet>
<content>
<![CDATA[
@thewinterwind
thewinterwind / helpers.php
Created March 28, 2014 22:18
Laravel 4 Helpers
<?php
/**
* Helpers for Laravel 4
* Author: Anthony Vipond
*/
// Preformat the dump and die function
if (!function_exists('d')) {
function d($mixed) {