1. Activate extras-devel.
2. Open terminal and enter the following commands.
root #needs to be root apt-get install lua5.1●๋•‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗●๋•
♪ kadaj's musing ♪
root #needs to be root apt-get install lua5.1●๋•‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗●๋•
string does not contain commonly used methods like split. However, the module string_ext contains them. Below is a snippet on how to use the split method. The point to consider here is the module we have to import in order for the method to work correctly. Importing only the string_ext module is not enough. We have to import list and strbuf modules as well.require("string_ext")
require("list")
require("strbuf")
print(string.split("Hello World", " ")) -- outputs {1=Hello,2=World}
●๋•‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗●๋•
rest. To install the plugin go to the grails project directory and rungrails install-plugin rest1. Run the grails application with HTTPS.
keytool -importcert -alias "subdomain.your-website-domain.com" -file localhost.crt -keystore truststore.jks -storepass password12344. Copy the truststore.jks file created in step 3 to
grails-app/conf folder.//RestConnector.groovy
import grails.converters.JSON
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.Method
import org.apache.http.impl.client.DefaultRedirectStrategy
import org.apache.http.impl.cookie.BasicClientCookie
import java.security.KeyStore
import org.apache.http.conn.scheme.Scheme
import org.apache.http.conn.ssl.SSLSocketFactory
import org.apache.http.HttpRequest
import org.apache.http.HttpResponse
import org.apache.http.protocol.HttpContext
import javax.servlet.http.HttpServletResponse
import javax.servlet.http.Cookie
import groovyx.net.http.Method
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.HttpResponseDecorator
class RestConnector {
private String baseUrl
private HTTPBuilder httpBuilder
private List<string> cookies
RestConnector(String url) {
this.baseUrl = url
this.httpBuilder = initializeHttpBuilder()
this.cookies = []
}
public def request(Method method, ContentType contentType, String url, Map<String, Serializable> params) {
debug("Send $method request to ${this.baseUrl}$url: $params")
// import the key from the keystore
def keyStore = KeyStore.getInstance(KeyStore.defaultType)
getClass().getResource( "/truststore.jks").withInputStream {
keyStore.load(it, "password1234".toCharArray())
}
SSLSocketFactory sf = new SSLSocketFactory(keyStore)
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
httpBuilder.client.connectionManager.schemeRegistry.register(new Scheme("https", sf, 443))
httpBuilder.request(method, contentType) { request ->
uri.path = url
//uri.query = params
headers['Cookie'] = cookies.join(';')
requestContentType = ContentType.URLENC
// sample params
body = ['username': "${params.username}", 'password': "${params.password}", 'otherParams': "${params.otherExampleParams}"]
headers.'Connection' = params['Connection']
headers.'Cookie' = params['Cookie']
println("::Cookie: -> " + params['Cookie'])
headers.'Host' = params['Host']
headers.'X-Requested-With' = params['X-Requested-With']
headers.'Origin' = params['Origin']
}
}
private HTTPBuilder initializeHttpBuilder() {
def httpBuilder = new HTTPBuilder(baseUrl)
httpBuilder.handler.success = { HttpResponseDecorator resp, reader ->
resp.getHeaders('Set-Cookie').each {
//[Set-Cookie: JSESSIONID=E68D4799D4D6282F0348FDB7E8B88AE9; Path=/frontoffice/; HttpOnly]
String cookie = it.value.split(';')[0]
debug("Adding cookie to collection: $cookie")
cookies.add(cookie)
}
if (resp.status == 302) {
println('302 detected')
return ['status': 'redirect', 'response': resp]
}
debug("Resp: ${resp}")
debug("Reader: ${reader}")
return ['status': 'ok', 'result': reader]
}
// Enable to follow redirect requests
/*httpBuilder.client.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) {
def redirected = super.isRedirected(request, response, context)
return redirected || response.getStatusLine().getStatusCode() == 302
}
})*/
return httpBuilder
}
private debug(String message) {
System.out.println(message) //for Gradle
}
}6. Using the above class in a grails controller://ExampleController.groovy
// ..imports
class ExampleController {
def index() {
String serverName = request.getServerName()
String serverUrl = "https://${serverName}"
RestConnector restConnector = new RestConnector(serverUrl) //some https url here
def result = restConnector.request(Method.POST, ContentType.JSON, "${serverUrl}", ['username': "${username}", 'password': "${password}", 'otherParam': "${otherParam}"])
if (result.status == "redirect") {
def resp = result.response
def heads = resp.getHeaders()
redirect(uri: 'redirect-uri-here')
} else if (result.status == "ok") {
render (result.result as JSON)
}
}
}●๋•‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗●๋•
// IIFE in js
(function(arg) {
if (arg === 1)
return "one";
else
return "not one";
})(1);In Groovy the same thing can be done using anonymous blocks which the language names as 'closure'. It is not the lexical closure that we are talking about, though it can be. The 'Closure' in Groovy is just a block of code.// IIFE in Groovy
{arg ->
if (arg == 1)
"one"
else
"not one"
}(1)●๋•‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗●๋•
Bookmarks Organizer Google Chrome Extension helps us in keeping the bookmarks sorted. By default Chrome does not sort bookmarks by title. This extension monitors for newly added or moved bookmarks and auto arranges them in ascending order by title. There is a reorder button to manually order the whole bookmark, which can be used initially after installation. The only down side is that there is API restriction on the number of bookmarks that can be reordered (moved) per min, per hour and the number is a bit low.cp command does not have an excludes option. One way to copy files ignores some files or directories is to create a tarball. The tar command has an exclude option. The exclude patterns can be mentioned in a separate file and passed in to the tar command.# Directory Structure
BO
│ .git
│ .gitignore
│ books.html
│ book.js
│ build.sh
│ buildExcludes
│ main.js
│ manifest.json
│
├───bin
│ └───BO
│ │ books.html
│ │ books.js
│ │ main.js
│ │ manifest.json
│ │
│ └───res
│ └───icons
│ bo-128.png
│ bo-16.png
│ bo-256.png
│ bo-32.png
│ bo-48.png
│ bo-512.png
│ bo-64.png
│
└───res
└───icons
bo-128.png
bo-16.png
bo-256.png
bo-32.png
bo-48.png
bo-512.png
bo-64.png
bo.fla
In the above directory structure, I want to copy certain file to bin/BO but ignore others like .git, fla files in the res/icons directory, the build scripts etc. For that first create an file say buildExcludes with the exclude pattern..git .gitignore bin res/icons/*.fla build.sh buildExcludesCreate the tar, deflate to the destination directory and delete the tar once done.
tar -cvf bo.tar * -X buildExcludes #create tar tar -xvf bo.tar -C bin/BO/ #deflate to destination directory rm -f bo.tar #cleanup●๋•‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗‗●๋•