Skip to content

Instantly share code, notes, and snippets.

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.File;

Postgres - Simple Master-Slave Replication

This is insecure, fast-to-setup setup of simple master-slave replication with dockerized PostgreSQL installation. Note, that below works with version postgres version 12.2: postgres (PostgreSQL) 12.2 (Debian 12.2-1.pgdg100+1).

Preparation:

# This is where your primary database files will be stored
@avshabanov
avshabanov / Sample Sequence.md
Last active February 17, 2018 03:42
RPM for binary distribution

Create RPM

$ rpmdev-setuptree
... (=> in SOURCES)
$ install -m 755 hello       samplepkg-1.0/usr/bin/
$ install -m 644 hello.conf  samplepkg-1.0/etc/hello/
$ tar -zcvf samplepkg-1.0.tar.gz samplepkg-1.0/
... (=> in SPECS)
@avshabanov
avshabanov / Dockerfile
Last active March 1, 2018 07:24
CentOS docker image for Go development
# Build environment image
# Do the following to build and run:
# docker build -t bld-centos-7 .
# Once image is built, you can run it:
# docker run -it bld-centos-7 /bin/bash
# The same, but with mounted 'proj' folder:
# docker run -it --mount type=bind,source="$(pwd)"/proj,target=/proj bld-centos-7 /bin/bash
# The same, also initializes systemd and maps gopath's src into /goproj/src:
# docker run -d -e=container=docker --stop-signal=SIGRTMIN+3 --cap-add=SYS_ADMIN --security-opt=seccomp:unconfined -v /sys/fs/cgroup:/sys/fs/cgroup:ro --mount type=bind,source=$GOPATH/src,target=/goproj/src bld-centos-7 /sbin/init

Principles of Good Programming

The principles of good programming are closely related to principles of good design and engineering. The following programming principles have helped me over the years become a better programmer, and I believe can help any developer become more efficient and to produce code which is easier to maintain and that has fewer defects.

DRY - Don’t repeat yourself

This is probably the single most fundamental tenet in programming is to avoid repetition. Many programming constructs exist solely for that purpose (e.g. loops, functions, classes, and more). As soon as you start repeating yourself (e.g. a long expression, a series of statements, same concept) create a new abstraction. http://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Abstraction Principle

@avshabanov
avshabanov / Measurements.md
Created February 5, 2017 07:33
Brikar RPCv2 vs RPCv1

Preparations

echo '{"userIds": [10, 11, 12, 13, 14]}' > /tmp/queryUsersRequest.txt

Timings

The results of:

The biggest pain of using spring is its heavy use of classloaders...

This is something that happens with me when I try to use custom version of jackson:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultIndenter
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1116)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1060)
	at org.springframework.beans.factory.support.AbstractAutowire
@avshabanov
avshabanov / append-html-string.js
Created January 11, 2017 01:59
Append HTML String as DOM part
// NOTE: two approaches are possible here, one uses jquery abstractions (and works on pretty old browsers),
// while the other uses insertAdjacentHTML, the standard API in all the modern browsers (and old IEs too!).
//
// First approach (jquery way):
const $element = $($.parseHTML(htmlString));
$element.appendTo($container);
// Other approach (HTML, works on modern browsers):
$container.each(function () { this.insertAdjacentHTML('beforeend', htmlString); });
@avshabanov
avshabanov / tcpdump-hints.md
Created January 3, 2017 06:52
Cheatsheet for capturing TCP traffic with tcpdump

Sample traffic capture (loopback0 interface, port 11280, pcap format understandable by wireshark):

tcpdump -i lo0 -v -X port 11280 -s0 -w ~/Downloads/traffic1.pcap
<!-- Sample range enumeration -->
<div>
<#list 0..9 as x>
<span><img src="/demo/media/image" width="64" height="64"/></span>
</#list>
</div>