Skip to content

Instantly share code, notes, and snippets.

//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]){
//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 August 11, 2024 09:27
Laravel Secure Headers Middleware
<?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 July 17, 2018 05:59
laravel htacces to remove public
<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 November 28, 2017 06:12
Laravel Export Database to Excel sheet
$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 November 12, 2017 11:45
Select2 Remote configuration for dropdown suggestion
//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 October 9, 2017 17:44
laravel Validation errors global include file
@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 September 1, 2017 17:11
Script to change Collation of your Database to utf8_general_ci
<!DOCTYPE html>
<html>
<head>
<title>DB-Convert</title>
<style>
body { font-family:"Courier New", Courier, monospace;" }
</style>
</head>
<body>