29 Haziran 2015 Pazartesi

AWS S3 Multi Part Upload

# Single put request limit is 5 GB if you need to upload larger than 5 GB
# you need to use multipart upload

import java.io.File; import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.Upload;

public class UploadObjectMultipartUploadUsingHighLevelAPI {

 public static void main(String[] args) throws Exception {
  String existingBucketName = "*** Provide existing bucket name ***";
  String keyName = "*** Provide object key ***";
  String filePath = "*** Path to and name of the file to upload ***";

  TransferManager tm = new TransferManager(new ProfileCredentialsProvider());
  System.out.println("Hello");  / TransferManager processes all transfers asynchronously,
  // so this call will return immediately.
  Upload upload = tm.upload( existingBucketName, keyName, new File(filePath));
  System.out.println("Hello2");

  try {
    // Or you can block and wait for the upload to finish
    upload.waitForCompletion();
    System.out.println("Upload complete.");
  } catch (AmazonClientException amazonClientException) {
    System.out.println("Unable to upload file, upload was aborted.");
    amazonClientException.printStackTrace();
  }
  //Do not forget to shut down transfer manager
  tm.shutdownNow();
 }
}

13 Haziran 2015 Cumartesi

Enable Remote Access To OSX

# SSH into your remote OSX machine with administrator account

 sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kicks tart -activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes -clientopts -setvncpw -vncpw mypasswd -restart -agent -privs -all

#Login using a VNC client (TightVNC,RealVNC...)

#Turn off when you are done with

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off  

Objective-C Exception Handling

Objective-C Exception Handling

@try{

   if(/*error*/){
     @throw exception;
   }
}
@catch(NSException* exception){
  [self handleException:exception];
}
@finally{
  [self cleanup];
}

Details are here;

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Exceptions/Tasks/HandlingExceptions.html#//apple_ref/doc/uid/20000059-SW8

How to Enable Passwordless Rsh Redhat/Centos

[bs ~]$ yum install rsh-server

#rsh,rlogin,rexec,xinetd on
[bs ~]$ chkconfig rsh on
[bs ~]$ chkconfig rexec on
[bs ~]$ chkconfig rlogin on
[bs ~]$ chkconfig xinetd on
[bs ~]$ service xinetd start or restart

#Edit /etc/securetty file. Append the lines below

rsh
rexec
rlogin

#Create .rhosts file in user home(~) with the host names of the machines you wish to allow
in below format.(node01 should be resolved with DNS)

node01
192.168.0.1

#Make sure file permissions
[bs ~]$ chmod 600 ~/.rhosts

rsh path variable and /usr/local/bin problem

# As we know same with bash rsh path variable read from .bashrc file but default value does not include /usr/local/bin folder. So if you need any executable to run from /usr/local bin you need to add;

export PATH=/usr/local/bin:$PATH

line into .bashrc file

How to mount a new drive on startup

Just do steps below;

sudo vim /etc/fstab
#Add line to end of file
/dev/xvdb /absolute/path/to/point auto defaults 0 2
:wq
Done :)