Skip to content

Instantly share code, notes, and snippets.

stulentsev / gist:1366422
Last active Oct 30, 2017
Британские ученые text maker
View gist:1366422
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[0] + # first letter
word[1..-2].chars.shuffle.join('') +
word[-1] # last letter
View regru.rb
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:"
puts " username: test"
stulentsev / checker.rb
Created Oct 23, 2012
DNS resolver / speed checker for
View checker.rb
# Example output:
# Resolved IP addresses for
# Loading from took 0.370469 seconds
# Loading from took 1.037444 seconds
# Loading from took 1.38692 seconds
stulentsev / gist:4169314
Created Nov 29, 2012
Simple unicorn upstart script
View gist:4169314
description "start and stop unicorn"
version "1.0"
author "Sergio Tulentsev"
#expect fork
cd /srv/stats/current && /home/sergio/.rvm/bin/r193_bundle exec unicorn_rails -E production -c config/unicorn.rb
end script
stulentsev / mongotop_handller.rb
Created Dec 13, 2012
A small ruby script to aggregate output of mongotop MongoDB command
View mongotop_handller.rb
# 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 = + 6, w + 6,
stulentsev / grep_yaml.rb
Created Apr 4, 2014
script to search yaml files
View grep_yaml.rb
#! /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 / excel_eval.rb
Created Sep 26, 2015
Recursive Excel-like evaluator
View excel_eval.rb
require 'awesome_print'
require_relative 'table_evaluator.rb'
def print_test(label, expectation)
evaluator =
actual = yield(evaluator)
if actual == expectation
puts "#{label}: PASS"

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

View pre-commit.rb
% cat .git/hooks/pre-commit
#! /usr/bin/env ruby
puts "pre-commit hook: checking for forgotten debug statements"
debug_statements = [
'focus: true',