Toggle class in jQuery

Written by: admin | Date: Friday, October 7th, 2016
Categories: jQuery

jQuery(document).on('click','.replyPost, .cancelPost', function(){
jQuery(this).toggleClass("cancelPost replyPost");
});


Laravel Database Column Types

Written by: admin | Date: Tuesday, September 27th, 2016
Categories: LaravelReference

Command Description
$table->bigIncrements('id'); Incrementing ID (primary key) using a “UNSIGNED BIG INTEGER” equivalent.
$table->bigInteger('votes'); BIGINT equivalent for the database.
$table->binary('data'); BLOB equivalent for the database.
$table->boolean('confirmed'); BOOLEAN equivalent for the database.
$table->char('name', 4); CHAR equivalent with a length.
$table->date('created_at'); DATE equivalent for the database.
$table->dateTime('created_at'); DATETIME equivalent for the database.
$table->dateTimeTz('created_at'); DATETIME (with timezone) equivalent for the database.
$table->decimal('amount', 5, 2); DECIMAL equivalent with a precision and scale.
$table->double('column', 15, 8); DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.
$table->enum('choices', ['foo', 'bar']); ENUM equivalent for the database.
$table->float('amount'); FLOAT equivalent for the database.
$table->increments('id'); Incrementing ID (primary key) using a “UNSIGNED INTEGER” equivalent.
$table->integer('votes'); INTEGER equivalent for the database.
$table->ipAddress('visitor'); IP address equivalent for the database.
$table->json('options'); JSON equivalent for the database.
$table->jsonb('options'); JSONB equivalent for the database.
$table->longText('description'); LONGTEXT equivalent for the database.
$table->macAddress('device'); MAC address equivalent for the database.
$table->mediumInteger('numbers'); MEDIUMINT equivalent for the database.
$table->mediumText('description'); MEDIUMTEXT equivalent for the database.
$table->morphs('taggable'); Adds INTEGER taggable_id and STRINGtaggable_type.
$table->nullableTimestamps(); Same as timestamps(), except allows NULLs.
$table->rememberToken(); Adds remember_token as VARCHAR(100) NULL.
$table->smallInteger('votes'); SMALLINT equivalent for the database.
$table->softDeletes(); Adds deleted_at column for soft deletes.
$table->string('email'); VARCHAR equivalent column.
$table->string('name', 100); VARCHAR equivalent with a length.
$table->text('description'); TEXT equivalent for the database.
$table->time('sunrise'); TIME equivalent for the database.
$table->timeTz('sunrise'); TIME (with timezone) equivalent for the database.
$table->tinyInteger('numbers'); TINYINT equivalent for the database.
$table->timestamp('added_on'); TIMESTAMP equivalent for the database.
$table->timestampTz('added_on'); TIMESTAMP (with timezone) equivalent for the database.
$table->timestamps(); Adds created_at and updated_at columns.
$table->uuid('id'); UUID equivalent for the database.

Frequently Used Laravel 5.2 Terminal Commands

Written by: admin | Date: Friday, July 1st, 2016
Categories: LaravelReference

Here I’m going to keep a list of my own frequently used Laravel 5.2 terminal commands. Every time I need to use one of these commands I end up googling and looking at several different sites to find the right command, and some are outdated. Here’s the list.

Use .htaccess to point http server root to Laravel’s public folder:

RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]

 

Setup an sqlite database
in terminal:
$ touch database/database.sqlite
in .env file:
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
(my mac setup: DB_DATABASE=/Users/my_user_name/Sites/my_project_folder/database/database.sqlite)

 

 

Clear view caches
php artisan view:clear

Clear cache
php artisan cache:clear

Make authorization views and scaffolding
php artisan make:auth

Create a new project called “blog” with the preferred distrubution of Laravel
composer create-project laravel/laravel tkcms –prefer-dist

Make a new model
php artisan make:model model-name

Make a new empty controller
php artisan make:controller MyController

Make a new controller with all standard methods
php artisan make:controller MyController –resource

Database

Create a table called create_users_table
php artisan make:migration create_users_table

GULP:

$ gulp //compiles sass
$ gulp watch //watches for changes and auto-compiles sass
$ control-c to stop gulp watch

Laravel Framework version 5.2.39

Usage:
command [options] [arguments]

Options:
-h, –help Display this help message
-q, –quiet Do not output any message
-V, –version Display this application version
–ansi Force ANSI output
–no-ansi Disable ANSI output
-n, –no-interaction Do not ask any interactive question
–env[=ENV] The environment the command should run under.
-v|vv|vvv, –verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
clear-compiled Remove the compiled class file
down Put the application into maintenance mode
env Display the current framework environment
help Displays help for a command
list Lists commands
migrate Run the database migrations
optimize Optimize the framework for better performance
serve Serve the application on the PHP development server
tinker Interact with your application
up Bring the application out of maintenance mode
app
app:name Set the application namespace
auth
auth:clear-resets Flush expired password reset tokens
cache
cache:clear Flush the application cache
cache:table Create a migration for the cache database table
config
config:cache Create a cache file for faster configuration loading
config:clear Remove the configuration cache file
db
db:seed Seed the database with records
event
event:generate Generate the missing events and listeners based on registration
key
key:generate Set the application key
make
make:auth Scaffold basic login and registration views and routes
make:console Create a new Artisan command
make:controller Create a new controller class
make:event Create a new event class
make:job Create a new job class
make:listener Create a new event listener class
make:middleware Create a new middleware class
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:policy Create a new policy class
make:provider Create a new service provider class
make:request Create a new form request class
make:seeder Create a new seeder class
make:test Create a new test class
migrate
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
queue
queue:failed List all of the failed queue jobs
queue:failed-table Create a migration for the failed queue jobs database table
queue:flush Flush all of the failed queue jobs
queue:forget Delete a failed queue job
queue:listen Listen to a given queue
queue:restart Restart queue worker daemons after their current job
queue:retry Retry a failed queue job
queue:table Create a migration for the queue jobs database table
queue:work Process the next job on a queue
route
route:cache Create a route cache file for faster route registration
route:clear Remove the route cache file
route:list List all registered routes
schedule
schedule:run Run the scheduled commands
session
session:table Create a migration for the session database table
vendor
vendor:publish Publish any publishable assets from vendor packages
view
view:clear Clear all compiled view files


Apache Start – Apache Stop – Apache Restart – Get Apache Version

Written by: admin | Date: Saturday, June 25th, 2016
Categories: ApacheReference

Start Apache
apachectl start

Stop Apache
apachectl stop

Graceful Stop
apachectl graceful-stop

Restart Apache
apachectl restart

Graceful restart
apachectl graceful

To find the Apache version
httpd -v


PHP illegal string offset warning

Written by: admin | Date: Tuesday, March 29th, 2016
Categories: JoomlaPHPReference

Ran across the PHP Joomla warning after upgrading one of my apps to Joomla 3.45:

Warning: Illegal string offset 'name' in

function golfLeagueShowFormats($formatObject){

$delimiter = ",";
$format_array = explode($delimiter, $formatObject);
foreach ($format_array as $format) {
$formatnumber = $format['name'];
golfLeagueGetFormatName($formatnumber);
//return 'poop';
}
}

It’s just a warning that only shows up in developer mode. Disabling developer mode would get rid of the warning but I decided to figure this out to make sure all the code was clean. Here’s the solution, to change $format[‘name’] to $format[0]


// convert format array to individual objects part 1
function golfLeagueShowFormats($formatObject){

$delimiter = ",";
$format_array = explode($delimiter, $formatObject);
foreach ($format_array as $format) {
$formatnumber = $format[0];
golfLeagueGetFormatName($formatnumber);
}
}


Put WordPress Widget Inside Post or Page Via Shortcode

Written by: admin | Date: Sunday, March 27th, 2016
Categories: ReferenceWordPress

Below WordPress function to show a widget via wordpress shortcode. You can use this to put a widget inside of a post, page, or even a widget.

function widget($atts) {
    global $wp_widget_factory;    
    extract(shortcode_atts(array(
        'widget_name' => FALSE
    ), $atts));
    $widget_name = esc_html($widget_name);
    if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
        $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
        if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
            return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
        else:
            $class = $wp_class;
        endif;
    endif;
    ob_start();
    the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => ''
    ));
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
add_shortcode('widget','widget'); 

In the post or page insert this shortcode:
[widget widget_name="widget_name"]


WordPress Bootstrap Nav Walker Strict Standards Warning

Written by: admin | Date: Saturday, March 26th, 2016
Categories: WordPress

After turning on WordPress Debug on one of my custom themes I noticed a strict standards waring regarding the Navwalker Bootstrap menu.

Error:

Strict Standards: Declaration of… start_lvl() should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = Array)

Fix:

change

function start_lvl(&$output, $depth) {

to

function start_lvl(&$output, $depth = 0, $args = array()) {