Friday, May 3, 2019

Laravel-like Timestamps With Symfony & Doctrine

I have enjoying my development time with Laravel a lot and a quite helping feature is Laravel keeping track of Model creation and update timestamps automatically when using its Eloquent ORM. Once after every indefinite days, I decide to do my next thing with Symfony. It was, is and will always be my favorite PHP framework!

After a lot of Laravel programming previously, I have been feeling sick of setting created_at and updated_at timestamps manually in each of my actions. So I figured myself a quick, re-usable way out to do it elegantly and move logic out of the actions.

It can be achieved by creating a trait in file Timestamps.php in src/Entity folder of your Symfony applications with below contents:

Then import and use the Timestamps trait in your Entity class as follows:

If you use (Doctrine) migrations for your database upgrades, you may add required created_at and updated_at columns as shown below to your table:

Hope it might help you too as it did to me!

Saturday, April 27, 2019

APK Studio 5 Release Announcement

I recently done finalising and then, releasing prolonged update for APK Studio, the 5.x series available for download on Github.

The notable changes are:

  1. Complete re-write, simpler codebase
  2. New dark theme for your eyes
  3. First-party builds for Linux, Mac OS X (yes!) & Windows
  4. More stability and features within IDE
  5. Did I mention, a newer, cleaner website?

Go ahead and download them here. Let me know here if any suggestions or report issues on Github.

Sunday, October 14, 2018

Remote Controlling LED Using NodeMCU (ESP8266) Board

Been tinkering around with the NodeMCU (ESP8266) more after I published the original tutorial about Getting Started To Use NodeMCU (ESP8266) With Arduino IDE. Before reading this further, I would recommend you go through it to make sure the board is already setup on your PC with the Arduino IDE (if not already).

I came to notice its quite easy to jump into the interesting world of IoT with this particular board. Since the board has on-board WiFi chip from Espressif, you can control just about anything you want remotely.

I have shared below a simplest possible example of how you can control state of an LED connected to the NodeMCU board remotely (from your phone). Let's start by putting connecting the LED as shown below:

Connect the board to the PC using a/the Micro-USB cable. Go to Tools, Board, select NodeMCU 0.9 (ESP-12 Module). Go to Tools, Port & select COMX port on which the board is connected to PC.

Replace below example code into your Sketch in Arduino IDE. Let me describe what the above code actually does. At startup, it tries to and waits for a successful connection with the SSID & password you have specified. Once connected, it then starts and listens for incoming connections over port 80 (HTTP default). This is what it does in the setup stage.

Now in the main loop, it waits for an incoming HTTP client connection which if found, the checks if the request method is GET and URL contains a specific command like /state/OFF or /state/ON and then reacts accordingly i.e., put the specified pin LOW or HIGH which in turn, sets the LED off or on respectively. In either case, it also responds with a HTML page that shows current state of LED and a link to change the state.

To access the HTML page, you need to be connected to the same WiFi network as the NodeMCU (ESP8266) board and browse the board's local IP address in your favorite browser. To know the IP address easily, the above code writes some useful messages over the serial port it is connected to which you can see by open the Serial Monitor from Tools, Serial Monitor from the Arduino IDE.

Sunday, September 30, 2018

Getting Started To Use NodeMCU (ESP8266) With Arduino IDE

I have recently started getting my hands a bit dirty with the electronics. To start with, I bought a Arduino UNO, Arduino Nano, CubieBoard 3 (CubieTruck), Raspberry Pi Zero W & a couple NodeMCUs. I am still into in-depth learning how these electronics work. When trying to use one of my NodeMCU with the Arduino IDE (they said it was compatible so it's convenient), I found its not very straight forward to get it working in first attempt.

In this blog post, I will try to write the exact steps that were need to get it working along with a minimal example to test. This tutorial assumes you got a Windows (10) PC. Linux/Mac users should be able to adapt most of this write-up to their systems accordingly. Let's start!

First you need to get yourself a ESP8266/NodeMCU board. You can buy one from Amazon (India/International) or any other website/place you like. Along with the board, make sure to get yourself a Micro-USB cable to connect the board with PC. When it comes to cable, I just prefer those from AmazonBasics. Always the top-notch quality and choice of black/white color (am I doing promotions here? :D Nope, I just love it so much). Also buy a breadboard and a simple LED required for the example program to run.

Once it arrives, download and install the Arduino IDE on your PC from here. Before you connect your board to PC, you will also need to download and install USB to UART drivers from here to get the serial/COM port working.

Launch Arduino IDE. Go to File, Preferences, Settings (Tab). Put below URL in additional board manager URLs:

Click OK. Go to Tools, Board, Board Manager. In the filter box at the top, type ESP8266 and install the esp8266 package by ESP8266 Community.

Not put your NodeMCU in the center of any breadboard end and connect the LED to GND and D8 (GPIO 15) as shown below:

Connect the board to the PC using a/the Micro-USB cable. Go to Tools, Board, select NodeMCU 0.9 (ESP-12 Module). Go to Tools, Port & select COMX port on which the board is connected to PC.

Replace below example code into your Sketch in Arduino IDE.

Hit the Upload button to compile + push your program to the board and run it! You should see the LED blinking or maybe not if anything messed up. Ask me in comments if you encounter issues!

Sunday, May 15, 2016

***SPAM*** Invoice #34069680 [Malware]

Iam always more interested in SPAM emails rather than my Inbox. Today, I stumbled upon an email in my Spam box with subject Invoice #34069680. It had a spam-my named attachment along with it saying they have sent some of my shipment lol! and this is the invoice to the same.

I then de-activated my Anti-Virus software, downloaded the zip archive, extracted & it had a lonely file in it named invoice_copy_Bqa6Ci.js. It was in fact, no invoice document but a JavaScript file with following contents.

It seemed like it was obfuscated, so I went in to dig the thing deeper and de-obsfuscate it line-to-line by hand. The result I got is as below:

This clearly shows what it does. It downloads a file from either or (most probably the second URL is there as a fallback in case the first one fails), and saves it as 4194304.exe in your %TEMP% folder, and finally executes it upon successful download. Thenafter, you cannot tell how much the unknown executable saved in your %TEMP% folder will be able to exploit your system.

So beware! If you receive any email similar or exactly as this one, make sure don't download anything there in it.