Skip to content

Instantly share code, notes, and snippets.

View Paxa's full-sized avatar

Pavel Evstigneev Paxa

View GitHub Profile
@Paxa
Paxa / attachment.rb
Created September 8, 2011 03:12
video encoder snippet
class Attachment < ActiveRecord::Base
belongs_to :post
mount_uploader :filename, PostAttachmentUploader
VIDEO_FORMATS = %W{ogv mp4 webm}
PREVIEW_FORMAT = "jpeg"
before_save :set_metas
after_create :start_encoding!, :if => :video?
@Paxa
Paxa / application.rb
Created November 20, 2011 08:12
Simple background processing
# config/application.rb
def Rails.bg_runner(code)
ruby_cmd = code.gsub(/("|\s)/) {|m| "\\#{m}" }
cmd = %{cd #{Rails.root} && ./script/background #{Rails.env} "#{ruby_cmd}"}
Rails.logger.info "IN BACKGROUND #{cmd}"
Rails.logger.info system(cmd)
end
@Paxa
Paxa / 1.html
Created February 24, 2012 03:16
Microdata breadcrumbs test
<!DOCTYPE html>
<html>
<head>
<title>Breadcrumb example - webpage_2.html</title>
</head>
<body>
<section itemscope itemtype='http://schema.org/WebPage'>
<a href='/books'><span itemprop='breadcrumb'>Books</span></a> >
<a href='/books/authors'><span itemprop='breadcrumb'>Authors</span></a> >
<a href='/books/authors/stephen-king'><span itemprop='breadcrumb'>Stephen King</span></a>
@Paxa
Paxa / bind.js
Created July 20, 2012 03:51
Function.prototype.bind
Function.prototype.bind = function(that){
var self = this,
args = arguments.length > 1 ? Array.slice(arguments, 1) : null,
F = function(){};
var bound = function(){
var context = that, length = arguments.length;
if (this instanceof bound){
F.prototype = self.prototype;
context = new F;
@Paxa
Paxa / cirillic.rb
Created July 24, 2012 02:29
Add "# encoding: utf-8" to files with russian characters
# encoding: utf-8
(Dir['app/**/**.rb'] + Dir['app/**/**.rake']).each do |file|
content = File.open(file, 'r:utf-8', &:read)
if content =~ /[а-яА-Я]+/ && content.split("\n").first !~ /coding: utf\-8/i
puts "UTF file #{file}"
File.open(file, 'w:utf-8') do |f|
f.write "# encoding: utf-8\n"
f.write content
end
@Paxa
Paxa / Rakefile
Created September 26, 2012 02:15
Rails 2.3 gem rake-tasks loader
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rdoc/task'
require 'tasks/rails'
@Paxa
Paxa / basic.ru
Created October 18, 2012 11:00
Async request handling with sinatra and EM
#!/usr/bin/env rackup -Ilib:../lib -s thin
# async message handling
# using gem https://github.com/raggi/async_sinatra
require 'sinatra/async'
module Handler
extend self
@pool = []
@Paxa
Paxa / basic.ru
Created October 20, 2012 02:51 — forked from charger/basic.ru
Async request handling with sinatra and EM, freeze if request not exist URL
#!/usr/bin/env rackup -Ilib:../lib -s thin
# async message handling
# using gem https://github.com/raggi/async_sinatra
require 'sinatra/async'
require "em-http-request"
require "em-synchrony"
require "em-synchrony/em-http"
@Paxa
Paxa / gist:4390042
Created December 27, 2012 17:16 — forked from ulitiy/gist:4389722
def make_square(n)
height = Math.sqrt(n)
throw "Input incorrect" unless height == height.to_i
x = ((height - 1) / 2).floor
y = ((height - 1) / 2).ceil
height = height.to_i
direction = 0
mat = []
(0 .. n - 1).each do |i|
mat[y] ||= []
@Paxa
Paxa / Задание.md
Last active December 11, 2015 03:39
Тестовые задания

Задание 1

Плюрализация русских слов. Т.е. делать множественную форму. например дом -> дома, стул -> стулья.

  • Дополнительная часть 1: сделать в обратную сторону.
  • Дополнительная часть 1: оформить чтобы встраивался в rails. "дом".pluralize # => "дома" и "дома".singularize # => "дом"

Задание 2

Сделать сервис для обратной связи для встраивания в сайты. Пишем сообщение, отсылаем, оно сохраняется, администратор получает емэйл. Сообщение содержит: имя, телефон или емэйл и текст сообщения.