Skip to content

Instantly share code, notes, and snippets.

View dmi3coder's full-sized avatar
🇩🇪
arbeite

Dmytro dmi3coder

🇩🇪
arbeite
  • Berlin, Germany
  • 06:45 (UTC +02:00)
View GitHub Profile
Note note = Note.newBuilder()
.setName("But list")
.setContent("Buy:\n"
+ "- Beer\n"
+ "- Beef\n"
+ "- Bacon\n"
+ "- Leg for C++ client part")
.setId(((long) (Math.random() * 900000000)))
.setType(NoteType.BASIC).build();
Envelope requesetEnvelope = Envelope.newBuilder().addNote(note).setType(Type.SAVE_NOTE).build();
@dmi3coder
dmi3coder / gist:97c7ab1cd36513e5198fc1d4f873c1a1
Last active June 5, 2017 08:12
c++ protbuf object to bytes
protocol::Note note = protocol::Note();
string name = "Buy vegetable";
string cafel = "-Apple\n-Pomodoro\n-Avocado";
note.set_name(name);
note.set_content(cafel);
note.set_id(1);
note.set_type(protocol::NoteType::BASIC);
Envelope envelope = createEnvelope(&note);
int size = envelope.ByteSize();
@dmi3coder
dmi3coder / .zshrc
Last active March 14, 2018 11:38
Kubernetes and Docker shell aliases
# ALIASES
## Kubernetes
alias kp="kubectl get po"
alias kl="kubectl logs"
alias ks="kubectl get logs"
## Docker
alias dk="docker"
alias dks="dk ps"
alias dksn="dks --format \"table {{.ID}}\t{{.Names}}\t'dkl {{.ID}}'\t'dke {{.ID}} bash'\""
alias dki="dk images"
@dmi3coder
dmi3coder / Main.java
Last active June 3, 2019 10:03
Spark app serves method
public class Main {
public static void main(String[] args) {
initApi();
}
public static void initApi() {
port(8080);
get("/", MainResource::handleMain);
}
@dmi3coder
dmi3coder / AnnotationExample.java
Last active November 27, 2019 13:40
Java's annotation example from Spring
@RequestMapping(
value = "/hello", method = GET)
@ResponseBody
public String getHelloMessage() {
return "hello";
}
@dmi3coder
dmi3coder / decorator_example.py
Created November 27, 2019 13:48
Example of Python's Decorators in flask
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def say_hello():
return 'hello'
@dmi3coder
dmi3coder / our_decorators_example.py
Last active November 27, 2019 15:02
Our example of python decorators
def as_html(func):
def wrapper():
result = func()
return f'<html>{result}</html>'
return wrapper
@as_html
def say_hello():
return 'Hello'
@dmi3coder
dmi3coder / cached_decorator_example.py
Last active November 28, 2019 08:16
Example of cached decorator in Python
import time
cached_items = {}
def cached(func):
def wrapper(*args, **kwargs):
global cached_item
if func.__name__ not in cached_items:
cached_items[func.__name__] = func(*args, **kwargs)
return cached_items[func.__name__]
return wrapper
@dmi3coder
dmi3coder / CachedAnnotationExample.java
Last active November 28, 2019 08:55
Cached annotation example in Java
public class Main {
@Retention(RetentionPolicy.RUNTIME)
@interface Cached { } // Nothing inside our annotation
static class SomeObject {
@Cached
public String intensiveTask() throws InterruptedException {
Thread.sleep(1000);
return "expensive task result";
@dmi3coder
dmi3coder / our_decorator_example2.py
Created November 28, 2019 12:13
Example of decorator without @ sign
def as_html(func):
def wrapper():
result = func()
return f'<html>{result}</html>'
return wrapper
def say_hello():
return 'Hello'