Skip to main content

Posts

Showing posts with the label programming

Write Python Code to Send Email from Gmail

sendmail In this tutorial, we will write python code to send to multiple emails. Followings are the scenario: Emails will be listed in a text file The Python code will read the emails and send email to each address The email used is gmail Allow Less Secure App You must allow low secure app in your google account setting before you can run the code. In order to do that, go to https://myaccount.google.com/?pli=1 , navigate to sign in and security , scroll down and enable the allow less secure apps Write the Python Code Now we go to the most interesting part i.e. writing the code. Simplest Code We will start with a very simple code to send to one account #!/usr/bin/python import smtplib fromaddr = "mymail@gmail.com" frompass = "mypass" text = "this is the body" email = "targetmail@gmail.com" # login and send the email server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(from...

How To Make Program to Corrupt File (Java)

Sometime we intentionally want our file to be corrupted e.g. to test software reliability. So, I made a program in Java that intentionally corrupt file. Please be careful to use this program as this program will make your file corrupt and cannot be reverted. Please backup your file before making it corrupt. OK, the logic is very simple. For each byte in the file, I simply put any random character (ASCII character is from 0 to 255). Here is the complete Java program: import java.io.RandomAccessFile; import java.util.Random; /**  *  * @author arwankhoiruddin  */ public class CorruptFile {     /**      * @param args the command line arguments      */     public static void main(String[] args) {         // TODO code application logic here         String FILEPATH = args[0];         System.out.println("File to corrupt: " + FILEPATH);     ...

Install Python 3 and use VirtualEnv (OS X)

Install xcode: $  xcode - select   -- install Install homebrew: $  ruby   - e   "$(curl -fsSL  https://raw.githubusercontent.com/Homebrew/install/master/install )" Create .bash_profile: $ touch ~/.bash_profile Put this line inside .bash_profile:  export  PATH = / usr / local / bin : $ PATH Install python3: $ brew install python3 Create virtual environment. To make it easily found, create it under home: $ cd ~ && pyvenv arwan Activate the virtual environment created: $ source arwan/bin/activate Now you can start working in the new virtual environment. Note that it is worth to look at requirements.txt to see required packages on certain projects.

Pull Older Version from Git

Clone the current repository: $ git clone Go to the cloned directory: $ cd Find the sha1 of the commit to pull. For stash, click on the commit and look at the address bar. It will be the last part of the url. For example, the sha1 for http://mystash.arwan.com/repos/arwanproj/commits/0b004fdb420838ca04c15b25ad2e0b66a5693963 will be  0b004fdb420838ca04c15b25ad2e0b66a5693963   Fetch the version based on the sha1 number found: $ git fetch origin Checkout: $ git checkout FETCH_HEAD