tag:blogger.com,1999:blog-38304277680904894462024-03-13T16:21:58.985+05:30Amod Pandey - My WorkshopThere is a lot that human can do, for everything else there is [shell] script :)Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.comBlogger50125tag:blogger.com,1999:blog-3830427768090489446.post-32169535895593491922017-01-16T01:46:00.001+05:302017-01-16T01:46:38.599+05:30Angular Factory for $resource and dynamic header content
I created a Factory recipe for my $resource instance.
There are multiple ways to create it. I used this approach.
angular.
module('myModule').
factory('myService', ['$resource', '$localStorage',
function($resource, $localStorage) {
var url = 'xxx';
return $resource(url + '/Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-29319170539126630592016-12-22T00:08:00.002+05:302016-12-22T00:08:47.291+05:30Sublime copying all text that match a pattern
I had a text file containing numbers in between text that I wanted to copy, move to a new file and format them.
Since the numbers were of of fixed length and at the same index I could have copied them using vertical select. The vertical select is tricky if the file is big and it wouldn't help if the pattern to looks for is different and can occur anywhere in the text.
I knew the first way was Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-56986678186636789392016-12-21T22:49:00.004+05:302016-12-21T22:49:55.893+05:30Creating a dynamic table out of list of numbers to join
I had a list of ids and I wanted to check which rows are not present in the DB.
We can use 'in (1, 2, 3)' and that would say which ones are in, and 'not in' would return rows outside the ids I had.
So I wanted to make a table out of the ids and use left or right join.
I could not find any simple way of doing this and then the approach mentioned here http://stackoverflow.com/questions/8002178Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-84879139955186846742016-12-20T21:48:00.000+05:302016-12-20T21:55:10.871+05:30Query join with View - Oracle Performance
I had a slow running query that joined on two views, A and B. I had this wrong understanding that the query is slow as it prepares the whole view and then runs the query on the view. This was totally incorrect.
Consider view in a join as a sub-query. The optimizer would try to minimize the cost.In my case the join with view A performed better than the join with view B. Both had approximately Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-80484021390544830412016-08-18T19:39:00.000+05:302016-08-18T19:39:21.310+05:30Avro - schema change compatibility
I was under the impression that I can add an optional field to Avro schema and consumers with old schema would still be able to read the message whether or not the newly added optional filed is set or not in the record.
So I added an optional field to an Avro schema, generated an Avro from it and I was able to read it from consumers using the old and new schema (this might not work if the Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com3tag:blogger.com,1999:blog-3830427768090489446.post-83014775473733252692016-03-29T15:42:00.000+05:302016-03-29T15:42:36.164+05:30Map.get - KeyNotFound error
It is interesting how different languages approach towards a given problem.
Let's have a look at how different languages react while trying to read a key from dictionary
Java
map.get('key_that_does_not_exist')
=> null
Ruby
map['key_that_does_not_exist']
=> nil
Python
>> x['key_that_does_not_exist']
Traceback (most recent call last):
FileAmodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-91842310875345335492015-02-22T19:09:00.002+05:302015-02-22T19:09:37.178+05:30JDK in OSX
I wanted to figure out the Java installation on OSX so that I can easily switch between JDK 6,7 and 8.
I got my answer from this post http://stackoverflow.com/questions/15120745/need-help-understanding-oracles-java-on-mac
In summary
When we install Java using a dmg it goes here /Library/Java/JavaVirtualMachines/
This command is handy to figure this out
$ /usr/libexec/java_home
Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-49290597425723113282015-01-11T21:32:00.001+05:302015-02-22T19:58:17.519+05:30eclipse
Adding more support to your eclipse (say you have only Java support and you want to add web support)
1. Download eclipse with Web support
2. Or, add required module through Help - Install New Software - http://download.eclipse.org/releases/luna (your release)
Extract the downloaded zip/tar. Run ./eclipse or double click the Eclipse App from inside the downloaded folder. Eclipse needs javaAmodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-80885410073909220072015-01-11T20:42:00.004+05:302015-02-22T20:06:51.891+05:30eclipse and maven
I have become a fan of Maven (there is no surprise to it).
Download and install instructions (bottom of the page) on this page http://maven.apache.org/download.cgi. It is better to use the zip/gz and set the appropriate env than using the yum installation.
Default repository location - ~/.m2
Settings.xml - ls $M2_HOME/conf
Maven eclipse integration - http://maven.apache.org/Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-57450959326256408162014-07-13T18:58:00.001+05:302014-07-13T18:58:47.127+05:30Exception - How to manage different exceptions your code wants to throw?
Often I have seen multiple Exception types created to handle different types of exceptions. In Java they all become individual classes. They might all extend from a common Exception class defined by you. But as Java does not support inheritance of constructors we end up having multiple classes with similar code. Not if it was Ruby code :)
Anyways. I got the following thought from the way Http Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-41197891531029992952014-06-12T15:05:00.000+05:302014-06-12T15:05:07.410+05:30Oracle Database - reading a CLOB through sqlplus
If you execute through sqlplus 'select <clob column>' you will get truncated data. To see the complete data in sqlplus
set buffer <X>
select DBMS_LOB.substr(column, <buffer size>) from table
Note: This is required for sqlplus. JDBC and hibernate handle it directly so this 'select column' should be good enough.
Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-42749080747966169952014-06-11T01:53:00.000+05:302014-06-11T01:53:00.391+05:30SQL equal or not equal and Mr NULL
I created a table with a column
IS_CONFIDENTIAL CHAR(1)
and I added this clause to my query if the user should not see the confidential data
AND IS_CONFIDENTIAL <> 'Y'
Now the user could not see the confidential records. All good!
But he could not see few other records which were not confidential ?? I checked the table and found records with IS_CONFIDENTIAL values 'Y','N' and NULL andAmodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-42412675644665548572014-06-11T01:36:00.002+05:302014-06-11T01:53:30.579+05:30curl command to error out on HTTP error codes
$ curl -I -f "http://json.org/example"
HTTP/1.1 200 OK
Date: Tue, 10 Jun 2014 20:01:02 GMT
Server: Apache
...
Ah! but it does not provide the / at the tail. We get a 404.
$ curl -I "http://json.org/example/"
HTTP/1.1 404 Not Found
Date: Tue, 10 Jun 2014 20:01:15 GMT
Server: Apache
...
echo $? will return 0 in both the case.
What if we are using it inside a script and want Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-48959792230763925042014-05-20T12:14:00.001+05:302014-05-20T12:14:10.886+05:30session_privs and session_roles
So my friend was getting 'SYS.DBA_IND_COLUMNS table does not exit' while he was trying to run
desc dba_ind_coulmns
I was able to run the same query. So of course we are in the territory of authorizations. But how do I prove it?
Then can session_privs and session_roles into picture. For me the result was
SQL> select * from session_privs;
PRIVILEGE
----------------------------------------
Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-46012932539786881102014-05-09T20:44:00.000+05:302014-06-06T18:55:09.828+05:30Git commands
> Log commits for a user since. Print in one line and with abbreviated commit
git log --committer=appandey --no-merges --since=2014-04-24 --pretty=oneline --abbrev-commit
> add all java files
git add \*.java
> Commit on someone else's behalf (same team)
git commit --author='author' -m '..'
fatal: No existing author found with 'author'
git commit --author='author <author@Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-6298367791004452692014-05-05T23:41:00.000+05:302014-05-05T23:41:05.279+05:30Did you know java TimeUnit class
I am not sure why Date din't do it, Calendar didn't do it and Apache DateUtils didn't do it?
Though every other product in every other company would need date diff !!!
I was introduced to TimeUnit through a retry wrapper class where I had to specify retry time using TimeUnit. So no longer we need a variable like private static final long numberOfSecondsInMinutes = 60; :)
Date diff is a Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com1tag:blogger.com,1999:blog-3830427768090489446.post-14103199776875364692014-04-18T20:44:00.000+05:302014-04-18T20:46:36.747+05:30Http Accept - 406
There are many HTTP headers which go unnoticed. Accept is one such header.
Accept is a way to tell the server what the client accepts. A server can smartly handle this.
e.g. Accept: application/xml to a service returns xml and Accept: application/json to same end point should return json.
Sometimes we have the server side code as to strictly say we support requests with Accept: application/Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-69832910882828500562014-03-02T23:15:00.002+05:302014-03-02T23:30:06.749+05:30The Orthodox: Java getter and setter
Let me start by saying, 'I hate it'. I always wrote it for the sake of writing it. Before making any decision I would like to bounce it with the community.
In the recent years most of us write Java classes that fall into one of these categories.
1. The so called POJO - Only attributes with getters and setters. Mostly used for serialization/de-serialization (to DB row, to JSON, to XML or any Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-51823764557169771912013-12-18T18:02:00.001+05:302013-12-18T18:04:16.342+05:30Third party calls (CORS), cookies and more...
1. Cookies set from the parent domain are by default not sent to the third party domain in xhr calls even if they from the common parent.
e.g. a.example.com and b.example.com
withCredential = true does the trick
2. Cookies set by the third party domain are not set on the client. The client ignores those headers.
Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-79440999771480588692013-12-18T17:54:00.000+05:302013-12-18T17:54:01.805+05:30Hibernate: OneToOne Mapping and fetch type
If a bean has a property that has mapping that is OneToOne mapping it is better to make the FetchType to EAGER.
EAGER FetchType will add to the main query.
LAZY makes the property to be loaded later, but is not the case with OneToOne mapping. After the bean is loaded all the OneToOne properties are loaded through a separate query if the FetchType is LAZY and will slow the loading.
Take away: Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-54062849149201335212013-12-18T17:43:00.003+05:302013-12-18T17:55:40.882+05:30Dojo: Download a file with GET/POST
There is a old trick to use iframe and its src to download a file. The same can be achieved through
dojo.io.iframe.send(xhrArgs)
http://livedocs.dojotoolkit.org/dojo/io/iframe
the dojo.io.iframe.send takes same parameter as xhrGet or xhrPost. And no iframe component is required!
sample
xhrArgs = {
url: "service endpoint",
form: "formid",
content: ""
}
<form method="Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-3851345387338202532013-09-01T20:16:00.001+05:302013-09-01T20:16:21.382+05:30Financial figures? BigDecimal, yes it is!!
If you have to show high value financial figures BigDecimal should be the right type to use.
Float and Double would not show the correct value even if there is no decimal part to it because of the nature of their storage. Yes, BigDecimal is little expensive than Float or Double but you would not mess with financial figures.
e.g.
"342345345"
Float.valueOf("342345345") = 342345344
Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-24257539115456345202013-09-01T19:16:00.001+05:302013-09-02T23:51:02.178+05:30RESTful - to PUT or to POST
This is an effort to simplify your decision making.
Reference
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
PUT
1. If the resource created/modified is represented by the URI
http://myservice.com/users/xyz
The body should contain data about xyz. If xyz is not found it is created else updated. Based on this
201, 200 or 204 is returned. In PUT the call is handles by the resource.
If Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com1tag:blogger.com,1999:blog-3830427768090489446.post-30389185551190557352013-08-26T00:08:00.001+05:302013-09-01T21:17:35.674+05:30Video streaming - little 'bit'
I want to show a video on my website?
There are two ways:
1. Upload it on a video hosting site and use the embed URL
2. Use your own js player and source it from a streaming server
So what is a streaming server?
There are various protocols for streaming. RTSP kind of proprietary from Adobe has ruled the world with flash players. But now we are moving back to HTTP.
In streaming what is Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0tag:blogger.com,1999:blog-3830427768090489446.post-68724343290069439092013-08-11T23:18:00.000+05:302013-08-11T23:58:02.478+05:30blackday for yatra.com
I opened yatra.com and it was not the one I was looking for !! What the hell happened??
The message was to renew domain. Even more surprising!! I looked on whois and found yatra.com has expired on 9th Aug! How can a big company like yatra could do such a mistake?? I know Monday it will be alarming for so many companies.
$ dig ns yatra.com
; <<>> DiG 9.8.3-P1 <<>> ns Amodhttp://www.blogger.com/profile/15519854619280595564noreply@blogger.com0