Skip to content

Instantly share code, notes, and snippets.

@l0co
l0co / angular-global-state.js
Created May 9, 2014 13:04
Global state in AngularJS controllers
myModule.service('state',
function () {
/** The global/shared modules state (filled in modules.run) **/
this.global = {};
/**
* Initializes the scope state. If the scope state is already initialized and kept from previous invocation,
* the scope is initialized using the previous state. If the scope state doesn't exist, the scope is initialized
* using the initFunc.
@l0co
l0co / atmosphere_spring.java
Last active August 29, 2015 14:04
Atmosphere + Spring
// web.xml
<!-- Atmosphere servlet -->
<servlet>
<servlet-name>async</servlet-name>
<servlet-class>org.atmosphere.cpr.MeteorServlet</servlet-class>
<init-param>
<param-name>org.atmosphere.servlet</param-name>
<param-value>org.springframework.web.servlet.DispatcherServlet</param-value>
</init-param>
package com.blogspot.lifeinide.async.service
import org.apache.commons.lang3.StringUtils;
import org.atmosphere.cpr.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
import org.springframework.stereotype.Service;
@l0co
l0co / ReferenceSimple.js
Last active August 29, 2015 14:06
Simple reference tracker for javascript
/**
* Creates new reference manager
* @constructor
*/
function Reference() {
function RefHolder() {
this.assignFunc = [];
}
@l0co
l0co / ReferenceRecursive.js
Created September 21, 2014 19:17
Recursive reference tracker for JavaScript based on unique ID
/**
* Creates new reference manager
* @param {function(object)} idFunc returning string representing unique ID of object
* @constructor
*/
function Reference(idFunc) {
this.idFunc = idFunc;
function RefHolder(id) {
this.id = id;
@l0co
l0co / LockService.java
Last active August 29, 2015 14:08
Service for locking rows in postgres using select for update
package com.blogspot.lifeinide.postgres.locks;
import org.hibernate.SessionFactory;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.jdbc.Work;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@l0co
l0co / DeadlockDetectAspect.java
Created October 27, 2014 19:37
AOP aspect to retry transaction on deadlock
package com.blogspot.lifeinide.postgres.locks;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.hibernate.exception.LockAcquisitionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = BaseEnity.DISCRIMINATOR_COLUMN, discriminatorType = DiscriminatorType.STRING, length = 255)
public class Company extends BaseEnity {
protected String name;
@OneToMany(mappedBy = "company")
@Cascade(CascadeType.ALL)
protected List<Department> departments = new ArrayList<Department>();
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = BaseEnity.DISCRIMINATOR_COLUMN, discriminatorType = DiscriminatorType.STRING, length = 255)
public class Department extends BaseEnity {
@ManyToOne
protected Company company;
protected String name;
public class MockCompanyDataSet {
protected int idx = 10;
public Object next() {
if (idx--==0) // stop iteration on 10 objects
return null;
Company company = PojoHelper.createCompany("Mock ");
company.setId(10-idx);