Skip to content

Instantly share code, notes, and snippets.

View stulentsev's full-sized avatar

Sergio Tulentsev stulentsev

View GitHub Profile
@stulentsev
stulentsev / grep_yaml.rb
Created April 4, 2014 16:36
script to search yaml files
#! /usr/bin/env ruby
require 'yaml'
require 'colorize'
filename = ARGV[0]
pattern_text = ARGV[1]
unless filename && pattern_text
puts "Usage: grep_yaml.rb filename pattern"
@stulentsev
stulentsev / excel_eval.rb
Created September 26, 2015 10:15
Recursive Excel-like evaluator
require 'awesome_print'
require_relative 'table_evaluator.rb'
def print_test(label, expectation)
evaluator = TableEvaluator.new
actual = yield(evaluator)
if actual == expectation
puts "#{label}: PASS"
@stulentsev
stulentsev / regru.rb
Created October 22, 2012 10:37
reg.ru task
require 'optparse'
require 'open-uri'
require 'json'
if ARGV.length == 0
puts "Usage: ruby regru.rb --domain NAME --username USER --password PWD"
puts "Defaults: "
puts " domain: google.com"
puts " username: test"
@stulentsev
stulentsev / checker.rb
Created October 23, 2012 06:46
DNS resolver / speed checker for reg.ru
# Example output:
#
# Resolved IP addresses for www.reg.ru:
#     31.31.204.42
#     31.31.204.21
#     31.31.205.41
#
# Loading from 31.31.204.42 took 0.370469 seconds
# Loading from 31.31.204.21 took 1.037444 seconds
# Loading from 31.31.205.41 took 1.38692 seconds
@stulentsev
stulentsev / gist:4169314
Created November 29, 2012 14:09
Simple unicorn upstart script
description "start and stop unicorn"
version "1.0"
author "Sergio Tulentsev"
#expect fork
script
cd /srv/stats/current && /home/sergio/.rvm/bin/r193_bundle exec unicorn_rails -E production -c config/unicorn.rb
end script
@stulentsev
stulentsev / mongotop_handller.rb
Created December 13, 2012 21:49
A small ruby script to aggregate output of mongotop MongoDB command
# Usage:
# mongotop --host host --port port | ruby mongotop_handler.rb
require 'curses'
include Curses
def print_stats stats, time_elapsed
h = stats.length
w = 130
win = Window.new(h + 6, w + 6,

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

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

package main
import (
"encoding/base64"
"fmt"
"github.com/VirgilSecurity/virgil-sdk-go"
"io/ioutil"
)
func main() {
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 = []