Skip to content

Instantly share code, notes, and snippets.

View kevintanhongann's full-sized avatar
🏠
Working from the cafe

Kevin H.A Tan kevintanhongann

🏠
Working from the cafe
View GitHub Profile
@kevintanhongann
kevintanhongann / gist:595c601909d1814641b8
Created March 6, 2015 10:06
An example on what type of volley android errors can be used
public void onErrorResponse(VolleyError error) {
int statusCode = error.networkResponse.statusCode;
NetworkResponse response = error.networkResponse;
Log.d("testerror",""+statusCode+" "+response.data);
// Handle your error types accordingly.For Timeout & No connection error, you can show 'retry' button.
// For AuthFailure, you can re login with user credentials.
// For ClientError, 400 & 401, Errors happening on client side when sending api request.
// In this case you can check how client is forming the api and debug accordingly.
// For ServerError 5xx, you can do retry or handle accordingly.
@kevintanhongann
kevintanhongann / CustomRestInterceptor.groovy
Last active December 26, 2021 21:35
This is a Grails custom REST interceptor that validates auth token with Firebase auth to authenticate to a Grails server.
package haulage.project
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.HttpResponseException
import static javax.servlet.http.HttpServletResponse.*
class CustomRestInterceptor {
@kevintanhongann
kevintanhongann / BootstrapTagLib.groovy
Created August 30, 2019 06:20
Paginate taglib that is themed with Bootstrap 3/4
import grails.util.TypeConvertingMap
import grails.web.mapping.UrlMapping
import org.springframework.web.servlet.support.RequestContextUtils
class BootstrapTagLib {
static namespace = "boots"
Closure paginate = { Map attrsMap ->
TypeConvertingMap attrs = (TypeConvertingMap)attrsMap
@kevintanhongann
kevintanhongann / application.yml
Created March 24, 2019 04:56
example-micronaut-gorm application.yml
micronaut:
application:
name: example-micronaut-gorm
dataSource:
pooled: true
dbCreate: create-drop
url: jdbc:h2:mem:devDb
driverClassName: org.h2.Driver
username: sa
password:
@kevintanhongann
kevintanhongann / gist:8f3d7b72a5a35595be113d94a571e8f2
Last active March 9, 2019 05:30
example-micronaut-gorm commands
1. Install SDKMAN
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk version
2. Install Micronaut through sdk command
@kevintanhongann
kevintanhongann / PersonController.groovy
Created March 8, 2019 04:21
example-micronaut-gorm code snippet 5
package example.micronaut.gorm.controller
import example.micronaut.gorm.domain.Person
import example.micronaut.gorm.service.PersonService
import io.micronaut.http.HttpResponse
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Delete
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post
import io.micronaut.http.annotation.Put
@kevintanhongann
kevintanhongann / Bootstrap.groovy
Created March 8, 2019 04:19
example-micronaut-gorm code snippet 4
package example.micronaut.gorm
import example.micronaut.gorm.domain.Person
import example.micronaut.gorm.service.PersonService
import io.micronaut.context.event.StartupEvent
import io.micronaut.runtime.event.annotation.EventListener
import javax.inject.Singleton
@Singleton
@kevintanhongann
kevintanhongann / PersonService.groovy
Created March 8, 2019 04:04
example-micronaut-gorm code snippet 3
package example.micronaut.gorm.service
import example.micronaut.gorm.domain.Person
import grails.gorm.services.Service
import groovy.transform.CompileStatic
import javax.inject.Singleton
@Service(Person)
@CompileStatic
@kevintanhongann
kevintanhongann / PersonService.groovy
Created March 8, 2019 04:04
example-micronaut-gorm code snippet 3
package example.micronaut.gorm.service
import example.micronaut.gorm.domain.Person
import grails.gorm.services.Service
import groovy.transform.CompileStatic
import javax.inject.Singleton
@Service(Person)
@CompileStatic
@kevintanhongann
kevintanhongann / Person.groovy
Created March 8, 2019 03:48
example-micronaut-gorm code snippets 2
package example.micronaut.gorm.domain
import grails.gorm.annotation.Entity
@Entity
class Person {
String name
String email