Skip to content

Instantly share code, notes, and snippets.

View jaydeepakbari's full-sized avatar
🏠
Working from home

Jaydeep Akbari jaydeepakbari

🏠
Working from home
View GitHub Profile
<?php
/**
* Takes in a filename and an array associative data array and outputs a csv file
* @param string $fileName
* @param array $assocDataArray
*/
public function outputCsv($fileName, $assocDataArray)
{
ob_clean();
@jaydeepakbari
jaydeepakbari / format_uri.php
Last active November 14, 2018 09:34
Generate SEO friendly URLs (slugs) Using PHP
<?php
function format_uri( $string, $separator = '-' )
{
$accents_regex = '~&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i';
$special_cases = array( '&' => 'and', "'" => '');
$string = mb_strtolower( trim( $string ), 'UTF-8' );
$string = str_replace( array_keys($special_cases), array_values( $special_cases), $string );
$string = preg_replace( $accents_regex, '$1', htmlentities( $string, ENT_QUOTES, 'UTF-8' ) );
$string = preg_replace("/[^a-z0-9]/u", "$separator", $string);
@jaydeepakbari
jaydeepakbari / button.js
Created August 12, 2018 04:53
Button loading jquery Plugin
(function ($) {
$.fn.button = function (action) {
var self = $(this);
if (action == 'loading') {
if ($(self).attr("disabled") == "disabled") {
e.preventDefault();
}
$(self).attr("disabled", "disabled");
$(self).attr('data-btn-text', $(self).html());
$(self).html('<i class="fa fa-spinner fa-spin"></i>' + $(self).text());
@jaydeepakbari
jaydeepakbari / node_encript_password_example.js
Last active June 29, 2018 10:02
Example of using bcrypt with mongoose to encript password with bcrypt
var mongoose = require('mongoose'),Schema = mongoose.Schema;
var bcrypt = require('bcrypt');
var salt = bcrypt.genSaltSync(10);
var enc_password = password = bcrypt.hashSync(req.body.password, salt);
@jaydeepakbari
jaydeepakbari / .htaccess
Last active April 16, 2018 04:58
Laravel : Simple .htaccess using mod_rewrite for Laravel
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]