Skip to content

Instantly share code, notes, and snippets.

View hackjutsu's full-sized avatar
:octocat:
building something great

CosmoX hackjutsu

:octocat:
building something great
View GitHub Profile
@hackjutsu
hackjutsu / PetRepository.java
Last active May 20, 2019 01:07
[medium snippets] #medium #designPattern #IteratorPattern
public class PetRepository implements Container {
private class NameIterator implements Iterator {
int index = 0;
@Override
public boolean hasNext() {
return index < pets.length;
}
@Override
@hackjutsu
hackjutsu / Iterator-pattern-interfaces.java
Last active May 20, 2019 01:08
[medium snippets] #medium #designPattern #IteratorPattern
public interface Iterator {
boolean hasNext();
Object next();
}
public interface Container {
Iterator getIterator();
}
@hackjutsu
hackjutsu / 1-Strategy.java
Last active May 20, 2019 01:32
[medium snippets] #medium #designPattern #StrategyPattern
public interface Strategy {
public int doOperation(int num1, int num2);
}
public class OperationAdd implements Strategy{
@Override
public int doOperation(int num1, int num2) {
return num1 + num2;
}
}
@hackjutsu
hackjutsu / enum-type-with-one-element.java
Last active May 20, 2019 01:08
[medium snippets] #medium #designPattern #SingletonPattern
public enum Elvis {
INSTANCE;
public void someMethod() {...}
}
@hackjutsu
hackjutsu / singleton-property-with-private-constructor.java
Last active May 20, 2019 01:08
[medium snippets] #medium #designPattern #StrategyPattern
public class Elvis {
private static final Elvis INSTANCE = new Elvis();
public static Elvis getInstance() {
return INSTANCE;
}
private Elvis() {...}
}
@hackjutsu
hackjutsu / Initialization-on-demand-holder-idiom.java
Last active May 20, 2019 01:08
[medium snippets] #medium #designPattern #SingletonPattern
public class Something {
private static class LazyHolder {
private static final Something INSTANCE = new Something();
}
public static Something getInstance() {
return LazyHolder.INSTANCE;
}
private Something() {}
@hackjutsu
hackjutsu / bad-double-check-locking.java
Last active May 20, 2019 01:08
[medium snippets] #medium #designPattern #SingletonPattern
class Foo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null) {
synchronized(this) {
if (helper == null) {
helper = new Helper();
}
}
}
@hackjutsu
hackjutsu / double-check-locking.java
Last active May 20, 2019 01:08
[medium snippets] #medium #designPattern #SingletonPattern
public class Singleton {
private volatile static Singleton uniqueInstance;
public static Singleton getInstance() {
if (uniqueInstance == null) {
synchronized (Singleton.class) {
if (uniqueInstance == null) {
uniqueInstance = new Singleton();
}
}
@hackjutsu
hackjutsu / create_publish_snap.sh
Created May 5, 2019 20:39
[Snap Publishment] snippets to register & publish #snap apps to snapcraft
sudo snap install snapcraft || brew install snapcraft
snapcraft login
snapcraft register lepton
snapcraft push --release stable Lepton_1.6.2_amd64.snap
@hackjutsu
hackjutsu / plotting-with-Matplotlib.ipynb
Created August 11, 2018 06:57
[Jupyter Notebook Demo 4] This is a #demo for Lepton's support of Jupyter Notebook viewer.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.