How to clone/edit/push a GitHub Gist

We can’t add any collaborators to a GitHub Gist.


We can clone a gist with HTTPS clone URL with a username provided.

$ git clone https://<username><id>.git
Cloning into '<id>'...
remote: Counting objects: ..., done.
remote: Compressing objects: 100% (.../...), done.
remote: Total ... (delta ...), reused ... (delta ...), pack-reused ...
Unpacking objects: 100% (.../...), done.
Checking connectivity... done.
$ cd <id>
$ git remote show origin
* remote origin
  Fetch URL: https://<username><id>.git
  Push  URL: https://<username><id>.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

Now we can make changes to our files.


And git might ask for your password when we push commits back to the remote.

$ git push
Password for 'https://<username>': <password>
Counting objects: ..., done.
Delta compression using up to ... threads.
Compressing objects: 100% (.../...), done.
Writing objects: 100% (.../...), ... bytes | ... bytes/s, done.
Total ... (delta ...), reused ... (delta ...)
To https://<username><id>.git
   xxxxxxx..xxxxxxx  master -> master

ByteBuffer#wrap(byte[], int, int)

I just found that ByteBuffer#wrap(byte[], int, int) is very different from what I’ve presumed.

Here comes the result.

$ java ArrayWrappingByteBufferTest
array: [1, 1, 1, 1, 1, 1, 1, 1]
array: [0, 1, 1, 1, 1, 1, 1, 1]
array: [0, 1, 1, 1, 1, 1, 1, 0]

As you can see, wrapping an array is just creating a soft view of buffer. We can change elements of any indices in backing array.

Hiding dependencies by Shading and ProGuarding

Let’s say your library depends on commons-lang and you don’t want them exposed.

make it optional


shade it


proguard it

        -keepattributes *Annotation*
        -keepattributes Signature
        -keepattributes InnerClasses
        -keep class your.main.* { *; }

@XmlTransient on transient fields

public class Child {

    private String name;

    private Parent parent;

And let’s make it as a Serializable.

public class Child implements Serializable {

    private String name;

    private transient Parent parent;

Not that parent field marked as transient.
You know what? JAXB complains.

Transient field "parent" cannot have any JAXB annotations.

I believe @XmlTransient should be excluded from this ridiculous rule and issued it.

args4j with BeanValidation



Annotate your @Options with some annotations defined in javax.validation.

@Option(name = "-buffer-capacity",
        usage = "each buffer's capacity in bytes")
private int bufferCapacity = 65536;

@Option(name = "-buffer-count", required = true,
        usage = "number of buffers to allocate")
private int bufferCount;


And then validate by yourself.

final Opts opts;
final ValidatorFactory factory
    = Validation.buildDefaultValidatorFactory();
final Validator validator = factory.getValidator();
final Set<ConstraintViolation<Opts>> violations
    = validator.validate(opts);
if ( -> {
    System.err.println("violation: " + v);
    return v;
}).count() > 0L) {