My Sites


Monday, July 20, 2015

How to make Sublime Text your best IDE :D


Package Management
https://packagecontrol.io/installation


View --> Show Console
Ctrl + Shift + P
Install Package

Essential Plug-ins
1.) Dayle Rees Color Scheme
2.) Predawn
3.) Bracket HIghlighter
4.) Sidebar Enchacement
5.) SublimeCodeIntel
6.) Emmet
7.) SublimeLinter
8.) SublimeLinter-jshint (https://github.com/SublimeLinter/SublimeLinter-jshint)
https://www.youtube.com/watch?v=zVLJfrIwEP8

Preferences --> User --> Settings --> font face : monospace 13pt 

Saturday, July 18, 2015

AWS - How to select the right Architecture for your Web Application

https://www.youtube.com/watch?v=Ypwi1Ics91Y

Hosting a static site

  1. Amazon Route 53
  2. Amazon Cloud Front
  3. Simple Storage Service (S3)

http://docs.aws.amazon.com/gettingstarted/latest/swh/website-hosting-intro.html

Single Virtual Machine Architecture
  1. Amazon Route 53
  2. Amazon Cloud Front
  3. Simple Storage Service (S3)
  4. Elastic Compute Cloud (EC2)
  5. EBS - Elastic Block Storage

Deciding the right DB service

  1. DynamoDB - NOSQL
  2. RDS - Relational Database Service
  3. EC2 - Manage DB yourself 

Monday, July 13, 2015

ComparatorChain java impl

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.0</version>
</dependency>

private TermActiveComarator activeComarator;

ComparatorChain comparatorChain = new ComparatorChain();
        comparatorChain.addComparator(activeComarator);
        comparatorChain.addComparator(startDateComparator);
        Collections.sort(list, comparatorChain);

public class TermActiveComarator implements Comparator<TermDto> {

    @Override
    public int compare(TermDto o1, TermDto o2) {
        Boolean a1 = new Boolean(o1.isActive());
        Boolean a2 = new Boolean(o2.isActive());
        return a2.compareTo(a1);

    }

}

Tuesday, July 7, 2015

Java Joda Date Time Essentials

DateTime creationDateTime = new DateTime(DateTimeZone.UTC);
2015-07-07T06:28:19.911Z

DateTime expirationDateTime=creationDateTime.plusMonths(3);
DateTime expirationDateTime=creationDateTime.minus(3)

if(expirationDateTime.isAfterNow()){

}

String datePattern = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
sdf.setTimeZone(TimeZone.getTimeZone("America/Denver"));

Date endDate= sdf.parse(termDto.getEndDateTime().substring(0,10));
Calendar endDateCal = Calendar.getInstance();
endDateCal.setTime(endDate);
endDateCal.add(Calendar.DAY_OF_MONTH, gracePeriod);
endDate = endDateCal.getTime();

Calendar cal = Calendar.getInstance();
                //cal.setTimeZone(TimeZone.getTimeZone("America/Denver"));
                cal.setTime(new Date());
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE,0);
                cal.set(Calendar.SECOND,0);
                cal.set(Calendar.MILLISECOND,0);
               
                if(stDate.compareTo(cal.getTime())<=0 && endDate.compareTo(cal.getTime())>=0){

}

DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'");
DateTime requestDateTime = dateFormatter.parseDateTime("timestamp");
DateFormat gmtFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
TimeZone gmtTime = TimeZone.getTimeZone("America/Denver");
gmtFormat.setTimeZone(gmtTime);
DateTime nowDate = dateFormatter.parseDateTime(gmtFormat.format(new Date()));

String datePattern = "yyyy-MM-dd'T'00:00:00";
        SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
        sdf.setTimeZone(TimeZone.getTimeZone("America/Denver"));
        String nowDate = sdf.format(new Date());

Convert joda datetime to Util date
.toDate()

Convert from java.util.date to JodaTime
ava.util.Date date = ...
DateTime dateTime = new DateTime(date);



Encoding vs. Encryption vs. Hashing

https://danielmiessler.com/study/encoding_encryption_hashing/

Sunday, July 5, 2015

Cookie VS Session [UNREVEALED]



The concept is storing persistent data across page loads for a web visitor. Cookies store it directly on the client. Sessions use a cookie as a key of sorts, to associate with the data that is stored on the server side.
It is preferred to use sessions because the actual values are hidden from the client, and you control when the data expires and becomes invalid. If it was all based on cookies, a user (or hacker) could manipulate their cookie data and then play requests to your site.
Edit: I don't think there is any advantage to using cookies, other than simplicity. Look at it this way... Does the user have any reason to know their ID#? Typically I would say no, the user has no need for this information. Giving out information should be limited on a need to know basis. What if the user changes his cookie to have a different ID, how will your application respond? It's a security risk.
Before sessions were all the rage, I basically had my own implementation. I stored a unique cookie value on the client, and stored my persistent data in the database along with that cookie value. Then on page requests I matched up those values and had my persistent data without letting the client control what that was.
Session:
  1. IDU is stored on server (i.e. server-side)
  2. Safer (because of 1)
  3. Expiration can not be set, session variables will be expired when users close the browser. (nowadays it is stored for 24 minutes as default in php)
Cookies:
  1. IDU is stored on web-browser (i.e. client-side)
  2. Not very safe, since hackers can reach and get your information (because of 1)
  3. Expiration can be set (see setcookies() for more information)
Session is preferred when you need to store short-term information/values, such as variables for calculating, measuring, querying etc.
Cookies is preferred when you need to store long-term information/values, such as user's account (so that even when they shutdown the computer for 2 days, their account will still be logged in). I can't think of many examples for cookies since it isn't adopted in most of the situations.
SESSIONS ENDS WHEN USER CLOSE HIS BROWSER,

COOKIES ENDS DEPENDING ON THE LIFE TIME YOU SET FOR IT. SO IT CAN LAST FOR YEARS

“No 'Access-Control-Allow-Origin' header is present on the requested resource” SOLUTION

XMLHttpRequest cannot load http://myApiUrl/login. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.
//Create a parseData json object
var parseData = {token : userToken};

var request = $.ajax({
        url: "http://localhost:8080/configurations/authenticate",
        type: "post",
        data: parseData
    });

http://davidwalsh.name/cdn-fonts
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://grid-static-stg.pearson.com/57-mlpui/0.0.4/assets/fonts/pearson-symbols/pearson-symbols.ttf. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

 

Center a column using Twitter Bootstrap 3

http://stackoverflow.com/questions/18153234/center-a-column-using-twitter-bootstrap-3

https://shapebootstrap.net
http://www.wpfreeware.com/tutorial/outstanding-bootstrap-ecommerce-templates-free-premium/

The first approach uses Bootstrap's own offset classes so it requires no change in markup and no extra CSS. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2.
In markup this would look like:
<div class="row">
    <div class="col-md-2 col-md-offset-5"></div>
</div>

Friday, July 3, 2015

JQuery form submit + HTML 5 place holder conflict SOLUTION

<form id="sampleForm" >
  <input type="text" id="studentID" required />
  <button type="submit"> Submit </button>
</form>

$('#sampleForm').on('submit', function(e) { //use on if jQuery 1.7+        
e.preventDefault();  //prevent form from submitting/refreshing       
    });

MODAL SOLUTION
$('#myModal').modal('toggle');