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
// assume getData to be an API call
console.log("Getting Data1");
var data1 = getData('123');
console.log("Data is:", data1);
console.log("Getting Data2");
var data2 = getData('456');
console.log("Data is:", data2);
var sum = 1 + 2;
console.log("Getting Data1");
getData('123', function(data1) {
console.log("Data is:", data1);
});
console.log("Getting Data2");
getData('456', function(data1) {
console.log("Data is:", data1);
});
sudo apt-get install percona-toolkit
pt-online-schema-change --alter
"Add column <new_column> varchar(60) NOT NULL default <default_value>"
--user=root D=<database_name>,t=<table_name> --execute
@cosmos-sajal
cosmos-sajal / pid.php
Last active September 13, 2018 10:10
getting PID in PHP
/**
* @return Integer
*/
public function getProcessId()
{
return getmypid();
}
@cosmos-sajal
cosmos-sajal / processRunning.php
Created September 13, 2018 10:24
Is a process running
/**
* @return boolean
*/
public function isProcessRunning($pid)
{
if (file_exists("/proc/".$pid)) {
return true;
} else {
return false;
}
@cosmos-sajal
cosmos-sajal / processRunning.php
Created September 13, 2018 10:27
is the process running
/**
* @param Integer $pid
*
* @return boolean
*/
public function isProcessRunning($pid)
{
if (file_exists("/proc/".$pid)) {
return true;
} else {
@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;
}
@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 / 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.
if ($this->lockHandlerUtil->isDuplicateInstanceRunning()) {
// trigger some kind of alert
return;
}
/*
actual cron code
....
....
*/