Thursday, March 10, 2022

The begin of my final phase

I have worked in NUST for the past four years now and I have experienced the so called cream of professionals there, none of whom were capable of actual change and all of them were only concentrated on one thing "How to get to the higher ranks without putting in your maximum efforts". This concept of lack of drive and greed of getting power, fame and recognition is probably one of the worst ways to drive your career. The path which you choose has to have the following components in order to have self-satisfaction. 1. Honesty: This means even if you have done something wrong, stand up, raise your hand and say yes I have done this and I am ready for the consequences 2. Smart Work: To some people smart work is probably copy pasting an already developed idea, for me smart work is to understand new processes and find a better solution 3. Integrity: This one is a bit tricky when it comes to Pakistan as no one here has this quality and the person who has it is considered to be stupid. Integrity is doing your work with full effort and trying your best even under fire. When it's a high pressure situation keeping your cool and working with full focus 4. Foresight: This is probably the most important component in your career development, to have a foresight of what might go wrong and how to fix it. That problem might never show it's face but still having a plan for it is wise and comes quite handy in sticky situations 5. Bravery: My most favourite trait and not an essential component when it comes to Pakistan but bravery/valour is a trait which makes a leader

Friday, March 1, 2019

The way to remove the UniversalHeader frame from the peoplesoft through javascript (Top Navigation Bar of Peoplecode)

So after searching for a solution to this for the past four to five days I gave up all hope and tried to think the way of the real developer and a hacker of course. The motive behind removing the god damn navigation header which contains the Home , Add Favourites and Sign out hrefs was simple, to trap the user to fill a form before proceeding the the main home page. I have been a developing pages on peoplesoft for the past two years and this was the first major obstacle I had to face for a very long time. Dont get me wrong I am an innovator and like to stretch the limits of any framework I am given. As this task had a time line on it, it was both fun and tense at the same time. Ok enough of the talk lets start with what my approach was. So I have added Iscripts before and I have dabbled in the signon peoplecode area too, so I know that you can easily show a page before the homepage without any problem. The main issue this time was that I needed to upload stuff and make a button which could call a report, that as we all know can only be done in peoplecode. So i mixed it up a bit. I redirected my user to a native peoplesoft page on the signon peoplecode function (custom made weblib record).  Now the problem was I needed to force the user to enter a survey and then proceed but the navigation bar was visible. So this is what I came up with. In the native peoplesoft page I added an html. and i wrote the below code in the html:


<script language='javascript'>
window.onload = function()
{
var test1 = top.window.frames['UniversalHeader'];
var pageToDestory = test1.document.getElementsByClassName('PSPAGE')[0];
pageToDestory.style.display ="none";
}

</script>




A simple and effective strike. Now what the problem peoplesoft makes two frames one frame is the UniversalHeader which is on the top of the page where ever we go and the second one is the frame which contains your page. No crumbs = true (xD) . the html which is custom made by the developer resides in the second frame. This code although resides in the second frame, it jumps to the first frame through.
var test1 = top.window.frames['UniversalHeader'];
    Now we have access to the first frame elements. Next is to get the page in the first frame which contains the navigation bar.
var pageToDestory = test1.document.getElementsByClassName('PSPAGE')[0];
  Then simply make display none.


Simple and elegent

Thursday, March 9, 2017

Just a Normal day

Started teaching Dameer Java and website designing. He is growing up really fast. Maybe one day he finds my "secret" blog which is exposed to the world. Its funny how small and insignificant we are in this world and yet in every life there is the universe immersed. On 13th there is a court hearing which his Father has initiated. I still have to do some work of kareem who is disappointed in me because I haven't completed his application and some more work for Usman who has a brilliant idea for joining amazon, ebay and a personal online store into a single click(let's no go into details about this).  Qudrat is just sending me online job offers I don't know why he is doing that, I hope he doesn't feel bad that he didn't find jobs for me in Oman and is compensating for that. Saira started a job in Fatima Jinnah University + doing her BA LLB from Islamic 3 more months remain. I didn't get my NUST Pay this month as I haven't attested my University Degree. I have found a friend in the office, Sir iftikhar who has been coding for a long time now. His heart is in the right place, and is extremely supportive. All of my office mates are nice and I have learned a lot of human interaction from them. I am feeling extremely sad today for no apparent reason maybe its because I am alone in my room and have locked my door while dameer is outside wondering where I am. I have grown quite fond of my Sister's son, I feel like he is my own. I feel that I am becoming more like my father after each passing day and I am afraid of the future and what it holds for me. I have strayed from the path I originally chose for myself, the path of solitude and separation from the world. I don't get Haris's calls now I think he is done with me I think I have disappointed him too somehow, I wonder how. 

Monday, December 5, 2016

Peoplesoft Dynamic Dropdown list with extra dropdown values

I am working in an organization which is using CMS of oracle called peoplesoft. In that CMS there was a requirement. The requirement is like this. So we have all these school names in our database and there a a table dedicated to the names of the Schools. I wanted to populate a dropdown menu which will show the names of the schools plus some other values in the dropdown too. Also I shouldn't insert a row in the table. Although this is a simple mechanism in html and css, in peoplesoft it requires a bit of programming. So first I made a field 30 characters long. It can be any amount of characters you want. Then I added a prompt table to the field ACAD_GROUP_TBL. with this prompt table added I got all the names of the schools in my field. Now comes the tricky part. Why is it tricky, well because there are two methods to achieve this feat. First one is crude, you make a new table and add the row you want to display in your dropdown values. Why is this crude, well you have to add a table thats why and I don't want to mess with the tables as much as possible today i add a table for this tomorrow i add more tables and keep on doing this and eventually the database is huge with repetitive tables with minor changes. So the work around is this. Add the code below to the rowinit of the field which you added the prompt table to.

Local Rowset &Xlat;

&FLD = GetRecord(Record.RR_REG_CON_SCH2).GetField(Field.RR_REG_REMARKS);
&FLD.ClearDropDownList();


&Xlat = CreateRowset(Record.ACAD_GROUP_TBL);
&Xlat.Fill();

&Xlat_cnt = &Xlat.ActiveRowCount;
For &I = 1 To &Xlat_cnt
   &CodeIn = &Xlat.GetRow(&I).GetRecord(1).ACAD_GROUP.Value;
   &DescIn = &Xlat.GetRow(&I).GetRecord(1).ACAD_GROUP.Value;
   
   &FLD.AddDropDownItem(&CodeIn, &DescIn);
End-For;

&FLD.AddDropDownItem("code", "description");

Once is this done you got yourself a dynamic drop down list which populates first from the ACAD_GROUP_TBL then adds somemore.


 

Wednesday, May 27, 2015

Of callbacks and cross-domains in arduino

I will begin with a little code snippet so it will help me jog my memory for future endeavors.

client.fastrprintln(F('HTTP/2.0 200 OK'));
client.fastrprintln(F('Content-Type:text/html'));
client.fastrprintln(F("")); //tells that headers have ended and the body is starting
client.fastrprintln(F("calculate('{\"arduino\":1}')"));


The last line is equivalent to God making life. Why would I say that? Well for that we will have to see the whole picture and where and how I came here.

  The need was simple, I was making a home automation application on phonegap and every arduino was on a different ip. Now we all know that cross domain access can only be done by jsonp in $.ajax which is given in jquery ( bless those ppl ). Why would I need cross domain you ask? Well my arduino is UNO and UNO means shitty small memory and for everyone's happiness we need the system to be fast, so why not remove the SD card dependency altogether meaning why not just make ajax calls to the arduino and have a html,css and js reside in the android / iphone device. When this happens you get into a problem. Android device has it's own ip, arduino UNOs have their own ips, so the need of  XHR comes into play. Now we all know that XHR can't be accessed through cross domains so we require jsonp on them(what about websockets?). JSONP are like fetching javascripts from other sites which we do every single day but and there is a huge butt here these scripts are transformed into json objects. So in short through jsonp on $.ajax we fetch the information in the form of scripts but we run it through a json parser and lo and behold we get a json object. Now this is all very simple on the android / iphone side with the help of Phonegap i.e. calling to a cross domain to give us a jsonp. Here is the code:
   $.ajax({
                      type:"GET",
                      url:"http://192.168.0.105/hi",
                      dataType:'jsonp',
                      jsonpCallback:'calculate',
                     success:function(data)
                                  {
                                   console.log("success");
                                  console.log(data);
                                    }
                      });


Now you see that I have added the jsonpCallback as calculate. If you revisit the first code i wrote, which was in arduino, you see what I am sending the the response data. You got it I am sending a whole function back in the response data calculate('{\"arduino\":1}'). When this function returns to the ajax it sees that the callback has returned from the server side with data ("arduino":1). this data can then be used by our html, js to change a part of the html. I searched the net for an answer on this but found none, so I am here sharing this with you. So if you need a cross domain response from the arduino in the form of a json object this is your answer. Hope this helps anyone who reads it ^^

Sunday, March 16, 2014

Stable comm?

So i think i have pinned the communication problem. It is stable now. Moving towards the stablization code soon. I still havnt tried the quad I know its dumb but I am a bit scared. Will try it this week promise as the days are coming close. I feel it is time now.

Saturday, March 15, 2014

Large delays small delays

package org.quad.finalyearproject;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.List;
import com.example.safsdf.R;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements SensorEventListener {



Handler hand = new Handler();
 private ToggleButton button,arm;
 private TextView tv;
 boolean armon,sent=false;
 SeekBar sb;
 String motorvalues;
 Communicator c;
 boolean onetime=true;
 boolean twotime=true;
 int armed=0;
 int h=0;
 int yaw;  // View to draw a compass
 int pitch;
 int roll;
 int pyaw=0,ppitch=0,proll=0;
 int throttle=1000;
private SensorManager sensorService;
private Sensor accel;
private Sensor gyro;

long dtMili = System.currentTimeMillis();
private List<Sensor> sensor;

 @Override
 public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  button = (ToggleButton) findViewById(R.id.connect);   //reference to the send button
  arm=(ToggleButton)findViewById(R.id.arm);
  sensorService = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
  tv=(TextView)findViewById(R.id.textView1);
  sensor=sensorService.getSensorList(Sensor.TYPE_ALL);
  accel = sensorService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
 gyro =sensorService.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);

 sb=(SeekBar)findViewById(R.id.seekBar1);
 sb.setVisibility(View.INVISIBLE);
 sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){

@Override
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {

//90 91
if(System.currentTimeMillis()-200>=dtMili)
{
throttle=arg1+50;
throttle=throttle*9;
dtMili = System.currentTimeMillis();
tv.setText(throttle+"");
}


}

@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub

}

@Override
public void onStopTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub

}});
  Iterator<Sensor> iterator = sensor.iterator();
while (iterator.hasNext()) {
Sensor d=iterator.next();
System.out.println(d.getName());
}


}
 protected void onPause() {
   super.onPause();
   sensorService.unregisterListener(this);
 }
 protected void onResume() {
   super.onResume();
   sensorService.registerListener(this, accel, SensorManager.SENSOR_DELAY_NORMAL);
   sensorService.registerListener(this, gyro, SensorManager.SENSOR_DELAY_NORMAL);
 }


 public void onarmclicked(View view) throws IOException
 {
boolean armon = ((ToggleButton) view).isChecked();
if(armon)
c.armmotors();
if(!armon)
c.disarmotors();


 }
 public void onToggleClicked(View view) {
   // Is the toggle on?
   boolean on = ((ToggleButton) view).isChecked();
 
   if (on) {
    ConnectivityManager connMgr = (ConnectivityManager)
               getSystemService(Context.CONNECTIVITY_SERVICE);
           NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
           if (networkInfo != null && networkInfo.isConnected()) {
           
             c=new Communicator(MainActivity.this);
             c.execute();
            Toast.makeText(MainActivity.this, "Network connection available.", Toast.LENGTH_SHORT).show();
            sb.setVisibility(View.VISIBLE);
     

           } else {
            Toast.makeText(MainActivity.this, "No network connection available.", Toast.LENGTH_SHORT).show();
           
           }
   } else {
   
    if(c.online())
    {
    boolean f=c.offline();
    if(f==true)
    {Toast.makeText(MainActivity.this, "Connection Terminated", Toast.LENGTH_SHORT).show();
    sb.setVisibility(View.INVISIBLE);
   
    }
    else
    Toast.makeText(MainActivity.this, "Connection couldn't be Terminated", Toast.LENGTH_SHORT).show();
    }

   }
}






@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub

}

float[] mGravity;
float[] mGeomagnetic;
public void onSensorChanged(SensorEvent event) {
  if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
    mGravity = event.values.clone();
  if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
    mGeomagnetic = event.values.clone();
  if (mGravity != null && mGeomagnetic != null) {
    float R[] = new float[9];
    float I[] = new float[9];
    boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
    if (success) {
    String s="";
      float orientation[] = new float[3];
      SensorManager.getOrientation(R, orientation);
      yaw =(int)( Math.toDegrees( orientation[0] ) + 0.5 );   // orientation contains: azimut, pitch and roll
      pitch=(int)( Math.toDegrees( orientation[1] ) + 0.5 );
      roll=(int)( Math.toDegrees( orientation[2] ) + 0.5 );//102
      if(onetime)
      { pyaw=yaw;
      ppitch=pitch;
      proll=roll;
      onetime=false;}
      if(yaw<pyaw-2 || yaw>pyaw+2) //100
      {
     s=yaw+" ";
      pyaw=yaw;}
      else
     s=pyaw+" ";
      if(pitch<ppitch-2 || pitch>ppitch+2) //102
      {s=s+pitch+" ";
      ppitch=pitch;}
      else
     s=s+ppitch+" ";
      if(roll<proll-2|| roll>proll+2) //102
      {s=s+roll+" ";
      proll=roll;}
      else
     s=s+proll+" ";
 
   
   
    tv.setText(s);s="";
 
   
   
    }
  }

}





public class Communicator extends AsyncTask<Void, String, Void> {
public static final String SERVER_IP = "192.168.3.105";
public static final int SERVERPORT = 3732;
String messsage;

private Socket client;
ObjectInputStream oIn;
ObjectOutputStream oOut;
boolean Activated=false;
public boolean online()
{
return Activated;

}
public void disarmotors() throws IOException {
armed=1;
sendDataToServer(new COM_DATA("disarm",true,4),oOut);
try {
   Thread.sleep(150);      
} catch (InterruptedException e) {
  e.printStackTrace();
}



}
public boolean offline()
{
try {
oOut.close();
oIn.close();
client.close();
return true;
} catch (IOException e) {

// TODO Auto-generated catch block
e.printStackTrace();
return false;
}



}
public Communicator(Context context)
{

   
}



private COM_DATA getDataFromServer( ObjectInputStream oIn ) throws IOException                                                                      
{
    COM_DATA  tDataFromClient = new COM_DATA("nothing",true,55);
    System.out.println(oIn.available());
 
       try {
     
     
          tDataFromClient = (COM_DATA) oIn.readObject();

         System.out.println(tDataFromClient.iRet);
       
       } catch ( ClassNotFoundException e ) {
           System.out.println( "ClassNotFound" );
       }
       catch(IOException e)
       {
        System.out.println("NO STREAM");
       
       }
       catch(ClassCastException e)
       {System.out.println("TOO FAST");}

         return tDataFromClient;
}
void armmotors() throws IOException
{armed=1;
sendDataToServer(new COM_DATA("arm",true,3),oOut);
try {
   Thread.sleep(200);      
} catch (InterruptedException e) {
  e.printStackTrace();
}

}

boolean sendDataToServer( COM_DATA tDataToClient, ObjectOutputStream  oOut ) throws IOException
{      

    oOut.writeObject( tDataToClient );
    oOut.flush();
  return true;
}

@Override
   protected void onProgressUpdate(String...arg0) {
tv.setText(arg0[0]);
 
   }
@Override
protected Void doInBackground(Void... arg0) {
int h=0;

COM_DATA datafromserver=new COM_DATA("hello",true,10);
 try {Activated=true;
 if(twotime==true){
           InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
         
           client = new Socket(serverAddr, SERVERPORT);
         
           oOut = new ObjectOutputStream( client.getOutputStream() );
       
           oIn  = new ObjectInputStream( client.getInputStream() );
     
          do{
          if(armed==1)
          {
        sendDataToServer(new COM_DATA(throttle+"",true,1),oOut);
        h++;
        if(h==2)
        sent=true;
try {
    Thread.sleep(200);      
} catch (InterruptedException e) {
   e.printStackTrace();
}
if(sent)
{
datafromserver=getDataFromServer(oIn);
if(datafromserver.iRet==8)
motorvalues=datafromserver.comData;
publishProgress(motorvalues);
try {
    Thread.sleep(50);      
} catch (InterruptedException e) {
   e.printStackTrace();
}
}

          }
          }
          while(c.online());
         }


     
           }
       catch (UnknownHostException e1) {

           e1.printStackTrace();

       } catch (IOException e1) {

           e1.printStackTrace();

       }
return null;
}

}





}