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 / 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 / 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 / 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 / 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 / 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 / validNumber.cpp
Created June 13, 2018 10:35
65. Valid Number
/*
Validate if a given string is numeric.
Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true
@y-fedorov
y-fedorov / RLE.cpp
Last active May 22, 2018 08:46
Run-length encoding implementation Example
#include <vector>
#include <iostream>
#include <sstream>
std::string RLE(std::string data) {
std::stringstream ss;
auto size = data.size();
size_t sequenceCounter = 0;
for (size_t i = 0; i < size; i++) {
auto currentChar = data[i];
@y-fedorov
y-fedorov / stringRotate.cpp
Last active May 22, 2018 09:18
String Rotate
#include <vector>
#include <iostream>
#include <string>
std::string simpleRotate(const std::string data) {
return std::string(data.rbegin(), data.rend());
}
std::string badRotate(std::string data) {
auto size = data.size();
@y-fedorov
y-fedorov / BubbleSort.cpp
Last active May 22, 2018 08:00
BubbleSort.cpp
#include <vector>
#include <iostream>
template<class T>
std::vector<T> bubbleSort(std::vector<T> data) {
bool changed;
do {
changed = false;
# debian
apt-get install vim curl sudo tmux htop mc
apt-get install git