Skip to content

Instantly share code, notes, and snippets.

@bmakarand2009
bmakarand2009 / gist:37c0ef8ac249b87f1ae7
Created August 29, 2014 23:58
How to use $last to run JQuery script after angular ngRepeat has loaded the table
//Step1 -- ngRepeat directive to go through all the rows in the table
//emp.html - we see a snipped code which is conrolled by the empController
<div ng-controller="empController">
<table id="myTable" class="emp-table">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
</tr>
@bmakarand2009
bmakarand2009 / highlightSelectedRow
Created August 27, 2014 20:55
highlight the selected row in a table when user clicks it
//Step 1. on ng-click call a method and pass the $index to it. say select($index).
//Note - $index is a property of ng-Repeat and represents the index of the selected row
<div ng-controller ="MyCtrl">
<tr ng-repeat="car in cars" ng-click="select($index)">
<td>..</td>
<tr>
</div>
//Step2 - On MyCtrl Controller, store the index
$scope.select = function(index){
$scope.index = index
@bmakarand2009
bmakarand2009 / hibernateBatch
Last active August 29, 2015 13:56
Hibernate Iterate throught Batches
//The query for the books:
//Reference : http://www.laliluna.de/articles/java-persistence-hibernate/performance-tips-hibernate-java-persistence.html
List<Book> books = session.createQuery(
“from Book b where b.name like ?”).setString(0, “Java%”).list();
/* The following code printing the books will create one SQL query per
book to initialize the chapters. We get 1+n queries in total. One for
the books and n for the chapters, if we have n books.
@bmakarand2009
bmakarand2009 / Hibernate-Statistics
Created February 6, 2014 07:46
Get the Hibernate Statistics
package com.webforefront.aop;
import org.hibernate.stat.Statistics;
import org.hibernate.SessionFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.EntityManagerFactory;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.apache.commons.logging.Log;
@bmakarand2009
bmakarand2009 / JPA-Timer
Created February 6, 2014 07:17
Measure the peformance of a JPA Query
package com.webforefront.aop;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Aspect;
@Aspect
@bmakarand2009
bmakarand2009 / gist:7478354
Created November 15, 2013 02:52
parse xml file
private def parseXmlClosure = { pRoot,parentObj,user,curId ->
def xmlMap=[:]
def rootName = pRoot.name()
def domainClz = SingUtils.DOMAIN_OBJECTS_MAP."${rootName}"
log.debug "domainc lass loaded as ${domainClz}"
def curObj=null
if(curId) {
curObj = domainClz.get(curId)
}
@bmakarand2009
bmakarand2009 / gist:7468039
Created November 14, 2013 14:46
Angular way of creating header and footers
<html ng-app="testApp"> <!-- remember testApp defines that this is angular app, you can define it at downlevels too -->
<!-- your css files -->
<head>
<link rel="stylesheet" href="css/style.default.css" type="text/css" />
<link rel="stylesheet" href="css/style.navyblue.css" type="text/css" />
<link rel="stylesheet" href="css/responsive-tables.css">
<script src="js/lib/angular/angular.js"></script>
<script src="js/lib/angular/angular-resource.js"></script>
<script src="js/app.js"></script>
<script>
@bmakarand2009
bmakarand2009 / noop
Last active December 27, 2015 13:19
angular goodness - angular.noop() function
//do nothing on the success callback, hence replacing the success callbck function with angular.noop()
$scope.contacts= Contacts.query( angular.noop,function(response) {
Window.myresp = response;
$scope.displayError(response);
console.log("bad boy, listContacts failed");
});
@bmakarand2009
bmakarand2009 / Groovy Goodness
Last active December 21, 2015 14:09
Convert List to Customized String in Groovy
Happy Coding!
@bmakarand2009
bmakarand2009 / javascript object literal
Created October 8, 2012 02:04
Javascript Object Literal
//http://jsfiddle.net/mbhatamb/4JYQH/
//Below is the Description of Employee Object, in a simple way
Employee e = new Object();
e.firstName = "John";
e.lastName = "tester";
e.getFullName = new function() {
return this.firstName + " " + this.lastName;
}
console.log(e.getFullName());