Skip to content

Instantly share code, notes, and snippets.

View habibutsu's full-sized avatar

Alexander Verbitsky habibutsu

View GitHub Profile
@habibutsu
habibutsu / Makefile
Created October 12, 2015 12:20
Make executable archive tar.gz for python
define RUN_SCRIPT
import tarfile
import StringIO
import imp
import runpy
PKG_NAME = "some_module"
if __name__ == '__main__':
tar_fd = StringIO.StringIO(PKG_DATA)
@habibutsu
habibutsu / snippets.erl
Created November 13, 2015 18:15
Inspect RabbitMQ
% For running can be used 'rabbitmqctl'
% Example:
% sudo rabbitmqctl eval 'node().'
% Find process with the largest memory consumption
lists:sublist(
lists:reverse(
lists:sort([{process_info(Pid, memory), Pid, process_info(Pid)} || Pid <- processes()])), 1).
% get all vhosts
@habibutsu
habibutsu / README.md
Last active March 10, 2016 18:56
Simple do-notation in Erlang without parse-tranform

Overview

Simplest implementation of do-notation in Erlang without using parse-tranform

do

<<"16.0">> = pipeline:do(0, [
    fun(X) -> X+1 end,
    fun(X) -> X+3 end,
@habibutsu
habibutsu / Makefile
Last active February 5, 2016 14:50
web-project
all: build
init:
opam init -a
opam pin add web-project . -n
get-deps:
opam install --deps-only web-project
@habibutsu
habibutsu / partitioning_functions.sql
Last active December 4, 2024 02:00
Postgresql / Sharding & Partitioning
create or replace
function partition_insert_trigger() returns trigger
language 'plpgsql' as $$
declare
column_name text := TG_ARGV[0];
columnt_format text := TG_ARGV[1];
column_value timestamp;
table_name text;
insert_stmt_tpl text := 'insert into %I select ($1).*';
insert_stmt text;
@habibutsu
habibutsu / lists.md
Last active February 19, 2016 08:22
Erlang

List

Internal implementation

Erlang list is a singly linked list. Each item has a size of 2 Eterm: one for storing value, second for storing the pointer to next item.

When you append new element to the list:

  • is created a new copy
  • and then to the last element is set the pointer to list that needed to append
@habibutsu
habibutsu / ooooops.md
Last active February 24, 2016 17:17
oooops

#OOOOOPS

Coding just for fun and relaxing

OOOOOPS

% erlc oooops.erl; erl -noshell -s oooops main -s init stop
-module(oooops).
@habibutsu
habibutsu / example.erl
Created March 25, 2016 19:01
Erlang: eval & compile
-module(test).
-compile([export_all]).
-links([
"https://github.com/efcasado/forms",
"https://github.com/matwey/pybeam",
"https://gist.github.com/kuenishi/3183043",
"https://github.com/hypernumbers/LuvvieScript",
"https://github.com/erlang/otp/blob/OTP-18.2/lib/compiler/src/genop.tab",
@habibutsu
habibutsu / snippets.sh
Created April 21, 2016 11:50
Bash-snippets
# check elapsed time after last modification
# not often than once at 15 minutes
if [ $(( $(date +%s) - $(stat --format %Y "some_file.txt") )) -gt 900 ]
then
echo "old"
fi
@habibutsu
habibutsu / mercator_projection.js
Created May 13, 2016 10:21
Mercator projection
// https://en.wikipedia.org/wiki/Mercator_projection
function MercatorProjection(){
this.EARTH_RADIUS = 6378137 // WGS-84
this.EARTH_HALF_CIRCUMFERENCE = Math.PI * this.EARTH_RADIUS // 20037508.342789244
this.EARTH_METERS_PER_DEGREE = (Math.PI * this.EARTH_RADIUS) / 180 // 111319.49079327358
this.RADIAN = Math.PI / 180
this.DEGREE = 180 / Math.PI
}