Saturday, September 26, 2015

Encryption with JavaScript

DIGEST

digest.js is a javascript library implementing cryptographic digest and HMAC algorithms.
digest.js is designed for modern web browsers and requires the W3C Typed Arrays support. digest.js has been successfully tested with these web browsers:
  • Chrome 11
  • Firefox 4
  • Safari 5.1
  • IE 10

Supported algorithms:

  • digest
    • MD5
    • SHA-1
    • SHA-256
  • Message Authentication Code (MAC)
    • HMAC/MD5
    • HMAC/SHA-1
    • HMAC/SHA-256
  • Password-Based Key Derivation Function (PBKDF)
    • PBKDF1/SHA1
    • PBKDF1/MD5
    • PBKDF2/HMAC/SHA1
    • PBKDF2/HMAC/SHA-256


Monday, August 17, 2015

Proxy Coding: Take control with the Proxy

Provide a surrogate or placeholder for another object to control access to it.

If the programming model for your distributed technology of choice includes the concept of a proxy, you're being forced into distributed object semantics

Monday, May 13, 2013

DATE with BASH Shell

Was struggling to get date validated in linux ... writing a script with all that date parsing checks (valid day, month etc.) naah there mus be some easy way, something that is built in. The OS itself manages date and time so it should have the logic built in. Why not leverage it.

Came across this date command in shell, which is designed to handle relative date calculations and return/print them to you in a user defined way.

Everyone is familiar with the $ date command

cmd:   $ date
result:  Tue May 14 07:47:45 IST 2013 


Now getting the previous day
cmd:   $ date --date="yesterday"
result:  Tue May 13 07:50:35 IST 2013 



Now getting the next day
cmd:   $ date --date="next day"
result:  Tue May 15 07:50:55 IST 2013 

Looks  great isn't it and not only this one can use different string formats to get the same output
Example

cmd:   $ date --date="1 days ago"   or
cmd:   $ date --date="1 day ago"  or
cmd:   $ date --date="-1 day"    or
cmd:   $ date --date="yesterday"    
result:  Tue May 13 07:50:35 IST 2013



Example of various string formats is
Past:
cmd:   $ date --date="yesterday"
cmd:   $ date --date="20 minute ago"
cmd:   $ date --date="2 hour ago"
cmd:   $ date --date="last Friday"
cmd:   $ date --date="10 days ago"
cmd:   $ date --date="10 week ago"
cmd:   $ date --date="10 month ago"

Future:
cmd:   $ date --date="tommorrow"
cmd:   $ date --date="20 minute"
cmd:   $ date --date="2 hour"
cmd:   $ date --date="this Friday"
cmd:   $ date --date="10 days "
cmd:   $ date --date="10 week"
cmd:   $ date --date="10 month "


Its amazing... very nicely coded and not only this you can specify your custom date format

cmd:   $ date --date="tommorrow" + "%d/%m/%Y"

Hope you find it interesting and helpful too..

Have a nice time playing with your dates. -S

Sunday, March 3, 2013

UPDATE .. FROM syntax difference in Sql Server and Oracle


There is syntactical difference in few operations in SQL in Oracel and Sql server

For example: UPDATE .. FROM

UPDATE students
     SET grade='A'
FROM students s 
INNER JOIN students_marks sm ON sm.student_id = s.student_id
WHERE sm.total_marks>80;

The above query syntax works in Sql Server but will fail in Oracle.

Below is the Oracle alternative.

UPDATE 
     (SELECT grade 
             FROM students s
             INNER JOIN students_marks sm ON sm.student_id = s.student_id
             WHERE sm.total_marks>80) t 
SET t.grade='A';


Below is the block diagram for the Oracle query



Wednesday, January 30, 2013

Find when a DB Object was created in ORACLE


I came across a requirement where I need to find when a table on the schema was modified. I am posting the solution here so as my other fellow programmers can get the idea.

SELECT * FROM  all_objects
WHERE  owner = 'object_owner'
AND object_name = 'object_name'

The column "CREATED" tells you when the object was created. The column "LAST_DDL_TIME" tells you when the last DDL was performed against the object.

Example:

SELECT created
FROM all_objects
WHERE object_name = 'my_table'
AND owner = 'sysdba'
AND object_type = 'TABLE'

It will tell you when a table was created.

The odds are good, but the goods are odd-S

Saturday, November 10, 2012

Awesome Java NIO

Easy File Reading

public static List getNamesFromFile(String filetoread)
{
 List lines = null;    
 try
 {
  lines = Files.readAllLines(Paths.get(filetoread), Charset.forName("UTF-8"));
 }
 catch(Exception e)
 {
  System.out.println("Error reading list file \n " + e);     
 }

 return lines;
} // end getNames




Easy File Copy

public static void copyFile(File src, File dest) throws IOException
{
 if (!src.exists())
 {
  // either return quietly OR throw an exception
  return;
 }

 if (!dest.exists())
 {
  dest.createNewFile();
 }

 try
 {
  FileChannel source = new FileInputStream(src).getChannel();
  FileChannel destination = new FileOutputStream(dest).getChannel();

  try
  {
   source.transferTo(0, source.size(), destination);
   // destination.transferFrom(source, 0, source.size());
  }
  finally
  {
   if (destination != null)
   {
    destination.close();
   }
  }
 }
 finally
 {
  if (source != null)
  {
   source.close();
  }
 }

} // function ends

 


Neo here is new NIO. -S

Monday, October 29, 2012

CSS ... Selectors to be learned

SelectorExampleExample descriptionSince CSS versionSupported in
.class.introSelects all elements with class="intro"1 IE6+ Firefox Chrome Safari Opera
#id#firstnameSelects the element with id="firstname"1 IE6+ Firefox Chrome Safari Opera
**Selects all elements2 IE6+ Firefox Chrome Safari Opera
elementpSelects all elements1 IE6+ Firefox Chrome Safari Opera
element,elementdiv,pSelects all
elements and all elements
1 IE6+ Firefox Chrome Safari Opera
element elementdiv pSelects all elements inside
elements
1 IE6+ Firefox Chrome Safari Opera
element>elementdiv>pSelects all elements where the parent is a
element
2 IE6+ Firefox Chrome Safari Opera
element+elementdiv+pSelects all elements that are placed immediately after
elements
2 IE6+ Firefox Chrome Safari Opera
[attribute][target]Selects all elements with a target attribute2 IE6+ Firefox Chrome Safari Opera
[attribute=value][target=_blank]Selects all elements with target="_blank"2 IE6+ Firefox Chrome Safari Opera
[attribute~=value][title~=flower]Selects all elements with a title attribute containing the word "flower"2 IE6+ Firefox Chrome Safari Opera
[attribute|=value][lang|=en]Selects all elements with a lang attribute value starting with "en"2 IE6+ Firefox Chrome Safari Opera
:linka:linkSelects all unvisited links1 IE6+ Firefox Chrome Safari Opera
:visiteda:visitedSelects all visited links1 IE6+ Firefox Chrome Safari Opera
:activea:activeSelects the active link1 IE6+ Firefox Chrome Safari Opera
:hovera:hoverSelects links on mouse over1 IE7+ Firefox Chrome Safari Opera
:focusinput:focusSelects the input element which has focus2 IE8+ Firefox Chrome Safari Opera
:first-letterp:first-letterSelects the first letter of every element1 IE8+ Firefox Chrome Safari Opera
:first-linep:first-lineSelects the first line of every element1 IE8+ Firefox Chrome Safari Opera
:first-childp:first-childSelects every element that is the first child of its parent2 IE8+ Firefox Chrome Safari Opera
:beforep:beforeInsert content before the content of every element2 IE7+ Firefox Chrome Safari Opera
:afterp:afterInsert content after every element2 IE7+ Firefox Chrome Safari Opera
:lang(language)p:lang(it)Selects every element with a lang attribute value starting with "it"2 IE8+ Firefox Chrome Safari Opera
element1~element2p~ulSelects every
    element that are preceded by a element
3 IE8+ Firefox Chrome Safari Opera
[attribute^=value]a[src^="https"]Selects every element whose src attribute value begins with "https"3 IE8+ Firefox Chrome Safari Opera
[attribute$=value]a[src$=".pdf"]Selects every element whose src attribute value ends with ".pdf"3 IE8+ Firefox Chrome Safari Opera
[attribute*=value]a[src*="coffee"]Selects every element whose src attribute value contains the substring "coffee"3 IE8+ Firefox Chrome Safari Opera
:first-of-typep:first-of-typeSelects every element that is the first element of its parent3 IE8+ Firefox Chrome Safari Opera
:last-of-typep:last-of-typeSelects every element that is the last element of its parent3 IE8+ Firefox Chrome Safari Opera
:only-of-typep:only-of-typeSelects every element that is the only element of its parent3 IE8+ Firefox Chrome Safari Opera
:only-childp:only-childSelects every element that is the only child of its parent3 IE8+ Firefox Chrome Safari Opera
:nth-child(n)p:nth-child(2)Selects every element that is the second child of its parent3 IE8+ Firefox Chrome Safari Opera
:nth-last-child(n)p:nth-last-child(2)Selects every element that is the second child of its parent, counting from the last child3 IE8+ Firefox Chrome Safari Opera
:nth-of-type(n)p:nth-of-type(2)Selects every element that is the second element of its parent3 IE8+ Firefox Chrome Safari Opera
:nth-last-of-type(n)p:nth-last-of-type(2)Selects every element that is the second element of its parent, counting from the last child3 IE8+ Firefox Chrome Safari Opera
:last-childp:last-childSelects every element that is the last child of its parent3 IE8+ Firefox Chrome Safari Opera
:root:rootSelects the document’s root element3 IE9+ Firefox Chrome Safari Opera
:emptyp:emptySelects every element that has no children (including text nodes)3 IE9+ Firefox3+ Chrome Safari Opera
:target#news:target Selects the current active #news element (clicked on a URL containing that anchor name)3 IE8+ Firefox Chrome Safari Opera
:enabledinput:enabledSelects every enabled input element3 IE9+ Firefox3+ Chrome Safari Opera
:disabledinput:disabledSelects every disabled input element3 IE9+ Firefox3+ Chrome Safari Opera
:checkedinput:checkedSelects every checked input element3 IE9+ Firefox3+ Chrome Safari Opera
:not(selector):not(p)Selects every element that is not a element3 IE9+ Firefox Chrome Safari Opera
::selection::selectionSelects the portion of an element that is selected by a user3 IE6+ Firefox Chrome Safari Opera

Selecting the selectors. -S