Skip to content

Instantly share code, notes, and snippets.

View hackjutsu's full-sized avatar

CosmoX hackjutsu

View GitHub Profile
@hackjutsu
hackjutsu / churn_analysis.ipynb
Last active November 8, 2019 14:41
[Jupyter Notebook Demo 1] This is a #demo for Lepton's support of Jupyter Notebook viewer.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hackjutsu
hackjutsu / M1_README.md
Last active November 4, 2019 13:54
[Markdown Demo] #tags: lepton, markdown

Introducing Markdown

Markdown is a plain text formatting syntax designed to be converted to HTML. Markdown is popularly used as format for readme files, ... or in text editors for the quick creation of rich text documents. - Wikipedia

As showed in this manual, it uses hash(#) to identify headings, emphasizes some text to be bold or italic. You can insert a link.

Planet

  • Earth
  • Mars

Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. From https://leetcode.com/problems/container-with-most-water/

Algorithm

The intuition behind this approach is that the area formed between the lines will always be limited by the height of the shorter line. Further, the farther the lines, the more will be the area obtained.

We take two pointers, one at the beginning and one at the end of the array constituting the length of the lines. Futher, we maintain a variable \text{maxarea}maxarea to store the maximum area obtained till now. At every step, we find out the area formed between them, update \text{maxarea}maxarea and move the pointer pointing to the shorter line towards the other end by one step.

@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.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hackjutsu
hackjutsu / ClientDemo.java
Created May 23, 2019 04:40
[medium snippets] #medium #designPattern #StatePattern
public class ClientDemo {
public static void main(String[] args) {
MP3PlayerContext mp3Player = new MP3PlayerContext();
mp3Player.press();
mp3Player.getState();
mp3Player.press();
mp3Player.getState();
}
}
@hackjutsu
hackjutsu / PlayingState.java
Created May 23, 2019 04:38
[medium snippets] #medium #designPattern #StatePattern
public class PlayingState implements State {
public void pressPlay(MP3PlayerContext context) {
context.setState(new StandbyState());
}
@Override
public String getState() {
return "Playing...";
}
}
@hackjutsu
hackjutsu / State.java
Created May 23, 2019 04:37
[medium snippets] #medium #designPattern #StatePattern
public interface State {
void pressPlay(MP3PlayerContext context);
String getState();
}
@hackjutsu
hackjutsu / MP3PlayerContext.java
Created May 23, 2019 04:35
[medium snippets] #medium #designPattern #StatePattern
public class MP3PlayerContext {
private State state;
public MP3PlayerContext() {
this.state = new StandbyState();
}
public void press() {
state.pressPlay(this);
}
@hackjutsu
hackjutsu / StreetMap.java
Created May 20, 2019 06:45
[medium snippets] #medium #designPattern #BuilderPattern
public class StreetMap {
private final Point origin;
private final Point destination;
private final Color waterColor;
private final Color landColor;
private final Color highTrafficColor;
private final Color mediumTrafficColor;
private final Color lowTrafficColor;
public static class Builder {
@hackjutsu
hackjutsu / ProxyPatternDemo.java
Created May 20, 2019 06:21
[medium snippets] #medium #designPattern #ProxyPattern
public class ProxyPatternDemo {
public static void main(String[] args) {
Image image = new ProxyImage("test_10mb.jpg");
image.display();
System.out.println("");
image.display();
}
}