Skip to content

Instantly share code, notes, and snippets.

View mudssrali's full-sized avatar
🕸️
Building software for better, at scale

Mudassar mudssrali

🕸️
Building software for better, at scale
View GitHub Profile
@mudssrali
mudssrali / upload.sh
Created February 2, 2023 12:26
Bash script to download a dir, zip it and upload to Google Cloud Storage using gsutil
#!/usr/bin/env bash
# make sure this bash script has executable permission, if doesn't have, run following command
# > $ chmod +x *.sh
gsutil - m cp - r "gs://[BUCKET_PATH]/$1". \
zip - r /root/ $1.zip $1 \
rm - rf $1 \
gsutil cp /root/ $1.zip gs://[BUCKET_PATH]/ \
rm -rf /root/$1.zip
@mudssrali
mudssrali / object-diff.ts
Last active January 21, 2023 09:43
Deep difference between two object, using lodash
//@ts-nocheck
import { isEqual, isObject, transform } from 'lodash'
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
@mudssrali
mudssrali / pdf-to-csv.py
Created November 23, 2022 04:13
Python script to convert Excel tables from PDF file to CSV
import pandas as pd
from tabula import read_pdf
# Specify file name
FILE_NAME = "sample.pdf"
# Total Pages
TOTAL_PAGES = 2
# Read the first page.
final_frame = read_pdf(FILE_NAME, pages="1")[0]
@mudssrali
mudssrali / geocodes.js
Created November 23, 2022 03:39
Read addresses from Pk-Cashpoints CSV and try to get geo-codes using Geolocation API
const fs = require('fs')
const axios = require('axios');
const Papa = require("papaparse");
fs.readFile('sample.csv', 'utf8', (err, data) => {
if (err) {
return console.error(err)
}
const [headers, ...parsedCSVData] = Papa.parse(data).data
@mudssrali
mudssrali / snippets-for-list-generation.ex
Created September 19, 2022 04:30
Snippets for list generation in Elixir
# Using for construct
# [0, 0, 0]
for _x <- 0..2, do: 0
# [0, 2, 4, 6, 8]
for x <- 0..4, do: x * 2
# List of 5 random numbers
for _x <- 0..4, do: System.unique_integer([:positive])
@mudssrali
mudssrali / snippets-for-array-generation.js
Created September 19, 2022 04:04
Snippets for array generation in JavaScript
// [0, 0, 0]
Array(3).fill(0);
Array.from(Array(3), () => 0);
// [0, 2, 4, 6, 8]
Array.from(Array(5), (_, index) => index * 2);
// Array of 5 random numbers
Array.from(Array(5), Math.random());
@mudssrali
mudssrali / open_browser.ex
Created August 20, 2022 09:26
Open a browser with URL in Elixir
def browser_open(url) do
win_cmd_args = ["/c", "start", String.replace(url, "&", "^&")]
cmd_args =
case :os.type() do
{:win32, _} ->
{"cmd", win_cmd_args}
{:unix, :darwin} ->
{"open", [url]}
@mudssrali
mudssrali / php-openssl-crypto-with-iv.php
Created September 15, 2021 22:28
PHP implementation of AES encryption and decryption using openssl_encrypt and openssl_decrypt with initialization vector
<?php
$ENCRYPTION_KEY = "put something secret here";
$ENCRYPTION_ALGORITHM = 'AES-256-CBC';
function encrypt($plain_text) {
global $ENCRYPTION_KEY;
global $ENCRYPTION_ALGORITHM;
$EncryptionKey = make_hash($ENCRYPTION_KEY, 32);
// create random Initialization Vector
@mudssrali
mudssrali / elixir-crypto-one-time.ex
Last active December 18, 2023 13:13
Elixir implementation of AES encryption and decryption using erlang's :crypto.crypto_one_time with initialization vector
defmodule Cipher.AES do
@moduledoc """
Functions related to encrypting and decrypting data using the Advanced
Encryption Standard (AES).
"""
@block_size 16
@secret_key "put something secret here"
@doc """
@mudssrali
mudssrali / php-openssl-crypto.php
Created September 15, 2021 20:45
Php implementation of encryption and decryption using openssl_encrypt and openssl_decrypt
<?php
$ENCRYPTION_KEY = '';
$ENCRYPTION_ALGORITHM = 'AES-128-ECB';
function encrypt($plainText) {
global $ENCRYPTION_KEY;
global $ENCRYPTION_ALGORITHM;
$EncryptionKey = makeHash($ENCRYPTION_KEY, 16);
$encryptedText = openssl_encrypt($plainText, $ENCRYPTION_ALGORITHM, $EncryptionKey);