Skip to content

Instantly share code, notes, and snippets.

View demirtasdurmus's full-sized avatar
🏠
Working from home

Durmuş Demirtaş demirtasdurmus

🏠
Working from home
View GitHub Profile
@demirtasdurmus
demirtasdurmus / to-jsonb.ts
Last active September 28, 2024 12:14
Custom jsonb wrapper for Drizzle ORM when used with Postgresql
import { SQL, sql } from 'drizzle-orm';
/**
* Converts a raw object or array to a jsonb object for postgres
*
* @export
* @template T
* @param {(T | T[])} raw
* @return {*} {SQL<unknown>}
*
@demirtasdurmus
demirtasdurmus / delete-all-local-branches-except.sh
Last active July 31, 2023 10:57
A shell script to delete all local git branches except the one specified while calling it. It also checks if there are any unpushed changes and prompts user to choose the appropriate action including either aborting the operation or pushing the changes
#! /bin/bash
# declare colors
Red=$'\e[1;31m'
Green=$'\e[1;32m'
Blue=$'\e[1;34m'
Yellow=$'\e[1;33m'
# exit when any command fails
set -e
const { exec } = require('child_process');
const CronJob = require('cron').CronJob;
// scheduling the backup job
var job = new CronJob('59 23 * * *',
function () {
console.log('-------Running cron job-------');
backupDatabase();
},
null,
true
#!/bin/bash
PGPASSWORD=${1} pg_dump -h ${2} -U ${3} -p ${4} -Fc -d ${5} > ${6}
const backupDatabase = () => {
// extract credentials from .env
const dbName = process.env.DB_NAME;
const dbPass = process.env.DB_PASS;
const dbHost = process.env.DB_HOST;
const dbUser = process.env.DB_USER;
const dbPort = process.env.DB_PORT;
const format = "backup"; // sql/backup/dump
// create a custom backup file name with date info
const date = new Date();
// automated-backups/index.js
const dotenv = require('dotenv');
dotenv.config();
const express = require('express');
const app = express();
const { exec } = require('child_process');
// execute node child process(exec)
exec(`sh ./backup.sh`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
#!/bin/bash
PGPASSWORD=mysupersecret pg_dump -h localhost -U postgres -p 5432 -Fc -d sampledb >
/Users/<username>/<path_to_dir>/sample.backup
#!/bin/bash
echo "I can run sh scripts"