Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# MySQL root password
ROOTPASS='password'
TIMEZONE='Europe/Moscow'
MYSQLPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
SFTPPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
PASSWORD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
##############
class ListingsController < ApplicationController
def index
movie_listing_service = ServiceLocator.get_service_instance(:MovieListing)
@available_movies = movie_listing_service.available_movies
render nothing: true #this is just an example don't get hung up on it :)
end
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
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
# позволяет получить процентное соотношение для чисел в массиве
# 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]
# 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
@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"
@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 / 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 / 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