Skip to content

Instantly share code, notes, and snippets.

View MichaelAstreiko's full-sized avatar

Michael MichaelAstreiko

  • Belarus, Minsk
View GitHub Profile
import static groovyx.net.http.Method.GET
import static groovyx.net.http.Method.POST
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
import org.apache.commons.lang.BooleanUtils
import org.apache.commons.httpclient.methods.multipart.Part
import org.apache.commons.httpclient.methods.multipart.StringPart
import com.nearme.portal.http.MultipartEntityWrapper
import grails.converters.JSON
import com.nearme.portal.domain.authentication.User
@MichaelAstreiko
MichaelAstreiko / DojoCheckCheckboxes
Created September 21, 2012 17:10
Check all checkboxes with name like ...
dojo.forEach(dojo.query('[id*=del-campaign]'), function(single) {
dojo.attr(single, "checked", true);
});
@MichaelAstreiko
MichaelAstreiko / file1.groovy
Created September 6, 2012 14:32
Find similar words
import uk.ac.shef.wit.simmetrics.similaritymetrics.Soundex
boolean isSamePlace = false
Soundex soundexAlgorithm = new Soundex()
if(distanceBetweenVenues(place1, place2) < 200 && soundexAlgorithm.getSimilarity(placeName1, placeName2) > 0.98) {
isSamePlace = true
}
@MichaelAstreiko
MichaelAstreiko / file1.groovy
Created September 6, 2012 14:25
Find Algorithm for similarities
/**
* Made test of three word comparison algorithms:
* JaroWinkler, SmithWatermanGotoh and Soundex
*
* Based on test result Soundex is chosen to be used in venue title merging algorithm
* It is more usable, so that I can say if similarity > 0.98 then is same word
*/
void testMergeAlgorithms() {
def cafeName1 = "Antonio Cafe"
def cafeName2 = "Antonio's Cafe"
@MichaelAstreiko
MichaelAstreiko / file1.groovy
Created September 6, 2012 14:19
Haversine algorithmus
double EARTH_RADIUS = 6371
/**
* Calculate distance based on Haversine algorithmus
* (thanks to http://www.movable-type.co.uk/scripts/latlong.html)
*
* @param latitudeFrom
* @param longitudeFrom
* @param latitudeTo
* @param longitudeTo
* @return distance in Kilometers
@MichaelAstreiko
MichaelAstreiko / gist:2361373
Created April 11, 2012 18:55
DataSource properties
properties {
/** The maximum number of active connections that can be allocated from
* this pool at the same time, or zero for no limit.
* Make it '-1' to prevent performance problems with idle connections
*/
maxActive = -1
/**
* The maximum number of active connections that can remain idle in the
* pool, without extra ones being released, or zero for no limit.
*/
@MichaelAstreiko
MichaelAstreiko / gist:2339580
Created April 8, 2012 19:56
Register Custom Marshallers
JSON.registerObjectMarshaller(new UserClassMarshaller(), 155)
JSON.registerObjectMarshaller(new SimpleDomainClassMarshaller(), 150)
@MichaelAstreiko
MichaelAstreiko / gist:2339545
Created April 8, 2012 19:47
UserClassMarshaller
class UserClassMarshaller extends SimpleDomainClassMarshaller {
private Map ALTERNATIVE_NAMES = ["username":"screenName"]
protected List getSkippedFields() {
return ["password", "email", "enabled", "accountExpired", "accountLocked",
"passwordExpired", "securityQuestion", "securityAnswer"]
}
protected String getAlternativeName(String originalName){
return ALTERNATIVE_NAMES[originalName]
@MichaelAstreiko
MichaelAstreiko / gist:2339498
Created April 8, 2012 19:35
New DomainClassMarshaller
class SimpleDomainClassMarshaller extends DomainClassMarshaller {
protected static final Log log = LogFactory.getLog(BaseDomainClassMarshaller.class)
protected ProxyHandler proxyHandler
private static List SKIPPED_FIELDS = Arrays.asList("lastUpdated", "dateCreated", "createdBy", "class", "id");
public SimpleDomainClassMarshaller() {
this(false, new HibernateProxyHandler());
}
@MichaelAstreiko
MichaelAstreiko / gist:2339446
Created April 8, 2012 19:25
Process API call in Controller
def list = {
def domainNameInPluralForm = params.domainInPlural
def domainName = retrieveDomainName(domainNameInPluralForm)
def entity = grailsApplication.getArtefacts("Domain").find {
it.getShortName() == domainName
}?.clazz
def result = entity.list(params)
def converter = [domainNameInPluralForm:result] as JSON