Skip to content

Instantly share code, notes, and snippets.

View bewithdhanu's full-sized avatar
😜
Focusing

Dhanu K bewithdhanu

😜
Focusing
View GitHub Profile
@bewithdhanu
bewithdhanu / laravel_postgres_setup.gist
Last active October 13, 2022 14:38
Laravel & PostgreSQL Setup on Windows
# Laravel & PostgreSQL Setup on Windows
- Apache & PHP - Can be installed with XAMPP
- https://ngonyoku.medium.com/how-to-install-xampp-a47f0787d9b6
- Composer
- https://medium.com/@importantcoding/installing-composer-in-windows-10-8584c69bdb8e
- PostgreSQL
- With Installer: https://freegistutorial.com/how-to-install-postgis-on-windows-10/
- With Docker Compose (Docker has to be installed first): https://github.com/bewithdhanu/PostgreSQL-with-PostGIS
- Laravel
- https://dev.to/shanisingh03/how-to-install-laravel-9-25c4
// routes/api.php
Route::post('get/user/chat', [UserController::class, 'getChatOfUser']);
Route::post('chat/send/message', [UserController::class, 'sendMessage']);
Route::get('chat/list', [UserController::class, 'getChatUsers']);
// Migration
<?php
@bewithdhanu
bewithdhanu / Laravel - Prevent SQL Injection attacks with global change.md
Last active February 26, 2025 19:13
Laravel - Prevent SQL Injection attacks with global change

Laravel - Prevent SQL Injection Attacks - Global Change

Create a Middle called PreventSQLInjection.php

This code basically takes in a request and add escape quotes to the input data, thus data passing to controllers will be filtered and incase of base64 encoded data coming as input we are avoiding that to be filtered

Registering your Middleware

When registering your middleware you have 3 choices.

@bewithdhanu
bewithdhanu / S3 File upload Kotlin.md
Created January 11, 2023 13:42
S3 File upload Kotlin using Amazon STS temporary credentials
private fun doFileTransfer(file: File) {

        val mCredentials = BasicSessionCredentials(YOUR_ACCESS_KEY, YOUR_SECRET_KEY, YOUR_SECRET_TOKEN)
        val s3: AmazonS3 = AmazonS3Client(mCredentials)
        s3.setRegion(Region.getRegion(Regions.US_EAST_2))
        mTransferUtility = TransferUtility.builder().s3Client(s3).context(mApplication).build()
        val objectKey = "android/${file.nameWithoutExtension}.${file.extension}";
        val access = CannedAccessControlList.Private
@bewithdhanu
bewithdhanu / AlarmActivity.kt
Last active January 12, 2023 11:47
Android check for bluetooth devices using alarm manager
package com.test.uploadtos3
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import java.util.*
class AlarmActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@bewithdhanu
bewithdhanu / Best Practices for Running Cron Jobs in Apache.md
Last active March 17, 2023 09:57
Best Practices for Running Cron Jobs in Apache

Best Practices for Running Cron Jobs in Apache

Cron jobs are a powerful tool for automating routine tasks in your web application. However, if you're running your application with Apache, it's important to ensure that your cron jobs are running under the correct user to avoid issues with file permissions.

By default, the crontab command works on a user level, meaning that any jobs created using crontab -e will be executed under the user that created them (e.g., ubuntu or root). If you're running a web application with Apache, it's likely that the user that Apache runs under is www-data. This means that if you create a cron job under ubuntu or root, the files created by that job may not have the correct permissions for Apache to access them, resulting in errors like "Permission denied".

To avoid this issue, it's best to create a cron job under the www-data user using the command sudo crontab -u www-data -e. This ensures that the job is executed under the correct user, and any files create

@bewithdhanu
bewithdhanu / install telescope on laravel.md
Last active April 26, 2023 13:09
Installation Guide for telescope in Laravel

Installation Guide for telescope in laravel

Telescope is a powerful debugging tool for Laravel applications. It provides a beautiful interface for debugging and monitoring your application in real-time. With Telescope, you can easily find performance bottlenecks, track down errors, and debug your code more efficiently.

  1. Install Telescope using Composer:

    composer require laravel/telescope
@bewithdhanu
bewithdhanu / Cache_Eloquent_Queries_in_Laravel.md
Last active April 13, 2023 11:54
Cache Eloquent Queries and Models in Laravel

Laravel Eloquent Query Cache

Laravel Eloquent Query Cache is a package that provides caching for Eloquent queries.

Installation

To install this package, run the following command:

@bewithdhanu
bewithdhanu / Social_Media_Meta_Tags.md
Created April 13, 2023 11:54
Optimising Your Web Content for Social Media: A Guide to Using Meta Tags

Here are the meta tags you can use for various social media platforms:

Facebook

<meta property="og:url" content="https://example.com">
<meta property="og:type" content="website">
<meta property="og:title" content="My Page">
<meta property="og:description" content="This is a description of my page.">
@bewithdhanu
bewithdhanu / Setup_multiple_PHP_Versions_on_macOS.md
Last active April 24, 2023 09:57
Setup multiple PHP Versions on macOS

Setup multiple PHP Versions on macOS

XCode Command Line Tools

If you have not yet installed XCode, please install the XCode Command Line Tools. These are required for brew. Open your Terminal and run:

xcode-select --install

Brew