Skip to content

Instantly share code, notes, and snippets.

@melontron
melontron / physics_dictionary
Last active May 5, 2020 14:44
In this dictionary I've listed common Arminian words that are being used in physics. This can be use-full when using spellchecks. Words are sorted from most popular to least popular.
են
Են
որ
Որ
եւ
Եւ
այն
Այն
միայն
Միայն
function decorate(object_path, method, pos='after', obj) {
const chain = object_path.split('.');
let object = obj || this;
for (let i =0; i < chain.length - 1; i++) {
if (!object[chain[i]]) throw new Error(`Invalid decoration ${object_path}`);
object = object[chain[i]];
}
if ('before' === pos) {

Keybase proof

I hereby claim:

  • I am melontron on github.
  • I am melontron (https://keybase.io/melontron) on keybase.
  • I have a public key ASAVjhcKGNqJq4xgMO-7y2a5s4q6uCbaG6bIlolFyjIs7Ao

To claim this, I am signing this object:

@melontron
melontron / nat.tf
Created August 2, 2019 12:59
Nat module with Elasticache port forwarding
resource "aws_security_group" "nat" {
name = "${var.env}-${var.project}-vpc-nat-sg"
description = "Allow traffic to pass from the private subnet to the internet"
ingress {
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = "${var.private_subnet_cidrs}"
}
@melontron
melontron / outputs.tf
Last active August 1, 2019 21:30
Terraform series VPC
output "vpc_id" {
value = "${aws_vpc.default.id}"
}
output "public_subnets" {
value = ["${aws_subnet.us-east-1a-public.id}","${aws_subnet.us-east-1b-public.id}"]
}
output "private_subnets" {
value = ["${aws_subnet.us-east-1a-private.id}","${aws_subnet.us-east-1b-private.id}"]
@melontron
melontron / client.js
Last active November 16, 2018 15:52
simple websocket client
const WebSocket = require('ws');
const ws = new WebSocket('ws://localhost:8080/path',["my-custom-subprotocol"], {
headers: {token: "some_super_secret_token"}
});
ws.on('open', function open() {
ws.send('something ' + Math.random());
});
@melontron
melontron / server.js
Last active November 16, 2018 16:07
Simple web socket server example
let WebSocketServer = require('ws').Server;
let wss = new WebSocketServer({
verifyClient: function (info, cb) {
let token = info.req.headers.token;
if (!token)
cb(false, 401, 'Unauthorized');
else {
// here should be your authorization logic
@melontron
melontron / websocket-handshake
Last active November 15, 2018 14:33
Handshakes of client and server of web-socket protocol
The handshake from the client looks as follows:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
const WebSocket = require('ws');
const ws = new WebSocket('ws://username@localhost:8080/path', {
headers: {token: "melo"}
});
ws.on('open', function open() {
ws.send('something ' + Math.random());
});