Skip to content

Instantly share code, notes, and snippets.

View ldclakmal's full-sized avatar
🎯
Focusing

Chanaka Lakmal ldclakmal

🎯
Focusing
View GitHub Profile
@ldclakmal
ldclakmal / bearer-auth-0.980.0.bal
Last active January 17, 2020 10:41
Ballerina bearer token authentication
endpoint http:Client bearerTokenAuthClient {
url: "https://www.example.org/api/v1",
auth: {
scheme: http:OAUTH2,
accessToken: "yf29.PlrfBb0gtDFXsbnE_LcDCG-Dz3djEp05zM9y-IPR8CsZz90XwOEyrhqeXPPYxubY9RHMIFzoV2"
}
};
public function testBearerTokenAuth() {
string requestPath = "/employees";
@ldclakmal
ldclakmal / basic-auth-0.980.0.bal
Last active January 17, 2020 10:42
Ballerina basic authentication
endpoint http:Client basicAuthClient {
url: "https://www.example.org/api/v1",
auth: {
scheme: http:BASIC_AUTH,
username: "admin",
password: "123"
}
};
public function testBasicAuth() {
@ldclakmal
ldclakmal / RESTAPI.java
Last active April 22, 2018 18:58
Call REST API
private Optional<JsonObject> callRestApi(String url) {
try {
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials =
new UsernamePasswordCredentials(System.getenv(Constant.EnvironmentVariable.USERNAME),
System.getenv(Constant.EnvironmentVariable.PASSWORD));
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
HttpResponse response = client.execute(new HttpGet(url));
String json = EntityUtils.toString(response.getEntity(), "UTF-8");
@ldclakmal
ldclakmal / MSF4J.java
Last active July 13, 2018 08:45
Microservice runner with netty-transports.yml
package org.wso2.cse.rest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wso2.cse.configuration.AuthInterceptor;
import org.wso2.cse.service.Constant;
import org.wso2.msf4j.MicroservicesRunner;
import java.io.File;
import java.io.IOException;
@ldclakmal
ldclakmal / Stemmer.java
Created January 21, 2018 02:47
Stemmer, implementing the Porter Stemming Algorithm
package DM;
/*
Porter stemmer in Java. The original paper is in
Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14,
no. 3, pp 130-137,
See also http://www.tartarus.org/~martin/PorterStemmer
@ldclakmal
ldclakmal / git-release.txt
Last active November 4, 2018 05:26
Git Release
-- Git releases --
Ex: tag = v1.0-alpha1
Add tag
----------------------------------------------
git tag -a [tag] -m "Released [tag]"
git push origin [tag]
Delete tag
----------------------------------------------
@ldclakmal
ldclakmal / VariableName.java
Created May 28, 2017 16:26
Get the names of the static variables of a class
public void getVariableNames() {
Field[] fields = MyClass.class.getDeclaredFields();
for (Field f : fields) {
if (Modifier.isStatic(f.getModifiers())) {
System.out.println(f.getName());
}
}
}
@ldclakmal
ldclakmal / UoMProxy.txt
Created May 9, 2017 14:22
Proxy of University of Moratuwa
set http_proxy=http://cache.mrt.ac.lk:3128
set https_proxy=https://cache.mrt.ac.lk:3128
@ldclakmal
ldclakmal / file_nio_ingress_connector.svg
Last active May 9, 2017 14:17
ASCII Doc for NIO File Ingress Connector
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ldclakmal
ldclakmal / SCP
Created February 15, 2017 04:16
Commonly used set of commands for SCP
Copy the file "foobar.txt" from a remote host to the local host
$ scp username@remotehost:foobar.txt /some/local/directory
Copy the file "foobar.txt" from the local host to a remote host
$ scp foobar.txt username@remotehost:/some/remote/directory
Copy the directory "foo" from the local host to a remote host's directory "bar"
$ scp -r foo username@remotehost:/some/remote/directory/bar
Copy the file "foobar.txt" from the local host to a remote host using port 2264