Skip to content

Instantly share code, notes, and snippets.

View cosmos-sajal's full-sized avatar
🌏
Trying to add meaning to this life.

Sajal Sarwar Sharma cosmos-sajal

🌏
Trying to add meaning to this life.
View GitHub Profile
@cosmos-sajal
cosmos-sajal / encryptAESCBC.go
Created October 26, 2023 15:29
Encrypt using AES CBC
func encryptKYCData(plainText string) string {
// refer this - https://chat.openai.com/share/1f7f6ca1-23fb-45c3-9fb1-88c42efb9880
password := []byte(os.Getenv("ENCRYPTION_KEY"))
// pad the plaintext if it is not a muliple of aes.BlockSize
plainTextBytes := []byte(plainText)
padLength := aes.BlockSize - len(plainTextBytes)%aes.BlockSize
padding := bytes.Repeat([]byte{byte(padLength)}, padLength)
plainTextBytes = append(plainTextBytes, padding...)
cipherText := make([]byte, len(plainTextBytes))
@cosmos-sajal
cosmos-sajal / plot.py
Created March 14, 2019 09:13
Plotting
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
# Donald Trump's tweet results were in twitter-out.txt
# Hillary Clinton's tweet results were in twitter-out1.txt
@cosmos-sajal
cosmos-sajal / pickling_classifier.py
Created March 14, 2019 08:57
Sentiment Analysis - Model Creation
import nltk
import pickle
from nltk.classify.scikitlearn import SklearnClassifier
def pickling(file, document_name):
save_documemts = open('../pickled_algos/' + document_name + '.pickle', 'wb')
pickle.dump(file, save_documemts)
save_documemts.close()
# let the training_set contains data in the form of -
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy import api
from tweepy.streaming import StreamListener
import json
#consumer key, consumer secret, access token, access secret.
ckey="<ckey>"
csecret="<csecret>"
atoken="<atoken>"
@cosmos-sajal
cosmos-sajal / Magic Link 1
Last active October 25, 2020 04:21
Magic Link 1
if ($this->lockHandlerUtil->isDuplicateInstanceRunning()) {
// trigger some kind of alert
return;
}
/*
actual cron code
....
....
*/
@cosmos-sajal
cosmos-sajal / Invoke LockHandlerUtil
Created September 13, 2018 10:48
Invoke LockHandlerUtil
$this->lockHandlerUtil = new LockHandlerUtil(
$this->getName(),
$this->getContainer()->get('kernel')->getRootDir()
);
// $this->getName() will return the current file name
// of the Command (Cron) in Symfony framework.
@cosmos-sajal
cosmos-sajal / LockHandlerUtil.php
Created September 13, 2018 10:43
The complete one!
/**
* Class LockHandlerUtil
*/
class LockHandlerUtil
{
/**
* @param String $fileName
* @param String $rootDir
*/
public function __construct($fileName, $rootDir)
@cosmos-sajal
cosmos-sajal / PID.php
Last active September 13, 2018 10:40
creating and checking PID
/**
* @param Integer $pid
*
* @return boolean
*/
public function isProcessRunning($pid)
{
if (file_exists("/proc/".$pid)) {
return true;
}