Categories
All

Allocate memory to work as swap space on VMs

When physical RAM is already in use, VM instances use swap space as a short-term replacement for physical RAM.

Contents of RAM that aren’t in active use or that aren’t needed as urgently as other data or instructions can be temporarily paged to a swap file. This frees up RAM for more immediate use.

Resolution

Calculate the swap space size

As a general rule, calculate swap space according to the following:

Amount of physical RAMRecommended swap space
2 GB of RAM or less2x the amount of RAM but never less than 32 MB
More than 2 GB of RAM but less than 32 GB4 GB + (RAM – 2 GB)
32 GB of RAM or more1x the amount of RAM
Note: Swap space should never be less than 32 MB.

In this example dd command, the swap file is 4 GB (128 MB x 32):  

$ sudo dd if=/dev/zero of=/swapfile bs=128M count=32

2.    Update the read and write permissions for the swap file:

$ sudo chmod 600 /swapfile

3.    Set up a Linux swap area:

$ sudo mkswap /swapfile

4.    Make the swap file available for immediate use by adding the swap file to swap space:  

$ sudo swapon /swapfile

5.    Verify that the procedure was successful:

$ sudo swapon -s

6.    Enable the swap file at boot time by editing the /etc/fstab file.

Open the file in the editor:

$ sudo nano /etc/fstab

Add the following new line at the end of the file, save the file, and then exit:

/swapfile swap swap defaults 0 0

Done )

run $ htop and check swp [ ] section.

Categories
All

How to write hidden text into image

—= EXIF =—
Exchangeable image file format (officially Exif, according to JEIDA/JEITA/CIPA specifications) is a standard that specifies the formats for imagessound, and ancillary tags used by digital cameras (including smartphones), scanners and other systems handling image and sound files recorded by digital cameras. The specification uses the following existing file formats with the addition of specific metadata tags: JPEG discrete cosine transform (DCT)[1] for compressed image files, TIFF Rev. 6.0 (RGB or YCbCr) for uncompressed image files, and RIFF WAV for audio files (Linear PCM or ITU-T G.711 μ-Law PCM for uncompressed audio data, and IMAADPCM for compressed audio data).[2] It is not used in JPEG 2000 or GIF.

This standard consists of the Exif image file specification and the Exif audio file specification.

wikipedia
duck.png

there are many tools, in this post I will use exiftool Linux tool:

$ exiftool duck.png
ExifTool Version Number         : 11.65
 File Name                       : duck.png
 Directory                       : .
 File Size                       : 22 kB
 File Modification Date/Time     : 2020:03:13 05:49:30+02:00
 File Access Date/Time           : 2020:03:13 05:53:21+02:00
 File Inode Change Date/Time     : 2020:03:13 05:49:38+02:00
 File Permissions                : rw-r--r--
 File Type                       : PNG
 File Type Extension             : png
 MIME Type                       : image/png
 Image Width                     : 512
 Image Height                    : 512
 Bit Depth                       : 8
 Color Type                      : RGB with Alpha
 Compression                     : Deflate/Inflate
 Filter                          : Adaptive
 Interlace                       : Noninterlaced
 Significant Bits                : 8 8 8 8
 Image Size                      : 512x512
 Megapixels                      : 0.262

Let’s add some text “secret text for you 😉” into duck.png image metadata.

$ exiftool -Comment="secret text for you ;)" duck.png

Let’s check metadata again:

$ exiftool duck.png
ExifTool Version Number         : 11.65
File Name                       : duck.png
Directory                       : .
File Size                       : 22 kB
File Modification Date/Time     : 2020:03:13 05:58:51+02:00
File Access Date/Time           : 2020:03:13 05:58:51+02:00
File Inode Change Date/Time     : 2020:03:13 05:58:51+02:00
File Permissions                : rw-r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 512
Image Height                    : 512
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Significant Bits                : 8 8 8 8
Comment                         : secret text for you ;)
Image Size                      : 512x512
Megapixels                      : 0.262

As you can see text added:

Comment: secret text for you ;) 

In windows you can check metadata and it will looks something like this


You can save and extract Geo location lat & long from media files and more details too.

Note: most famous social media extract or removes(or in fact compress media files while uploading which cause exif data removal) but other many websites DONOT ex. flickr @_@

Understand Flickr EXIF data

EXIF data reveals the story behind a photo. Info like the camera type, settings, and location are automatically added by the device when it’s captured. You can see any photographer’s EXIF data if they’ve made it public.
Show or Hide EXIF data
– Click any photo to open it.
-Below the photo, click Show EXIF.

You can hide the EXIF data by clicking Hide EXIF.
Manage your EXIF data
– Keep EXIF data secret – Update your Privacy Settings to hide your own EXIF visibility.
– Missing EXIF data – Some image editing apps delete this upon saving.

https://help.flickr.com/en_us/understand-flickr-exif-data-r1ge02Xo1X

Which means if your smartphone camera enabled to save the Geo-location and you just capture video and upload it online.. that means your current physical Geo-location and more other details about you will be available online to the public.

Categories
All

API Multiprocessing

Motivation

In this article, I am going to show you how we can improve the computing power of simple API script from total overall (6 minutes and 17 seconds) to (1 minute 14 seconds)

The Idea

I will share with you one of my simple favourite technique that I prefer to use especially when I work on data science tasks such as data visualization, data analysis, code optimization, and big data processing.

Processing a task in a sequential way may take a long time especially when we are talking about a huge amount of data(eg. big inputs)

This technique takes advantage of parallelization capabilities in order to reduce the processing time.

The idea is to divide the data into chunks so that each engine takes care of classifying the entries in their corresponding chunks. Once performed, each engine reads, writes and processes its chunks, each chunk be processed in the same amount of time.

Example

The example I choose to use for this article is Genderize names that consist of 2 alphabetic characters.

Output Analysis Chart

Explanation

Clone GitHub Repo and follow instructions in Usage section.

Let’s generate all alphabet names that consist of 2 characters(to make the testing process easy)

we can use some Linux Kali penetration testing tool[1] such as crunch
$ crunch 2 2 > names.txt
so we generate all possible alphabet names with length 2 (676 lines)

then let’s create directories which are needed for splitting process
$ mkdir subs/ subs/inputs subs/outputs subs/outputs/parts subs/outputs/all

now we can split out input data, there are many ways to do that but I prefer to use Unix split command [2]
$ split -l 100 -d names.txt ./subs/inputs/
so we split names.txt file into small files, each file consists of 100 lines

now let’s run all processes: ./init.bash
after finish use merger.py script to merge all outputs.
merging process separated to avoid conflicts behaviours and sorting-save.


The Project on GitHub:
https://github.com/khaledalam/api-multiprocessing

An application uses this technique:
Hiring-Related Email(https://github.com/khaledalam/amazon-jobs)

Interesting related ideas:
Parallelizing using GPUs
– MapReduce (https://en.wikipedia.org/wiki/MapReduce)

[1] https://tools.kali.org/password-attacks/crunch
[2] https://en.wikipedia.org/wiki/Split_(Unix)