Skip to content

Instantly share code, notes, and snippets.

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 / file.txt
Created September 27, 2017 13:46
for usage in tests
hello world!
@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
def ts_to_oid(timestamp)
unixtime = timestamp.to_i.to_s(16)
BSON::ObjectId.from_string(unixtime + '0' * 16)
end
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
class Cell
attr_accessor :alive
attr_accessor :coordinates
attr_accessor :neighbours
attr_accessor :live_neighbours
def initialize(live_cell_ratio)
@alive = ([true] + Array.new(live_cell_ratio, false)).sample
@coordinates = []
@neighbours = []
package main
import (
"encoding/base64"
"fmt"
"github.com/VirgilSecurity/virgil-sdk-go"
"io/ioutil"
)
func main() {
% cat .git/hooks/pre-commit
#! /usr/bin/env ruby
puts "pre-commit hook: checking for forgotten debug statements"
debug_statements = [
'binding.pry',
'console.log',
':focus',
'focus: true',

When running this command for the first time

$ bundle exec rake db:create

you may get this error

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "username"=>"tulenmenu", "password"=>"tulenmenu", "database"=>"tulenmenu_development"}

FATAL: role "tulenmenu" does not exist

Uploading files to TextMaster

TextMaster uses AWS S3 for storage, so s3-compatible libraries/toolkits can be used (for example, EvaporateJS). However, it is quite simple to do it with a basic HTTP client library, which is capable of doing GET/PUT requests.

The process consists of 4 steps:

  1. Obtain a file you want to upload
  2. Construct HTTP PUT request that will upload the file
  3. Obtain a signature for the upload request
  4. Send the signed request