Skip to content

Instantly share code, notes, and snippets.

View andreichernov's full-sized avatar

andreichernov andreichernov

View GitHub Profile
@andreichernov
andreichernov / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@andreichernov
andreichernov / trim
Created April 30, 2015 07:21
trim: удаляет завершающие пробелы, табуляции и новые строки
/* trim: удаляет завершающие пробелы, табуляции и новые строки */
int trim(char s[])
{
int n;
for (n = strlen(s) - 1; n >= 0; --n)
{
if ((s[n] != ' ') && (s[n] != '\t') && (s[n] != '\n'))
break; // выходим из цикла, встретив печатаемый символ
}
s[n+1] = '\0';
@andreichernov
andreichernov / PrintPositives
Created April 30, 2015 08:26
PrintPositives
void PrintPositives(int array[], int arraySize)
{
int i;
for (i = 0; i < arraySize; i++)
{
if (array[i] < 0) /* пропуск отрицательных элементов */
continue;
printf("%d ", array[i]);
}
}
@andreichernov
andreichernov / function_overload_example
Created April 30, 2015 08:32
пример перегрузки
#include <stdio.h>
void Print(int number)
{
printf("%d", number);
}
void Print(double number)
{
printf("%.15f", number);
}
class IntStack
{
public:
void Push(int value);
int Pop();
bool isEmpty() const;
private:
// здесь располагаются данные
// необходимые для реализации стека целых чисел
@andreichernov
andreichernov / наследование
Created April 30, 2015 09:58
Наследование позволяет описать новый класс на основе уже существующего родительского (базового) класса
class Plane
{
public:
void TakeOff();
void Fly();
void Land();
private:
double m_fuel;
};
@andreichernov
andreichernov / полиморфизм
Created April 30, 2015 10:21
Полиморфизм - явление, при котором классы-потомки могут изменять реализацию метода класса-предка, сохраняя его интерфейс
// Полиморфизм - классы-потомки могут изменять реализацию метода класса-предка, сохраняя его интерфейс
class Shape
{
public:
virtual ~Shape()
{
}
virtual double GetArea() const = 0;
};
@andreichernov
andreichernov / объявление класса
Created April 30, 2015 10:25
Для объявления класса в C++ служит ключевое слово class
// пример объявления класса
class Date
{
public:
void Next();
void Print() const;
private:
int year, month, day;
};
@andreichernov
andreichernov / latency.txt
Created April 26, 2017 20:20 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@andreichernov
andreichernov / noip2.service
Created April 28, 2019 20:26 — forked from NathanGiesbrecht/noip2.service
Systemd Service file for no-ip.com dynamic ip updater
# Simple No-ip.com Dynamic DNS Updater
#
# By Nathan Giesbrecht (http://nathangiesbrecht.com)
#
# 1) Install binary as described in no-ip.com's source file (assuming results in /usr/local/bin)
# 2) Run sudo /usr/local/bin/noip2 -C to generate configuration file
# 3) Copy this file noip2.service to /etc/systemd/system/
# 4) Execute `sudo systemctl enable noip2`
# 5) Execute `sudo systemctl start noip2`
#