Skip to content

Instantly share code, notes, and snippets.

View bubble_sort.js
//Bubble Sort in Javascript
var data = [23,87,21,3,9,11,98,45,31];
for(var i=0; i< data.length; i++){
//Last i digits already sorted
for(var j = 0; j < (data.length - i - 1); j++){
if(data[j+1] < data[j]){
View reverse_number.js
//Reverse integer number without loop in Javascript
var num = 34562;
var reversed = 0;
while(num > 1){
var last_digit = num % 10;
reversed = reversed * 10 + last_digit;
num = parseInt(num/10);
}
@chetans9
chetans9 / SecureHeadersMiddleware.php
Last active Dec 10, 2020
Laravel Secure Headers Middleware
View SecureHeadersMiddleware.php
<?php
namespace App\Http\Middleware;
use Closure;
class SecureHeadersMiddleware
{
// Enumerate headers which you do not want in your application's responses.
// Great starting point would be to go check out @Scott_Helme's:
// https://securityheaders.com/
@chetans9
chetans9 / .htaccess
Created Jul 17, 2018
laravel htacces to remove public
View .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
@chetans9
chetans9 / gist:dda7add3d23c4d42c530eeb37cac0b95
Created Nov 28, 2017
Laravel Export Database to Excel sheet
View gist:dda7add3d23c4d42c530eeb37cac0b95
$users = new User;
$usersArray = $users->select("col1",'col2','col3')
->where('life_member','1')->get()->toArray();
$storage_path = public_path().'/files';
$curr_date = Carbon::now();
Excel::create('export_life_members',function ($excel) use($usersArray,$curr_date){
// Set the title
$excel->setTitle("Exported Life Members on $curr_date");
@chetans9
chetans9 / select2_remote_configuration.txt
Created Nov 12, 2017
Select2 Remote configuration for dropdown suggestion
View select2_remote_configuration.txt
//JS side Configuration
$("#user_emails").select2({
ajax: {
url:"/api/yourown",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
@chetans9
chetans9 / laravel_validation_errors.blade.php
Last active Oct 9, 2017
laravel Validation errors global include file
View laravel_validation_errors.blade.php
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@chetans9
chetans9 / gist:5c1b887541a96e61481b23e609bc7e12
Created Sep 1, 2017
Script to change Collation of your Database to utf8_general_ci
View gist:5c1b887541a96e61481b23e609bc7e12
<!DOCTYPE html>
<html>
<head>
<title>DB-Convert</title>
<style>
body { font-family:"Courier New", Courier, monospace;" }
</style>
</head>
<body>