Skip to content

Instantly share code, notes, and snippets.

View moriline's full-sized avatar

Moriline moriline

View GitHub Profile
@moriline
moriline / UniDiffStatic.java
Last active April 5, 2026 07:17
Utility Java class for computing diff (by Eugene Myers greedy differencing algorithm) between strings in Unified Format (unidiff) and applying patch
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* Utility class for computing differences between sequences and applying patches.
*/
public final class UniDiffStatic {
@moriline
moriline / desktop_swing.jsh
Last active June 2, 2021 03:02
JShell desktop application with Swing
import javax.swing.*;
// usage example: jshell --startup JAVASE desktop_swing.jsh
class MyGui extends JFrame { // class with own GUI components
public void createGUI() {
setTitle("HelloGUI");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(320, 240);
setLayout(null);
final JTextField tf=new JTextField();
tf.setBounds(20,10,95,30);
@moriline
moriline / swt_win_64_simple_app.groovy
Last active May 26, 2021 13:28
SWT windows 64 simple app
@Grapes(@Grab(group='org.eclipse.swt', module='org.eclipse.swt.win32.win32.x86_64', version='4.3'))
import org.eclipse.swt.widgets.*
def display = new Display()
def shell = new Shell(display)
shell.setText("Snippet 1")
shell.open()
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep()
}
@moriline
moriline / sqlite_example.groovy
Created May 21, 2021 02:17
sqlite usage example
@Grapes([
@Grab(group='org.xerial',module='sqlite-jdbc',version='3.34.0'),
@GrabConfig(systemClassLoader=true)
])
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:sqlite:sample.db", "org.sqlite.JDBC")
sql.execute("drop table if exists person")
sql.execute("create table person (id integer, name string)")
@moriline
moriline / vertx_server_advanced.groovy
Last active May 21, 2021 00:06
groovy script for starting vertx server with some routing and handlers
@Grapes([
@Grab(group='io.vertx', module='vertx-lang-groovy', version='4.1.0.Beta1'),
@Grab(group='io.vertx', module='vertx-core', version='4.1.0.Beta1'),
@Grab(group='io.vertx', module='vertx-web', version='4.1.0.Beta1')
//@GrabExclude("org.codehaus.groovy:groovy-swing")
])
import io.vertx.core.Vertx
import io.vertx.core.http.HttpClientRequest
import io.vertx.core.http.HttpServer
@moriline
moriline / vertx_server_simple.groovy
Last active May 21, 2021 00:07
groovy script for starting simple vertx server
@Grapes([
@Grab(group='io.vertx', module='vertx-lang-groovy', version='4.1.0.Beta1'),
@Grab(group='io.vertx', module='vertx-core', version='4.1.0.Beta1'),
@Grab(group='io.vertx', module='vertx-web', version='4.1.0.Beta1')
//@GrabExclude("org.codehaus.groovy:groovy-swing")
])
import io.vertx.core.Vertx
import io.vertx.core.http.HttpClientRequest
import io.vertx.core.http.HttpServer
@moriline
moriline / vertx_web_client.groovy
Last active May 21, 2021 00:06
groovy script for sending simple web request to URL
@Grapes([
@Grab(group='io.vertx', module='vertx-lang-groovy', version='4.1.0.Beta1'),
@Grab(group='io.vertx', module='vertx-core', version='4.1.0.Beta1'),
@Grab(group='io.vertx', module='vertx-web-client', version='4.1.0.Beta1')
//@GrabExclude("org.codehaus.groovy:groovy-swing")
])
import io.vertx.ext.web.client.WebClientOptions
import io.vertx.ext.web.client.WebClient
import io.vertx.core.Vertx
@moriline
moriline / jetty_server_simple.groovy
Last active May 21, 2021 01:31
groovy script for starting jetty server with simple handler
@Grab('javax.servlet:javax.servlet-api:3.0.1')
@Grab(group='org.eclipse.jetty', module='jetty-webapp', version='8.1.8.v20121106')
@Grab(group='org.eclipse.jetty', module='jetty-server', version='8.1.8.v20121106', transitive=false)
@Grab(group='org.eclipse.jetty', module='jetty-servlet', version='8.1.8.v20121106', transitive=false)
@GrabExclude('org.eclipse.jetty.orbit:javax.servlet')
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import groovy.servlet.*