Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / websockets.md
Last active November 17, 2020 08:36
Persistent Connection Services - Pricing

Here I'm interested in a use case of subscribers keeping a permanent connection open (24/7), but with negligible amount of messages. So I'm only concerned about price per connection, not price per message.

AWS API Gateway

https://aws.amazon.com/api-gateway/pricing/

$0.25 per million connection minutes

That's $1 per 4 million connection minutes.

@mahemoff
mahemoff / README.md
Last active April 6, 2024 00:38
Vim Terminal Mode - A short introduction

Vim has a Terminal Mode!

Since v8.1 (May 2018), Vim has shipped with a built-in terminal. See https://vimhelp.org/terminal.txt.html or type :help terminal for more info.

Why use this? Mainly because it saves you jumping to a separate terminal window. You can also use Vim commands to manipulate a shell session and easily transfer clipboard content between the terminal and files you're working on.

Key Bindings

@mahemoff
mahemoff / README.md
Last active August 28, 2020 23:37
Generate a strong password in bash

A wrapper for pwgen. Put this in your ~/.bashrc to generate a long & strong password. You can append an optional message to remind yourself of the purpose if you can't immediately transfer it to a credentials repository.

Example usage:

$ hardpass
ZzVMh:u(?ln134`q&PW9rmM0h]rRQ6p-#tv\3I.7
$ hardpass
OXX]k%e1/o-njU0XIK'UT@=\,9OeUGOr
$ hardpass new twitter password
### new twitter password
@mahemoff
mahemoff / README.md
Last active August 26, 2020 07:16
Split mbox file into N parts
### Keybase proof
I hereby claim:
* I am mahemoff on github.
* I am mahemoff (https://keybase.io/mahemoff) on keybase.
* I have a public key ASAG4tJDQ2HpifE_ViR49cBZWw75E2MeiYX5PpTpxoJADgo
To claim this, I am signing this object:
```json
{
"body": {
"key": {
@mahemoff
mahemoff / README.md
Last active February 5, 2020 09:05
WikiData Sample JSON dump
@mahemoff
mahemoff / bench.rb
Last active September 6, 2019 14:02
in versus include
#!/usr/bin/env ruby
require 'benchmark'
require 'active_support/all'
puts 'in', Benchmark.measure { 90000.in?(1..99000)}
puts 'include', Benchmark.measure { (1..99000).include? 90000 }
@mahemoff
mahemoff / parallel_array.rb
Created June 29, 2019 08:57
Extending Array with Parallel gem
class Array
%w(each map each_with_index map_with_index flat_map any? all?).each { |meth|
define_method("#{meth}_in_parallel") { |&block|
Parallel.send(meth, self) { |item| block.call(item) }
}
}
}
@mahemoff
mahemoff / backup.sh
Created February 2, 2019 17:19
mysql incremental backup
#!/bin/bash
function slice() {
lower=$1
upper=$(expr $lower + 100000)
echo "Backing up $lower"
mysqldump db_name table_name --opt --no-create-info --where "id > $lower and id <= $upper" | gzip -c | ssh user@host "cat > /home/backup/dump$lower.gz"
}
lower=0