Skip to content

Instantly share code, notes, and snippets.

View sagrawal31's full-sized avatar
🧑‍💻
😊

Shashank Agrawal sagrawal31

🧑‍💻
😊
View GitHub Profile
@sagrawal31
sagrawal31 / groovyJavaPractices.groovy
Last active July 1, 2016 09:42
A simple code standard for our Groovy/Java code
/**
* Must have copyright statement either of the company or of our client.
* Follow other files in the repository.
*/
package com.wp.test // package declaration just after copyright statement
// One line space after package declaration
// Import statement must be organized. Use organize tool in GGTS
import java.text.DateFormat
@sagrawal31
sagrawal31 / grails
Created March 9, 2017 09:16
Auto use Grails 3 versions from gradle.properties
#!/usr/bin/env bash
set -e
# Handy script to auto use the Grails 3 version based on what is defined in the "gradle.properties". This script uses
# the Grails installed by the famous SDKMan so it will look the Grails installation at "~/.sdkman/candidates/grails"
# so only make sure the particular Grails version is installed using "sdk install grails <version>".
#
# The only thing to care about is that this script should be included first in the "PATH" before the
# ".sdkman/candidates/grails/current" is included.
#
@sagrawal31
sagrawal31 / resurseFile.groovy
Created April 28, 2017 15:24
A Groovy code to recuse every file (of specific type) in a directory
import groovy.io.FileType
File fooDirectory = new File("/some-path-to-the-parent-directory")
// Recurse only *.html file (for example)
def reportNamePattern = ~/.*\.html/
fooDirectory.eachFileMatch(FileType.FILES, reportNamePattern) { File myFile ->
// Use myFile as you want
println myFile.name
}
@sagrawal31
sagrawal31 / tomcat8.sh
Created March 22, 2018 14:11
init script to auto start Tomcat 8
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat7
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop Tomcat server
### END INIT INFO

Keybase proof

I hereby claim:

  • I am sagrawal31 on github.
  • I am shagrawal (https://keybase.io/shagrawal) on keybase.
  • I have a public key ASBdggAw-it7HVnymLwArRHY_FbcbMmbH6ikz2jt8RRh8Ao

To claim this, I am signing this object:

@sagrawal31
sagrawal31 / getFinalURL.groovy
Created August 7, 2018 06:56
A simple Groovy script to get the final URL of a URL by hitting that URL and checking for 301, 302 response codes
URL getFinalURL(String url) {
getFinalURL(new URL(url))
}
URL getFinalURL(URL url) {
HttpURLConnection connection = (HttpURLConnection) url.openConnection()
connection.setInstanceFollowRedirects(false)
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36")
connection.addRequestProperty("Accept-Language", "en-US,en;q=0.8")
connection.addRequestProperty("Referer", "http://example.com/")
import liquibase.statement.core.UpdateStatement
databaseChangeLog = {
// Some other changeSets
changeSet(author: "Shashank (generated)", id: "1381499382647-13") {
addColumn(tableName: "ufile") {
column(name: "file_group", type: "varchar(255)") {
constraints(nullable: "false")
import liquibase.statement.core.InsertStatement
databaseChangeLog = {
changeSet(author: "Shashank Agrawal", id: "my-custom-unique-id-for-each-changeSet-11212013-1") {
grailsChange {
change {
def statements = []
import liquibase.statement.core.InsertStatement
databaseChangeLog = {
changeSet(author: "Shashank Agrawal", id: "my-custom-unique-id-for-each-changeSet-11212013-1") {
grailsChange {
change {
def statements = []
// Iterating through each row in table.
sql.eachRow('select * from old_table_name') {
def insertStatement = new InsertStatement("my_database_name", "new_table_name")
import liquibase.statement.core.*
import com.some.domain.Post
databaseChangeLog = {
// Auto generated change sets which adds column to the post table.
grailsChange {
change {
Post.list().each { postInstance ->
postInstance.dateCreated = new Date()
postInstance.lastUpdated = new Date()