All Projects → hindol → commons

hindol / commons

Licence: MIT license
Ad-hoc collection of re-usable Java classes.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to commons

deadlink
💀 Checks and fixes URLs in code and documentation.
Stars: ✭ 105 (+600%)
Mutual labels:  url
Odyssey
A piece of software that shows a traceroute of a URL redirect path
Stars: ✭ 41 (+173.33%)
Mutual labels:  url
go-types
Library providing opanapi3 and Go types for store/validation and transfer of ISO-4217, ISO-3166, and other types.
Stars: ✭ 14 (-6.67%)
Mutual labels:  url
1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (+220%)
Mutual labels:  url
uri
A type to represent, query, and manipulate a Uniform Resource Identifier.
Stars: ✭ 16 (+6.67%)
Mutual labels:  url
cpp-feather-ini-parser
Header only, simple, fast, templated - portable INI parser for ANSI C++.
Stars: ✭ 44 (+193.33%)
Mutual labels:  ini-parser
gravatar-url-generator
A fun and friendly generator of Gravatar urls.
Stars: ✭ 44 (+193.33%)
Mutual labels:  url
Linkt
A lightweight and simple Kotlin library for deep link handling on Android 🔗.
Stars: ✭ 101 (+573.33%)
Mutual labels:  url
marshmallow-objects
Marshmallow Objects and Models
Stars: ✭ 37 (+146.67%)
Mutual labels:  ini-parser
laravel-linkable
URL binding for Laravel models
Stars: ✭ 22 (+46.67%)
Mutual labels:  url
url
Build and parse URLs. Useful for HTTP and "routing" in single-page apps (SPAs)
Stars: ✭ 69 (+360%)
Mutual labels:  url
golgi
A composable routing library for Haxe.
Stars: ✭ 37 (+146.67%)
Mutual labels:  url
kzilla.xyz
Shorten the URL. Broaden the reach.
Stars: ✭ 34 (+126.67%)
Mutual labels:  url
link text
Easy to use text widget for Flutter apps, which converts inlined urls into working, clickable links
Stars: ✭ 20 (+33.33%)
Mutual labels:  url
github-base
Simple, opinionated node.js interface for creating basic apps with the GitHub API.
Stars: ✭ 58 (+286.67%)
Mutual labels:  url
immurl
🔗 A tiny immutable URL library, backed by the native whatwg URL.
Stars: ✭ 23 (+53.33%)
Mutual labels:  url
relateurl
Create a relative URL with options to minify.
Stars: ✭ 52 (+246.67%)
Mutual labels:  url
remote-origin-url
Extract the git remote origin URL from your local git repository.
Stars: ✭ 15 (+0%)
Mutual labels:  url
All-Url-Uploader
A simple telegram Bot, Upload Media File| video To telegram using the direct download link. (youtube, Mediafire, google drive, mega drive, etc)
Stars: ✭ 122 (+713.33%)
Mutual labels:  url
Omeka-plugin-CleanUrl
Omeka plugin that allows to have clean, searchable and readable URL like https://example.com/my_collection/dc:identifier instead of https://example.com/items/show/internal_code.
Stars: ✭ 13 (-13.33%)
Mutual labels:  url

Commons

Ad-hoc collection of re-usable Java classes.

Argument

Reads configuration parameters from environment variables and Java system properties.

Usage

String javaHome = Argument.resolver()
        .firstTry("javaHome", Argument.Type.PROPERTY) // -DjavaHome="..."
        .thenTry("JAVA_HOME", Argument.Type.ENVIRONMENT_VARIABLE) // export JAVA_HOME=...
        .orElse("/usr/lib/jvm/openjdk-8-jdk/")
        .resolve();

BackOffPolicy

Back-off policy for anything web.

Usage

BackOffPolicy backOffPolicy = new ExponentialBackOffPolicy.Builder()
        .setInitialInterval(1, TimeUnit.SECONDS)
        .setMaxInterval(1, TimeUnit.MINUTES)
        .setMultiplier(1.5)
        .setMaxElapsedTime(15, TimeUnit.MINUTES)
        .setRandomizationFactor(0.5)
        .build();

// Pseudo code, won't compile
while (true) {
    try {
    	String response = url.fetch();
        backOffPolicy.reset();
    } catch (IOException ioe) {
    	long interval = backOffPolicy.nextIntervalMillis();
        if (interval != BackOffPolicy.STOP) {
            Thread.sleep(interval);
        } else {
            throw e;
        }
    }
}

DirectoryWatcher

Watches one or more directories for changes using Java 7's WatchService API.

Usage

DirectoryWatcher watcher = new DirectoryWatcher.Builder()
        .addDirectories("/home/hindol/")
        .setPreExistingAsCreated(true)
        .build(new DirectoryWatcher.Listener() {
            public void onEvent(DirectoryWatcher.Event event, Path path) {
                switch (event) {
                    case ENTRY_CREATE:
                        System.out.println(path + " created.");
                        break;

                    case ENTRY_MODIFY:
                        ...

                    case ENTRY_DELETE:
                        ...
                }
            }
        });

try {
    watcher.start(); // Actual watching starts here
    TimeUnit.SECONDS.sleep(30);
    watcher.stop(); // Stop watching
} catch (Exception e) {
    // Do something
}

URL

URL encoding/decoding and parser/builder. Definitely not as standards compliant as other libraries but it works!

Usage

assertEquals(
    URL.timesEncoded("namshi%253A%252F%252Fn%252Ftarget%252F%253Futm_source%253Dtestng"),
    2
);

assertEquals(
    URL.decode("namshi%253A%252F%252Fn%252Ftarget%252F%253Futm_source%253Dtestng", 2),
    "namshi://n/target/?utm_source=testng"
);

assertEquals(
    URL.encode("namshi%3A%2F%2Fn%2Ftarget%2F%3Futm_source%3Dtestng", 0),
    "namshi%3A%2F%2Fn%2Ftarget%2F%3Futm_source%3Dtestng"
);

assertEquals(
    URL.ensureProtocol("www.vizury.com", "https"),
    "https://www.vizury.com"
);
assertEquals(
    URL.ensureProtocol("http://www.vizury.com", "https"),
    "http://www.vizury.com"
);

assertTrue(URL.isDeepLink("mmyt://htl/listing/?checkin=05192016&checkout=05212016&city=GOI"));

assertEquals(
    URL.safeDecode("http://www.google.com?q=Guy+Ritchie"),
    "http://www.google.com?q=Guy+Ritchie"
);

URL.Parser parser = URL.parse("mmyt://htl/listing/?checkin=05192016&checkout=05212016&city=GOI");

assertEquals(parser.protocol(), "mmyt");
assertEquals(parser.host(), "htl");
assertEquals(parser.path(), "/listing/");
assertEquals(parser.query(), "checkin=05192016&checkout=05212016&city=GOI");

URL.QueryParser query = parser.queryParser();

assertEquals(query.parameter("checkin"), "05192016");
assertEquals(query.parameter("checkout"), "05212016");
assertEquals(query.parameter("city"), "GOI");

assertEquals(
    URL.builder().setProtocol("https").setHost("www.vizury.com").toUrl(),
    "https://www.vizury.com/"
);

XML

DSL like XML creation.

Usage

String xml = Xml.createWriter()
                    .beginElement("VAST")
                        .attribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
                        .attribute("xsi:noNamespaceSchemaLocation", "vast.xsd")
                        .attribute("version", "3.0")
                        .beginElement("Ad")
                            .attribute("id", "xyz")
                            .beginElement("Wrapper")
                                .element("AdSystem", "Vizury")
                                .element("VASTAdTagURI", Xml.wrapInCdata("https://www.vizury.com/"))
                                .element("Error", Xml.wrapInCdata("https://www.vizury.com/"))
                                .element("Impression", Xml.wrapInCdata("https://www.vizury.com/"))
                                .beginElement("Creatives")
                                    .beginElement("Creative")
                                        .attribute("AdID", "xyz")
                                    .endElement()
                                .endElement()
                            .endElement()
                        .endElement()
                    .endElement().toXml();

The above code creates the following XML (minus the indentation of course),

<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="vast.xsd"
      version="3.0">
    <Ad id="xyz">
        <Wrapper>
            <AdSystem>Vizury</AdSystem>
            <VASTAdTagURI><![CDATA[https://www.vizury.com/]]></VASTAdTagURI>
            <Error><![CDATA[https://www.vizury.com/]]></Error>
            <Impression><![CDATA[https://www.vizury.com/]]></Impression>
            <Creatives><Creative AdID="xyz" /></Creatives>
        </Wrapper>
    </Ad>
</VAST>

Template

Simple string templates.

Usage

// Use '{{' and '}}' as marker (default).
Template template = Template.compile("To {{verb}} or not to {{verb}}.");
String sentence = template.format("verb", "be");
    
// Use '__' instead.
Template template = Template.createEngine("__", "__").compile("I tried to __verb__ your __noun__.");
String sentence = template.format("verb", "roast", "noun", "toast");
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].