Skip to content

Instantly share code, notes, and snippets.

View abhikhatri's full-sized avatar
💭
I may be slow to respond.

Abhi Khatri abhikhatri

💭
I may be slow to respond.
View GitHub Profile
@abhikhatri
abhikhatri / bash.sh
Created September 2, 2022 21:39 — forked from wikiti/bash.sh
Backup and restore in PostgreSQL using compressed backups.
# List databases
sudo su postgres
psql
\list
# Create a compressed backup
sudo su postgres
pg_dump -Fc <database_name> > <file>
# Example
@abhikhatri
abhikhatri / dump-restore
Created July 29, 2020 12:43 — forked from ricjcosme/dump-restore
DUMP / RESTORE PostgreSQL Kubernetes
DUMP
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
kubectl exec [pod-name] -- bash -c "pg_dump -U [postgres-user] [database-name]" > database.sql
RESTORE
// pod-name name of the postgres pod
// postgres-user database user that is able to access the database
// database-name name of the database
@abhikhatri
abhikhatri / deployUser.md
Created December 11, 2019 05:51 — forked from learncodeacademy/deployUser.md
Adding a deploy user in Linux

(wherever it says url.com, use your server's domain or IP)

Login to new server as root, then add a deploy user

sudo useradd --create-home -s /bin/bash deploy
sudo adduser deploy sudo
sudo passwd deploy

And Update the new password

@abhikhatri
abhikhatri / socketio-event-name.js
Created November 17, 2019 14:42
function to listen to all socket io events
var onevent = socket.onevent;
socket.onevent = function (packet) {
var args = packet.data || [];
onevent.call(this, packet);
console.log('packet', packet.data);
};
POSTGRES_USER=sonar
POSTGRES_PASSWORD=sonar
POSTGRES_DB=sonarqube
@abhikhatri
abhikhatri / ResolvePromise.js
Created March 26, 2019 13:43
Resolve promise from outside the scope
//Actual promise function that retuns a promise
function defer() {
var res, rej;
var promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
promise.resolve = res;
@abhikhatri
abhikhatri / boot.js
Created January 6, 2019 17:58
script to automatically populate the models on boot
'use strict';
module.exports = function(app) {
/*
* The `app` object provides access to a variety of LoopBack resources such as
* models (e.g. `app.models.YourModelName`) or data sources (e.g.
* `app.datasources.YourDataSource`). See
* https://loopback.io/doc/en/lb3/Working-with-LoopBack-objects.html
* for more info.
*/
@abhikhatri
abhikhatri / loopback-automigration
Created January 6, 2019 15:14
Loopback script to migrate tables for default tables boot/server.js. EOS
//Importing the db structure for default apps
var appModels = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
var ds = app.dataSources.postgres;
ds.isActual(appModels, function (err, actual) {
if (!actual) {
ds.autoupdate(appModels, function (err) {
if (err) throw (err);
});
}
@abhikhatri
abhikhatri / Snapshot Delete
Last active November 13, 2018 08:18
Rough Snippet to delete snap in firebase
ref.orderByChild('key').equalTo('something').once('value')
.then(function (snap) {
snap.forEach(function (snap) {
if (item.key === '-LTRAB3DKkK4FC765') {
snap.remove();
}
});
});
@abhikhatri
abhikhatri / VsCode-List-Extensions
Created October 17, 2018 06:22
command to list all the extensions to install in other machine
code --list-extensions | xargs -L 1 echo code --install-extension