Skip to content

Instantly share code, notes, and snippets.

@starx
starx / curl_gmail.sh
Last active March 20, 2021 06:09
Send mail using gmail and curl
email_file=$(tempfile)
# Compose message
echo "From: Earthlings <people@earth.com>" >> $email_file
echo "To: Martians <people@mars.com>" >> $email_file
echo "Subject: Helloooo world" >> $email_file
echo "Content-Type: text/plain; charset=\"utf8\"" >> $email_file
echo >> $email_file
echo "Hi! :)" >> $email_file
# Send the email
@starx
starx / extract_binlog
Created September 19, 2017 09:31
Bash to extract MySQL bin logs of a database between date range
#!/bin/bash
MYSQL_BIN_LOG_FOLDER='/var/lib/mysql'
MYSQL_BIN_LOG_FORMAT='.*mysql\-bin.*'
DATABASE_NAME=$1
START_TIMESTAMP=$2
END_TIMESTAMP=$3
echo $DATABASE_NAME
echo $START_TIMESTAMP
@starx
starx / restrict_file.php
Last active February 16, 2017 16:20
PHP Restrict access to file based on created time of the file
<?php
$requestedPath = '...';
$service = $app['service.filesystem'];
$fullFilePath = realpath($requestedPath);
// If the file path cannot be found then stop proceeding
if(!$fullFilePath) die('INVALID');
$fileStat = stat($fullFilePath);
$finalAllowedTimeStamp = strtotime("2017-02-01");
{% extends "@app/form_layout.html.twig" %}
{% block _{FORM_NAME}_{ELEMENT_NAME}_widget %}
{{ form_widget(form) }} Modified
{% endblock %}
@starx
starx / heredoc.php
Created January 26, 2017 10:48
PHP: Calling a function inside HEREDOC
<?php
echo <<<EOT
One month ago was ${!${''} = date('Y-m-d H:i:s', strtotime('-1 month'))}.
EOT;
<?php
/**
* throw exceptions based on E_* error types
*/
set_error_handler(function ($err_severity, $err_msg, $err_file, $err_line, array $err_context)
{
// error was suppressed with the @-operator
if (0 === error_reporting()) { return false;}
switch($err_severity)
{
@starx
starx / generate_x509_cert.sh
Created November 2, 2016 10:44
Generate x509 Certificate using Expect
/usr/bin/expect -c 'spawn openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./apache.key -out ./apache.crt
expect -re {Country Name \(2 letter code\) [^:]*:} {send "NP\n"}
expect -re {State or Province Name \(full name\) [^:]*:} {send "Bagmati\n"}
expect -re {Locality Name \(eg, city\) [^:]*:} {send "Budhanilkantha\n"}
expect -re {Organization Name \(eg, company\) [^:]*:} {send "nGen Technologies\n"}
expect -re {Organizational Unit Name \(eg, section\) [^:]*:} {send "Software Development\n"}
expect -re {Common Name \(e.g. server FQDN or YOUR name\) [^:]*:} {send "mrnepal.com\n"}
expect -re {Email Address [^:]*:} {send "test@mrnepal.com\n"}
expect eof'
@starx
starx / Javascript ISO Country Lists for Select2 Plugin
Last active June 22, 2020 12:57 — forked from maephisto/Javascript ISO country code to country name conversion
ISO 3166-1 alpha-2 country code to country name conversion with a implementation for Select2 plugin [Demo 1: http://jsfiddle.net/Starx/sgb4888k/1/, Demo 2 (With flags): http://jsfiddle.net/Starx/sgb4888k/2/]]
(function($) {
$(function() {
var isoCountries = [
{ id: 'AF', text: 'Afghanistan'},
{ id: 'AX', text: 'Aland Islands'},
{ id: 'AL', text: 'Albania'},
{ id: 'DZ', text: 'Algeria'},
{ id: 'AS', text: 'American Samoa'},
{ id: 'AD', text: 'Andorra'},
{ id: 'AO', text: 'Angola'},