Skip to content

Instantly share code, notes, and snippets.

View shelajev's full-sized avatar

Oleg Šelajev shelajev

View GitHub Profile
@shelajev
shelajev / Default methods override
Last active August 29, 2015 13:58
Java 8, default methods
package org.shelajev.throwaway.defmeth;
public class Main {
public static void main(String[] args) {
// what does this program produce?
B b = new B();
b.m1();
b.callM1();
b.callSuperM1();
}
@shelajev
shelajev / Main.java
Last active January 10, 2020 08:56
IterateOverHeap JVMTI example
package org.shelajev;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
Thread t = new Thread();
int a = countInstances(Thread.class);
System.out.println("There are " + a + " instances of " + Thread.class);
}
@shelajev
shelajev / dsu-analysis
Last active August 29, 2015 14:11
DSU system analysis diagram description:
# http://bramp.github.io/js-sequence-diagrams/
DSU solution->Genrih: notifies about upcoming update
Genrih->>DSU solution: request changed classes
DSU solution->Genrih: provides changed classes
Genrih->Diff tool: old code, new code
Diff tool->>Genrih: list of changes
Note right of Genrih: changes => potential phenomena
Genrih->Oracle: list of phenomena
Oracle->Runtime: queries state
Runtime->>Oracle: state information
@shelajev
shelajev / app.groovy
Created December 3, 2015 16:32
4 Examples of a Dynamic Language... post snippets
@RestController
class ThisWillActuallyRun {
   @RequestMapping("/")
   String home() {
       return "Hello World!"
   }
}
@shelajev
shelajev / Foo1.java
Last active December 9, 2015 16:56
RebelLabs post: A Fluent API or not API fluent a? That is the Question!
public class Foo {
private String bar;
private int number;
public Foo() {
// Do some stuff
}
public String getBar() { return this.bar; }
@shelajev
shelajev / DefaultMethods.java
Last active July 31, 2018 18:52
Java 8 Cheat Sheet Code Snippets
//Default methods in interfaces
@FunctionalInterface
interface Utilities {
default Consumer<Runnable> m() {
return (r) -> r.run();
}
// default methods, still functional
Object function(Object o);
}
@shelajev
shelajev / Debuggable.java
Last active February 23, 2022 05:26
Java 8 cheat sheet code
public interface Debuggable {
default String debug() {
StringBuilder sb = new StringBuilder(this.getClass().getName());
sb.append(" [ ");
Field[] fields = this.getClass().getDeclaredFields();
for(Field f: fields) {
f.setAccessible(true);
try {
sb.append(f.getName() + " = " + f.get(this));
sb.append(", ");
@shelajev
shelajev / ExampleActor.java
Last active December 18, 2015 19:16
RebelLabs post: Exploring the virtues of microservices with Play and Akka
class ExampleActor extends AbstractActor {
// this child will be destroyed and re-created upon restart by default
final ActorRef other = getContext().actorOf(new Props(OtherActor.class), "childName");
public ExampleActor() {
receive(ReceiveBuilder
.match(Request1.class, r ->
other.tell(r.getMsg(), self())
)
.match(Request2.class, r ->
@shelajev
shelajev / snackbar-example.java
Created January 15, 2016 16:14
retrofit2-snackbar-example.java
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, “Super fast hello world”, Snackbar.LENGTH_LONG)
.setAction(“Action”, null).show();
}
});
@shelajev
shelajev / retrofit-dependencies.groovy
Created January 15, 2016 16:15
retrofit2-retrofit-dependencies.groovy
compile ‘com.squareup.retrofit2:retrofit:2.0.0-beta2’
compile ‘com.squareup.retrofit2:gson-converter:2.0.0-beta2’