Skip to content

Instantly share code, notes, and snippets.

@yurivm
yurivm / websocket_echo.js
Created April 14, 2020 09:10
websocket echo
const http = require('http');
const WebSocket = require('ws');
const server = http.createServer();
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws, req) {
console.log('Incoming connection from %s', req.connection.remoteAddress);
clients.push(ws);
ws.on('close', function() {
console.log('%s disconnected', ws._socket.remoteAddress);
const id = clients.indexOf(ws);
@yurivm
yurivm / mumble_loop.js
Created April 14, 2020 09:04
mumble_loop.js
const net = require('net');
const clients = [];
function handleConnection(conn) {
function onConnData(d) {
const decoder = new StringDecoder();
// Decode received string
const stream = decoder.write(d);
try {
splitJson(stream).forEach((str) => clients.forEach((client) => client.send(str)));
@yurivm
yurivm / upgrade-postgres-9.5-to-9.6.md
Created November 1, 2017 14:20 — forked from delameko/upgrade-postgres-9.5-to-9.6.md
Upgrading PostgreSQL from 9.5 to 9.6 on Ubuntu 16.04

TL;DR

Install Postgres 9.5, and then:

sudo pg_dropcluster 9.6 main --stop
sudo pg_upgradecluster 9.5 main
sudo pg_dropcluster 9.5 main
@yurivm
yurivm / eq_hash_matcher.rb
Created May 27, 2016 13:51
expect(foo).to eq_hash(bar) : show hash diff in a table (very useful for nested hashes)
require "rspec/expectations"
require "hashdiff"
require "terminal-table"
RSpec::Matchers.define :eq_hash do |expected|
match do |actual|
HashDiff.diff(expected, actual).empty?
end
failure_message do |actual|
diff = HashDiff.diff(expected, actual)
class String
def to_bool
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
@yurivm
yurivm / gist:2867415
Created June 4, 2012 09:25
WhinyMonday module
module WhinyMonday
def included(mod)
mod.instance_methods.each {|m| mod.send(:remove_method,m)}
end
def method_missing(symbol, *args)
puts "On Monday, I don't #{symbol}"
end
end