Skip to content

Instantly share code, notes, and snippets.

View apavlyut's full-sized avatar

Alexander Pavlyut apavlyut

View GitHub Profile
@apavlyut
apavlyut / Torg12
Last active December 16, 2015 03:48
<!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%= stylesheet_link_tag "print_order", :media => "print, screen" %>
</head>
<body>
<p align="right">
Унифицированная форма № ТОРГ- 12 Утверждена постановлением Госкомстата России от 25.12.98 № 132
# ruby 2.0
str = "\u0000\u0001\u000177773705257\u0000\u0000\u0001559#81635181\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\b\u0000\b\u0004!\u0004\"\u0004\u001E\u0004\u001F"
puts "str:\n"
puts str
puts "\n here relults for str:"
yes = str.force_encoding("utf-16be").encode("utf-8")
puts yes
puts yes.include?('СТОП')
puts str.force_encoding("utf-16le").encode("utf-8")
@apavlyut
apavlyut / heroku_redirect.rb
Created April 23, 2014 09:29
Ловим на входе в heroku наши домены поддомены и что надо делаем.
# config/environments/production.rb
# ...
config.middleware.use HerokuRedirect
@apavlyut
apavlyut / heroku_redirect.rb
Last active August 29, 2015 14:00
Ловим на входе в heroku наши домены поддомены и что надо делаем.
# lib/heroku_redirect.rb
class HerokuRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
unless request.host.starts_with?("www.") || request.host.starts_with?("start.") || request.host.starts_with?("crm.") || request.host.starts_with?("api.") || request.host.starts_with?("erp.") || request.host.include?("mydomain.com") || request.host.include?("staging.")
# puts 'redirecting to www'
require 'tire'
require 'nobrainer'
NoBrainer.connect 'rethinkdb://server/company'
class Employee
include NoBrainer::Document
field :name
field :title
module Accessible
extend ActiveSupport::Concern
included do
has_many :accessibilities, as: :accessible, dependent: :destroy
has_many :roles, -> { uniq }, through: :accessibilities
scope :visible_to, ->(role_names) {
role_names = [role_names] if [String, Symbol].include?(role_names.class)
if role_names.include?(Role::ROOT_ROLE)
all
# connecting select2 to the appropriate hooks:
#
# hard case: best_in_place's select
$ ->
# first, find the mount point
$('body').on 'best_in_place:activate', '.best_in_place', ->
# second, attach empty update() to `this` to screen the downstream calls
# which otherwise will cause an error
heroku pg:backups capture;
curl -o latest.dump `heroku pg:backups public-url`;
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U pguser -d blog_development latest.dump;
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
# Задача: Программа получает ссылку на страницу, выбирает оттуда все ссылки которые найдет и выводит их на экран.
# Ограничения: программа должна получать ссылку от меня в интерактивном режиме (используя метод gets)
# Программа:
class Proga # создание класса "Программа"
puts "Please, input a web-site" # запрос у пользователя ссылки на сайт
link = gets.chomp # создание переменной link, в которую будет складываться ответ пользователя
puts "You enter #{link}" # вывести на экран значение переменной link