SESWatcher : how to prevent Amazon SES account from being suspended

Introdution

At this moment, AWS SES service is the best affordable price and high-quality service to sending (and receiving) programmatic emails. But, one day your account could be suspended without notice, and that takes a big effort of requesting support to get it back to work.

So it’s good to prevent that siatuation happens by watching your Bounces Rate and Complaints Rate. One way to resolve problem when your rates being too-high than allowance, is send a big amount of dummy emails to your blackhole email address.

Example

These is your send statistics :

  • Deliveries : 2000
  • Bounces : 180 ==> Bounces Rate : 180 / 2000 = 9%
  • Complaints : 30 ==> Complaints Rate : 30 / 2000 = 1.5%

Meaning :

  • Bounces : when your email didn’t send to existed email address (maybe your user type wrong or input fake one), we can pre-validate email before sending by using some email validator library or services like fast-email-validator
  • Complaints : when your receiver mark your email as SPAM :( Poor you !!!

Solution

AWS SES rules :

  • Bounces Rate : 5% => So you have to send more (180 / 4%) - 2000 = 2500 emails to reduce Bounces Rate to 4%
  • Complaints Rate : 0.1% => So you have to send more (30 / 0.07%) - 2000 = 40857 emails to reduce Complaints Rate to 0.07%

==> Number emails send = max(2500, 40857) = 40857 emails

SPAM YOURSELF 40857 EMAILS !!! 😂

SESWatcher - Your SES watchman

It’s open source software at https://github.com/khanhicetea/seswatcher (My first PyPi package :D)

Installation

1
$ pip install seswatcher

Usage

  1. Step 1 : Get AWS Credential User within AmazonSESFullAccess policy
  2. Step 2 : Verify sender email in AWS SES
  3. Step 3 : Get a blackhole email address which receives un-important emails.
  4. Step 4 : Create a hourly cronjob that runs seswatcher
1
$ seswatcher [OPTIONS] ACCESS_KEY SECRET_KEY FROM_EMAIL TO_EMAIL

Get help :

1
2
3
4
5
6
7
$ seswatcher --help
Usage: seswatcher [OPTIONS] ACCESS_KEY SECRET_KEY FROM_EMAIL TO_EMAIL

Options:
--region TEXT AWS SES Region (default is us-east-1)
--interval INTEGER Timer interval
--help Show this message and exit.

Evaluate expression string with variables in PHP without eval

TLDR;

Never ever use eval function in PHP !

Updated Jul 31 : we can use Expression Language

Introduction

In some applications, we need to let user defines the expression (user lambda function) to evaluate a value or a condition. So we store user-defined expression in database then using eval function and pass variables to that function.

It works, but not securely ! Remember this important thing :

NEVER TRUST USER INPUT !

So how this article will show how we achieve the goal without touching eval or create_function function.

Idea

The idea came out when I used Ansible tool (a Pythonic dev-ops tool, with great docs and community). Ansible uses jinja template engine as mainly syntax for many thing, to render the template file and to evaluate the condition when syntax.

Same in PHP, we have Twig template engine !

Twigeval

This is my library (https://github.com/khanhicetea/twigeval) that using the above idea, one of few libraries which I write Unit Test for ;)

Installation

1
$ composer require khanhicetea/twigeval

Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
$cacheDir could be :
- false : no use cache (mean use eval function), be carefully !
- null : use sys_get_temp_dir() to get system temp directory as cache dir
- string : cache directory path
*/
$cacheDir = null;
$calculator = new KhanhIceTea\Twigeval\Calculator($cacheDir);

$math = $calculator->number('a / 4 + b * 3', ['a' => 16, 'b' => 3]);
// => 13

$boolean1 = $calculator->isTrue('(a and b) or c', ['a' => false, 'b' => true, 'c' => false]);
// => false

$boolean2 = $calculator->isFalse('(a and b) or c', ['a' => false, 'b' => true, 'c' => false]);
// => true

// We can even use Twig filters, functions
$string = $calculator->calculate('{{ a|reverse }} world !', ['a' => 'hello']);
// => olleh world !

Voilà !!! We have user-defined lambda function.

Feel free to contribute ! Thanks ! :)

Til next time !

AI Has Been Ruining Mankind Slowly

Just my 2 cents …

Nowaday, it’s easy to see a news about AI (artificial intelligence) on the media. Even we are using it everyday without cognition. SO WHAT IS IT ? IS IT GOOD or BAD ? AND CAN WE … EAT IT ?

In this article I will try to answer that questions :

  • AI is just technology, so you can’t eat it ;)
  • Technology is just a … technology, a thing that human created. So it’s good or bad ? Depends on what purpose and context we used it !
  • In some context, it will ruin your life. I will explain in this section.

AI has been eating the world

Get back to your life :

  • When did the last time you search thing on Google ? Have you notice that Google will show different results for different people within same keyword ? That’s personality AI !
  • Remember when you was watching a Youtube video and saw the recommended videos in right sidebar ? It’s recommendation AI !
  • And the time you posted a photo to Facebook then it’s automated help you tag your friend to the photos ? This is recognition AI !!
  • And many many cases …

We can not eat technology !

As I said, AI is just technology that human created from their stupidity. It helps us building this world up and sometimes burning it down.

AI can help in agriculture, industry, healthcare, services by automation with its learned knowledge. But automation is killing jobs, taking money from non-professional worker, taking food and learning condition away from their children, etc.. Unemployment is really really bad !

“Every war, every revolution, demands the sacrifice of a generation, of a collectivity, by those who undertake it.” - Simone de Beauvoir

And human can pass any war, any revolution in history. So AI isn’t really bad in this context ! So how has AI been ruining mankind slowly ?

By making us lazy on thinking and stupid on decision !

This is an example. Today (May 9 2018), Google announced its new feature for GMAIL users : SUBJECT: Write emails faster with Smart Compose in Gmail

This is what it provided : “Smart Compose, a new feature powered by artificial intelligence, to help you draft emails from scratch, faster.”

And this is its demostration :

Smart Compose

As we can see, the writer only have to press first word (or even first letter) then [TAB] (haha this looks like autocomplete in programming by an IDE, may be this idea came from a developer). Everything is done ! WOW, this is amazing feature, a killer feature, a revolution on writing email.

BUT … BUT …

It annoys you on thinking what to write next !

It destroys your emotion !

It’s just a template, a stereotypy ! It kills your imagination and your creative !

It fixes us on wrong words, grammars, ideas ! But we has been improving ourself by making mistake everyday !

It makes us lazy on thinking and stupid on decision !

It has been ruining your life !

WHAT IF !? WHAT IF !? SOMEDAY, WHEN YOU TYPE THE FIRST KEY [F], IT WILL RECOMMEND THIS TEXT “FUCK HUMANITY !” 😂 LIKE THIS SIRI

DON’T LET TECHNOLOGY RUIN YOUR LIFE ! BUT USE IT TO MAKE LIFE BETTER !


Ref :

  • Smart Compose demonstration from Google
  • Cover photo from Google Image Search (thanks for this AI, haha)

Learn Sketch : Day #3

The result of day #3, practice Dragon Head again, front face is failed :(

Sketch day 3

Til next time !

Learn Sketch : Day #2

The result of day #2 (Dragon Head , a bit like Dog Head :lol: ) :

Sketch day 2

Til next time !

Learn Sketch : Day #1

The result of day #1 :

Sketch day 1

Til next time !

Yay ! This's my 101st blog post

Hi there,

I start this blog from Nov 30, 2015. It means I have taken a 777-day journey through every line, every single word of this blog. (Oh man ! It’s a lucky number !!!)

777 / 101 = 7.(6930)(6930)(6930)(6930)… days per post 😱

You know, sometimes we can’t achieve anything without help from the others. And yes, it’s from you - who reading this line. You are the purpose, the (why) I wrote this thing.

I know my writing skill isn’t good, my ideas aren’t new, unique or shiny, but I believe that I gave you something (at least for entertainment or wasting your time, haha). I believe that I will improve it as long as I write. Btw, I have a plan to stop writing when no one reads this blog for a month. Maybe the plan will never come true! Maybe not ?! 😜

So please help me on this, ask me, make me stuck in your curiosity, then fix me! m(‘.’)m

KEEP BELIEF, DO ACTION THEN SHARE VALUE

Thanks!

Til next time ;)