Skip to content

Instantly share code, notes, and snippets.

View ram0973's full-sized avatar
:octocat:
Thinking

ram0973 ram0973

:octocat:
Thinking
View GitHub Profile
@ram0973
ram0973 / hell.java
Created February 21, 2021 09:02
Фабрика фабрик
class TestDrive {
public static void main(String[] args) throws InterruptedException {
BurgerStore mcDonalds = new McDonStore();
BurgerStore burgerKing = new BurgerKingStore();
Burger burger;
System.out.println("-Hello, one McDonalds style cheeseburger");
System.out.println("-Okay! Please wait for a sec, -Calling to the McDonaldsStore. -Cheeseburger");
burger = mcDonalds.orderBurger(Burger.CHEESE);
@ram0973
ram0973 / Words.java
Created February 25, 2021 09:18
Java count most 10 frequent words in text
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.function.Function.identity;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
@ram0973
ram0973 / Main.java
Last active March 14, 2021 09:48
Java Mockito example
// Let's consider an example. UsdConverter class is responsible for converting local currency to USD (United States dollar).
// The test should check the behavior of the tested unit in isolation from its dependencies.
// As the exchange rate varies with time, UsdConverter uses ExchangeRateService to get the latest updates.
// Moreover, getUsd method of a live ExchangeRateService can send a request over HTTP to get the actual exchange rate,
// which is difficult to reproduce in the test environment.
// Mockito allows us to avoid those difficulties and provides an API for creating empty objects and managing behavior.
// Note: here we use BigDecimal since financial transactions need high accuracy:
public class UsdConverter {
@ram0973
ram0973 / Sum.java
Last active March 11, 2021 16:31
Test sum
package com.javarush.task.task04.task0442;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
int number = 0;
@ram0973
ram0973 / tokens.md
Created April 26, 2021 17:32 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
connections {
rw {
pools = primary-pool
local {
auth = pubkey
certs = cert.pem
id = certificate_domain_name
}
remote {
auth = eap-mschapv2
@ram0973
ram0973 / gist:272f0c60ecf1f7b31e566c4255448934
Last active October 3, 2022 12:59
Iptables rules for IPSEC IKEV2 VPN
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT # SSH
iptables -A INPUT -p udp --dport 500 -j ACCEPT # for ISAKMP (handling of security associations)
iptables -A INPUT -p udp --dport 4500 -j ACCEPT # for NAT-T (handling of IPsec between natted devices)
iptables -A INPUT -p 50 -j ACCEPT # ESP - IP port 50 for ESP payload (the encrypted data packets)
iptables -A INPUT -j DROP
# Protect from trafic routing outside (WAN). Use outer interface here if any
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A FORWARD -j REJECT
@ram0973
ram0973 / Main.java
Created October 17, 2022 09:50
Викторина
package org.example;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
@ram0973
ram0973 / test.json
Created October 17, 2022 09:52
Викторина
{
"questions": [
"Question1",
"Question2"
],
"answers": [
{
"options": [
"Variant1",
"Variant2"
@ram0973
ram0973 / hugo.sh
Created October 17, 2022 14:05
Hugo push and start remote
cd ~/hugoblog; git add --all; git commit -m "next commit"; git push; ssh me "cd /web/yabbarov.ru/hugoblog; git pull; hugo"