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 / CreateWatchKey.java
Last active January 12, 2017 19:12
Create a watch key and poll the events
WatchKey key = watcher.take();
for (WatchEvent<?> event: key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
}
@ldclakmal
ldclakmal / PathMatcher.java
Last active January 12, 2017 14:47
Check whether picked file matches with the given path pattern
public boolean isMatchPattern(GRPattern GRPattern, Path file) {
PathMatcher matcher = FileSystems.getDefault().getPathMatcher(GRPattern.getPatternSyntax() +
Paths.get(GRPattern.getPathPattern()).toString());
Path name = file.getFileName();
return name != null && matcher.matches(file);
}
@ldclakmal
ldclakmal / SCPFrom.java
Last active February 14, 2017 20:42
Secure copy files from remote server
private static void copyRemoteToLocal(Session session, String from, String to, String fileName) throws JSchException, IOException {
from = from + File.separator + fileName;
String prefix = null;
if (new File(to).isDirectory()) {
prefix = to + File.separator;
}
// exec 'scp -f rfile' remotely
String command = "scp -f " + from;
@ldclakmal
ldclakmal / SCPTo.java
Last active February 14, 2017 20:42
Secure copy files to remote server
private static void copyLocalToRemote(Session session, String from, String to, String fileName) throws JSchException, IOException {
boolean ptimestamp = true;
from = from + File.separator + fileName;
// exec 'scp -t rfile' remotely
String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + to;
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
// get I/O streams for remote scp
public static void main(String[] arg) throws IOException, JSchException {
String remoteA = "/tmp/scp/remote-a/";
String remoteB = "/tmp/scp/remote-b/";
String local = "/tmp/scp/local/";
String fileName = "abc.txt";
String user = "chanaka";
String host = "localhost";
int port = 22;
@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
@ldclakmal
ldclakmal / file_nio_ingress_connector.svg
Last active May 9, 2017 14:17
ASCII Doc for NIO File Ingress Connector
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / 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
----------------------------------------------