Skip to content

Instantly share code, notes, and snippets.

def highlight_oid(oid)
str = oid.to_s
rgx = /(?<ts>\w{8})(?<machine>\w{6})(?<process>\w{4})(?<counter>\w{6})/
m = str.match(rgx)
require 'colorize'
print m[:ts].red
print m[:machine].yellow
print m[:process].light_magenta
print m[:counter].green
puts
def ts_to_oid(timestamp)
unixtime = timestamp.to_i.to_s(16)
BSON::ObjectId.from_string(unixtime + '0' * 16)
end
@stulentsev
stulentsev / count_by.rb
Created July 27, 2017 07:05
The missing piece of ruby enumerable api
module Enumerable
def count_by(&block)
Hash[group_by(&block).map { |key,vals| [key, vals.size] }]
end
end
@stulentsev
stulentsev / file.txt
Created September 27, 2017 13:46
for usage in tests
hello world!
class Proc
def and(other_proc)
->(*args) { call(*args) && other_proc.call(*args) }
end
end
def word_or_number(n)
div3 = ->(x) { x.modulo(3).zero? }
div5 = ->(x) { x.modulo(5).zero? }
@stulentsev
stulentsev / gist:1366422
Last active October 30, 2017 08:57
Британские ученые text maker
str = "Today we (professors + teaching assistants) proctored a midterm exam for a class of about 80 students. There was undoubtedly a 'hardest' question on the exam, since nearly the entire classroom of students asked us how to proceed with that question. To be fair, we didn't give any hints, but it was clear that one had to use a definition to be able to proceed."
res = str.gsub(/\b[[:alpha:]]+\b/) do |word|
if word.length < 4
word
else
word[0] + # first letter
word[1..-2].chars.shuffle.join('') +
word[-1] # last letter
end
require 'openssl'
require 'jwt'
require 'awesome_print'
rsa_private = OpenSSL::PKey::RSA.generate 2048
rsa_public = rsa_private.public_key
payload = {
'data' => 'test',
'projects.quote.request' => true,
@stulentsev
stulentsev / golang_job_queue.md
Created December 23, 2018 01:46 — forked from harlow/golang_job_queue.md
Job queues in Golang
@stulentsev
stulentsev / boilerplate.cpp
Last active February 7, 2019 09:48
hackerrank boilerplate
#include <bits/stdc++.h>
using namespace std;
vector<string> split_string(string);
// Complete the sockMerchant function below.
int sockMerchant(int n, vector<int> ar) {
@stulentsev
stulentsev / keybase.md
Created February 7, 2019 22:06
keybase.md

Keybase proof

I hereby claim:

  • I am stulentsev on github.
  • I am stulentsev (https://keybase.io/stulentsev) on keybase.
  • I have a public key ASAHjuCvisMwyIgXMFulA_a6Bq9BCF8TWwp3KaPqXv3tago

To claim this, I am signing this object: