Skip to content

Instantly share code, notes, and snippets.

View nkapliev's full-sized avatar
🎯
Focusing

Nick Kapliev nkapliev

🎯
Focusing
View GitHub Profile
@nkapliev
nkapliev / test_1.cpp
Last active December 7, 2017 12:50
Compilation error if field class does not have default constructor and the field was not initialized during pre-constructor initialization.
#include <iostream>
class Point {
public:
int x;
int y;
Point() {
std::cout << "A point has been initialized by default constructor" << std::endl;
@nkapliev
nkapliev / Makefile
Last active March 19, 2020 12:10
Linux kernel 4.4+ netfilter packet capturing boilerplate.
obj-m += ip_mac_packet_logger.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
install:
insmod ip_mac_packet_logger.ko
#include <iostream>
#include <stdio.h>
using namespace std;
class cStack
{
private:
int A[255];
int ptr;
public:
@nkapliev
nkapliev / gcd.js
Last active September 9, 2016 10:46
Greatest common divisor in Javascript @see: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
var gcd = function(a, b) {
var coef = 1;
while (
a !== b &&
a !== 0 &&
b !== 0 &&
a !== 1 &&
b !== 1
) {
@nkapliev
nkapliev / getftree.sh
Created June 28, 2016 16:12
Amazing fractal tree on bash
# @see https://www.hackerrank.com/challenges/fractal-trees-all
# Creating a Fractal Tree from Y-shaped branches
#
# This challenge involves the construction of trees, in the form of ASCII Art.
#
# We have to deal with real world constraints, so we cannot keep repeating the pattern infinitely.
# So, we will provide you a number of iterations, and you need to generate the ASCII version
# of the Fractal Tree for only those many iterations (or, levels of recursion). A few samples are provided below.
#
# Input Format
@nkapliev
nkapliev / range.js
Created April 18, 2016 14:41
js range
Array.apply(null, {length: N}).map(Number.call, Number)
for f in aaa*; do mv $f $(echo $f | sed 's/^aaa/bbb/g'); done
integration :: (Double -> Double) -> Double -> Double -> Double
integration f a b | a == b = 0
| otherwise = coeff * dx * ((f begin + f end) / 2 + helper (begin + dx) 0 (numberOfSteps - 1))
where
begin = min a b
end = max a b
numberOfSteps = 1000
coeff = if end == a then (-1) else 1
dx = (end - begin) / numberOfSteps
helper x sum n | n == 0 = sum
fibonacci :: Integer -> Integer
fibonacci 0 = 0
fibonacci 1 = 1
fibonacci (-1) = 1
fibonacci (-2) = (-1)
fibonacci n | n > 0 = helper (fibonacci 0) (fibonacci 1) (n - 2)
| n < 0 = helper (fibonacci (-1)) (fibonacci (-2)) (n + 3)
helper :: Integer -> Integer -> Integer -> Integer
helper a b n | n == 0 && a > b = a - b