Skip to content

Instantly share code, notes, and snippets.

View y-fedorov's full-sized avatar
🧑‍💻

Yaroslav Fedorov y-fedorov

🧑‍💻
View GitHub Profile
@y-fedorov
y-fedorov / atoi.cpp
Last active June 13, 2018 14:58
8. String to Integer (atoi)
/*
Implement atoi which converts a string to an integer.
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.
If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed.
If no valid conversion could be performed, a zero value is returned.
@y-fedorov
y-fedorov / reverseWords.cpp
Last active June 13, 2018 16:05
151. Reverse Words in a String
/*
Given an input string, reverse the string word by word.
Example:
Input: "the sky is blue",
Output: "blue is sky the".
Note:
@y-fedorov
y-fedorov / Info.txt
Last active November 26, 2018 14:48
C++ to Objective-C accessor
based on: "A shortcut for wrapping Objective-C objects in C++"
http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++
don't forget to turn off ARC:
You can disable ARC for individual files in XCode under the 'Build Phases' tab in the build target's properties.
Fold out the 'Compile Sources' section and add `-fno-objc-arc` to the compiler flags for the file(s) in question.
for MyObject.mm (`-fno-objc-arc`)
@y-fedorov
y-fedorov / copy_assignment_operator_example.cpp
Last active March 23, 2019 10:30
// Copy assignment operator implementation
#include <iostream>
#include <string>
#include <memory>
#include <algorithm>
class DataObject {
public:
DataObject(std::string_view value)
@y-fedorov
y-fedorov / std_bind_example_1.cpp
Last active March 23, 2019 10:51
std::bind example
#include <iostream>
// Example from Jason Turner's video.
// https://youtu.be/JtUZmkvroKg?t=290
void print(int i, const std::string_view s) {
std::cout << i << ' ' << s << '\n';
}
int main() {
@y-fedorov
y-fedorov / std_function_example_1.cpp
Created March 23, 2019 11:04
std::function example
#include <iostream>
// Example from Jason Turner's video.
// https://youtu.be/JtUZmkvroKg?t=290
template <typename T>
void print(T i, const std::string_view s) {
std::cout << i << ' ' << s << '\n';
}
@y-fedorov
y-fedorov / bad_example.cpp
Created March 25, 2019 08:52
BAD Example of code. C++
/*
* Learning C++ Best Practices :: Avoid Defining Any Default Operations, Or Define Them All (Jason Turner)
* https://learning.oreilly.com/videos/learning-c-best/9781491954898/9781491954898-video241545
*/
#include <string>
struct S {
~S() {};
std::string s;
@y-fedorov
y-fedorov / randomStringUtils.java
Created November 6, 2019 10:30
Generate random Cyrillic character
public class RandomStringUtils {
private static final SecureRandom RANDOM = new SecureRandom();
private static final String cyrillicCharacters = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
public static String generateRandomCharacter(){
int randomCharIndex = RANDOM.nextInt(cyrillicCharacters.length());
return String.valueOf(cyrillicCharacters.charAt(randomCharIndex));
}
}
@y-fedorov
y-fedorov / docker-compose.yml
Created November 8, 2019 14:32
Test kafka cluster with 3 nodes.
version: '3.1'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
- ZOOKEEPER_CLIENT_PORT=2181
- ZOOKEEPER_TICK_TIME=2000
ports:
- "32181:2181"
@y-fedorov
y-fedorov / Java_task_1
Last active November 18, 2019 15:34
Java tasks
Приложение: Менеджер карт
У Клиента есть набор различных карт (дебетовые, кредитные, скидочные) различных банков.
Каждая карта имеет номер, тип, дату истечения (месяц и год).
Номер карты представлен 20 символьной цифровой последовательностью.
Имя банка или магазина определяется первыми 4 символами номера.
Реализовать функциональность работы с картами клиента (добавление/удаление),
вывод списка клиентов и информацию о количестве его карт (с сортировкой по имени клиента)
вывод в консоль информацию в удобно читаемом виде по всем картам у конкретного клиента (в порядке убывания количества карт у клиента)