Skip to content

Instantly share code, notes, and snippets.

View arvindkumarbadwal's full-sized avatar

Arvindkumar Badwal arvindkumarbadwal

  • India
View GitHub Profile
@arvindkumarbadwal
arvindkumarbadwal / Postgres Command
Last active March 3, 2022 07:44
Postgres Command to Dump or Restore File in Docker without Owner & Privileges
--
-- Dump a PostgreSQL database into a file
-- container_name - PostgreSQL container name
-- db_user - user name to connect as.
-- db_name - name of the database to be dumped
-- -O - no-owner
-- -x - no-privileges
--
docker exec -i [container_name] pg_dump --username [db_user] [db_name] -O -x > dump.sql
@arvindkumarbadwal
arvindkumarbadwal / Fixing Postgres Sequences For Tables
Last active July 27, 2021 12:04
Updating postgres sequence values from table
Step 1:
/* Create queries to set the sequences of the table with max of the table */
SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
FROM pg_class AS S,
pg_depend AS D,
pg_class AS T,
pg_attribute AS C,
@arvindkumarbadwal
arvindkumarbadwal / StorageCopy.php
Last active July 14, 2020 10:15
Laravel Storage File Copy From Public Disk To S3 Disk
<?php
/**
* Logic to copy public files to s3
*/
$sourceFiles = \Storage::disk('public')->allFiles();
$destinationFiles = \Storage::disk('s3')->allFiles();
foreach ($sourceFiles as $file) {
if (!in_array($file, $destinationFiles)) {
@arvindkumarbadwal
arvindkumarbadwal / calculate_distance.sql
Created May 31, 2020 14:53
Postgres Routine to calculates distance between two points (latitude/longitude)
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :*/
/*:: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :*/
/*:: unit = the unit you desire for results :*/
/*:: where: 'M' is statute miles (default) :*/
/*:: 'K' is kilometers :*/
/*:: 'N' is nautical miles :*/
/*:: :*/
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
@arvindkumarbadwal
arvindkumarbadwal / axios-refresh-token.js
Created May 22, 2020 14:22
Axios interceptors for token refreshing with multipe async api support
import axios from 'axios';
import { Auth } from '.';
let isRefreshing = false;
let refreshSubscribers = [];
axios.interceptors.response.use(response => {
return response;
}, error => {
const originalReq = error.config;
@arvindkumarbadwal
arvindkumarbadwal / axios.js
Created May 15, 2020 13:58
Axios SSL Certificate Pinning
const tls = require('tls');
const https = require('https');
const crypto = require('crypto');
const axios = require('axios');
function sha256(s) {
return crypto.createHash('sha256').update(s).digest('base64');
}
const options = {
@arvindkumarbadwal
arvindkumarbadwal / .phpcsfixer
Created May 12, 2020 09:49
Laravel - PHP CS Fixer Config
<?php
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'array_indentation' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
@arvindkumarbadwal
arvindkumarbadwal / ec2tos3.sh
Created May 12, 2020 09:45
Syncing files from EC2 instance to S3 bucket
#!/bin/bash
#source directory path
backup_path=/var/www/application/uploads
#destination s3 bucketname
bucket_name=uploads
echo "Sync Process Start ::" $(date)