gitA collection of git commands and scenarios
remote: error: File file.zip is 200.00 MB; this exceeds GitHub's file size limit of 100.00 MB
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/...'
$ git filter-branch --tree-filter 'rm -rf file.zip' a12345.HEAD
$ git push origin master --force
See entire post »
 groovyexecPBSZ(0)
execPROT("P")
import org.apache.commons.net.ftp.FTPSClient
new FTPSClient("TLSv1", true).with {
  connect "localhost", 990
  execPBSZ(0)
  execPROT("P")
  login "user", "pass"
  setControlEncoding("UTF-8");
  enterLocalPassiveMode()
  setFileType(FTP.ASCII_FILE_TYPE)
  setFileTransferMode(FTP.ASCII_FILE_TYPE)
  changeWorkingDirectory ("/home/user")
  def stream = new BufferedInputStream(
    new FileInputStream("file.txt"))
  if (stream.available() == 0) {
    throw new Exception("Cannot read local file stream!")
  }
  result = it.storeFile(destFilename, stream)
  stream.close()
  logout()
  disconnect()
}
See entire post »
 grails groovyimport grails.util.Environment
class BootStrap {
  def init = { servletContext ->
    println "Initializing..."
    if (Environment.current == Environment.DEVELOPMENT) {
      println "Development"
    } else if (Environment.current == Environment.TEST) {
      println "Test"
    } else if (Environment.current == Environment.PRODUCTION) {
      println "Production"
    }
  }
  /**
   * Note: this is not guaranteed to be called by the servlet container
   */
  def destroy = {
    printn "De-initializing..."
    if (Environment.current == Environment.DEVELOPMENT) {
    } else if (Environment.current == Environment.TEST) {
    } else if (Environment.current == Environment.PRODUCTION) {
    }
  }
}
import org.springframework.web.context.support.WebApplicationContextUtils
class BootStrap {
  def init = { servletContext ->
    def springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext)
    println "Initializing..."
    def service = springContext.getBean("notificationService")
    service.sendAdminNotification("[UP] started")
  }
  /**
   * Note: this is not guaranteed to be called by the servlet container
   */
  def destroy = { servletContext ->
    printn "De-initializing..."
    def springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext)
    if (Environment.current == Environment.DEVELOPMENT) {
    } else if (Environment.current == Environment.TEST) {
    } else if (Environment.current == Environment.PRODUCTION) {
      def service = springContext.getBean("notificationService")
      service.sendAdminNotification("[DOWN] destroyed")
    }
  }
}
import org.springframework.web.context.support.WebApplicationContextUtils
import org.springframework.cloud.CloudFactory
import org.springframework.cloud.CloudException
class BootStrap {
  def grailsApplication
  def init = { servletContext ->
    def springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext)
    println "Initializing..."
    println "Datasource: " + grailsApplication.config.dataSource
    println "Mongo: " + grailsApplication.config.grails.mongo
    // Get bean ref
    def mongo = springContext.getBean("mongo")
    // Get cloud info
    def cloud = null
    def dbName = "mydb"
    try {
      cloud = new CloudFactory().cloud
      // Get database name for bound service
      def mongoInfo = cloud?.getServiceInfo('myservice-db')
      dbName  = mongoInfo?.database
      println "Got dbName from cloud info: " + dbName
    } catch (CloudException e) {
      println "ERROR getting cloud: " + e
    }
    def db = mongo.getDB(dbName)
    println "Got db: " + db
  }
}
See entire post »
 camel groovy// xstream default
from("direct:input")
.marshal()
.json()
.to("log:main?showBody=true")
{"map":{"entry":[{"string":"input3","list":{"string":[1,2]}},{"string":["input2","abc123"]},{"string":["input1","abcde"]}]}}
import org.apache.camel.model.dataformat.JsonLibrary
// ...
from("direct:input")
.marshal()
.json(JsonLibrary.Jackson)
.to("log:main?showBody=true")
See entire post »