Skip to content

Instantly share code, notes, and snippets.

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

Bishwanath Jha bishwanathjha

🏠
Working from home
View GitHub Profile
@bishwanathjha
bishwanathjha / SupportsCertificateRotationWithoutRestartFlag.txt
Last active April 4, 2024 09:36
Parse the output of aws describe-db-engine-versions and display SupportsCertificateRotationWithoutRestart flag per engine version
// Modify the DB instance or Multi-AZ DB cluster to change the CA from rds-ca-2019 to rds-ca-rsa2048-g1 or others.
// To check if your database requires a restart to update the CA certificates,
// use the describe-db-engine-versions command and check the SupportsCertificateRotationWithoutRestart flag.
// Below command parse the output from describe-db-engine-versions and print line per engine version with SupportsCertificateRotationWithoutRestart flag
// Change the "aurora-mysql" and "eu-central-1" according to your use case
// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL-certificate-rotation.html#UsingWithRDS.SSL-certificate-rotation-updating
aws rds describe-db-engine-versions \
@bishwanathjha
bishwanathjha / flatten.php
Created May 30, 2021 17:01
PRAMP Flatten a Dictionary in PHP
<?php
$list = [];
function flatten($array) {
global $list;
foreach ($array as $key => $value) {
utility($value, $key);
}
return $list;
@bishwanathjha
bishwanathjha / compress-pdf-with-gs.md
Created March 10, 2021 04:08 — forked from guifromrio/compress-pdf-with-gs.md
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
@bishwanathjha
bishwanathjha / create_requests_zendesk_api.php
Created June 10, 2020 07:39
Create request/ticket on zendesk using API sample request
<?php
# To enable anonymous requests on zendesk so that you can create new request using API:
# - Sign in to Support and go to the Customers page (Admin > Settings > Customers).
# - Enable "Anyone can submit tickets".
# - Disable "Ask users to register".
$data = '{
"request": {
"requester": {
@bishwanathjha
bishwanathjha / moodle_query_get_attendance_studentwise_coursewise.sql
Last active May 1, 2020 21:30
Moodle Query to get Attendance Student wise Course Wise
-- Moodle get student wise attendence for each courses
-- To filter data you can put the parent course id and start {start_date_epoch} and end {end_date_epoch} in where clause
select
l.id as logid,
c.fullname as course,
CONCAT(FROM_UNIXTIME(s.sessdate,"%d %b, %Y %h:%i %p"), ' - ', FROM_UNIXTIME(s.sessdate + s.duration ,"%h:%i %p")) as session_title,
-- s.description as session_desc,
u.id as student_id,
u.username,
u.firstname as first_name,
@bishwanathjha
bishwanathjha / sqldump_remove_insert_tables
Last active October 11, 2021 06:05
Remove large insert statements from mysql dump file
# I am going to remove the activies insert from sql file because that huge aroudn 500MB
# Below command will create a new sql file by removing the activities insert query
sed '/INSERT INTO `activities`/d;/INSERT INTO `reconciliation_statement`/d;/INSERT INTO `activity_actions`/d' mydb.sql > reduced.sql
@bishwanathjha
bishwanathjha / mysql_database_backup_bash_script.sh
Created December 3, 2019 10:16
Bash script to backup mysql database, upload backup to aws s3 and notify on slack
#!/bin/bash
# Database credentials
user="db_user"
password="db_password"
host="127.0.0.1"
db="database"
prefix="db"
# Other options
backup_path="/home/ec2-user"
@bishwanathjha
bishwanathjha / tmux.conf
Created November 15, 2017 17:30 — forked from spicycode/tmux.conf
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@bishwanathjha
bishwanathjha / prime_number_list.php
Last active October 27, 2016 08:41
List all the prime numbers less than or equal to a given integer n in PHP
<?php
/**
* @author Bishwanath Jha <bishwanathkj@gmail.com>
* Give the nth number as input and it will return all prime numbers less than or equal to that number
*/
function GetPrimeNumberList($num) {
if ($num == 1) {
return $num;
}
@bishwanathjha
bishwanathjha / contiguous_subarray_sum.php
Created October 23, 2016 15:28
Largest Sum Contiguous Subarray in PHP
<?php
/**
* @author Bishwanath Jha <bishwanathkj@gmail.com>
* Largest Sum Contiguous Subarray
*/
function GetMaxSum($array) {
$total = $max_total = 0;
$count = count($array);
for($i = 0; $i < $count; $i++) {
$total += $array[$i];