Skip to content

Instantly share code, notes, and snippets.

View brainwire's full-sized avatar

Vadim Gorbunov brainwire

View GitHub Profile
@brainwire
brainwire / Ansible-Vault how-to.md
Created February 24, 2016 08:29 — forked from tristanfisher/Ansible-Vault how-to.md
A short tutorial on how to use Vault in your Ansible workflow. Ansible-vault allows you to more safely store sensitive information in a source code repository or on disk.

##Working with ansible-vault

I've been using a lot of Ansible lately and while almost everything has been great, finding a clean way to implement ansible-vault wasn't immediately apparent.

What I decided on was the following: put your secret information into a vars file, reference that vars file from your task, and encrypt the whole vars file using ansible-vault encrypt.

Let's use an example: You're writing an Ansible role and want to encrypt the spoiler for the movie Aliens.

# coding: binary
class BMP
class Reader
PIXEL_ARRAY_OFFSET = 54
BITS_PER_PIXEL = 24
DIB_HEADER_SIZE = 40
def initialize(bmp_filename)
File.open(bmp_filename, "rb") do |file|
@brainwire
brainwire / timezones.ru.rb
Last active August 28, 2015 08:53 — forked from Envek/timezones.ru.rb
Full list of russian time zones for Ruby on Rails
# Full list of Russian Federation time zones with helper to get this list.
# Place this file in config/initializers/timezones.ru.rb
class ActiveSupport::TimeZone
@country_zones = ThreadSafe::Cache.new
def self.country_zones(country_code)
code = country_code.to_s.upcase
@country_zones[code] ||=
TZInfo::Country.get(code).zone_identifiers.select do |tz_id|
@brainwire
brainwire / Readme.md
Last active August 27, 2015 06:32 — forked from vodafon/Readme.md
Linking #GoLang lib in #Ruby
go build -buildmode=c-shared -o sum.so sum.go
ruby link.rb
@brainwire
brainwire / trgm.rb
Last active August 29, 2015 14:26 — forked from davetoxa/trgm.rb
require 'active_record'
require 'open-uri'
require 'pg'
require 'minitest/autorun'
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
database: 'trgm',
host: 'localhost',
username: 'postgres'
@brainwire
brainwire / angular_momentjs_binding_directive.js
Last active August 29, 2015 14:26 — forked from kolen/angular_momentjs_binding_directive.js
Two-way binding between form field and moment.js date object for angular.js. With validation.Date object is in UTC, form field displays local date.
directive('dateBinding', function() {
//var format = "YYYY-MM-DD HH:mm:ss"
//date.isValid() is not enough for strict validation, see moment.js doc
//var pattern = /^\s*\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}(:\d{2})?\s*$/
var parseFormat = attrs.dateBinding;
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
ngModel.$parsers.push(function(text) {
@brainwire
brainwire / ssh_client.go
Last active August 29, 2015 14:25 — forked from iamralch/ssh_client.go
SSH client in GO
package main
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"strings"
# http://www.evanmiller.org/bayesian-ab-testing.html implemented in ruby
# requires the distribution gem from https://github.com/clbustos/distribution (gem 'distribution', require: false)
def probability_b_beats_a(completed_a, total_a, completed_b, total_b)
require 'distribution/math_extension'
total = 0.0
alpha_a = completed_a + 1
beta_a = total_a - completed_a + 1
alpha_b = completed_b + 1
# позволяет получить процентное соотношение для чисел в массиве
# percents [1,2,3] => [0.16666666666666666, 0.3333333333333333, 0.5]
def percents(numbers)
total = numbers.inject(:+).to_f
numbers.map {|it| it / total }
end
# позволяет получить процентное распределение для чисел в массиве
# требуется чтобы генерировать рендомное число с заданными вероятностями
# distribution [1,2,3] => [0.16666666666666666, 0.5, 1.0]
100 = :continue
101 = :switching_protocols
102 = :processing
200 = :ok
201 = :created
202 = :accepted
203 = :non_authoritative_information
204 = :no_content
205 = :reset_content
206 = :partial_content