Skip to content

Instantly share code, notes, and snippets.

View Paxa's full-sized avatar

Pavel Evstigneev Paxa

View GitHub Profile
@Paxa
Paxa / gist:8080098
Created December 22, 2013 09:15
Textmate/sublime command to format markdown table
#!/usr/bin/env ruby
def format_table(table_str)
lines = table_str.split("\n")
collumn_widths = []
collumn_aligns = []
lines.each_with_index do |line, line_no|
line.split("|").each_with_index do |column_data, col_no|
column_data = column_data.strip
if line_no == 1
@Paxa
Paxa / is_haml_benchmark.rb
Created July 11, 2013 07:29
Benchmarking HAML with RubyVM::InstructionSequence
# benchmark haml templates compiled with RubyVM::InstructionSequence
require "rubygems"
require "bundler/setup"
require "haml"
require "rbench"
class ViewHelpers
include Haml::Helpers
@Paxa
Paxa / convert.rb
Created March 21, 2013 04:32
Convert all sass files to right syntax
files = Dir['**/**.sass']
files.each do |file|
old_style = `sass-convert -F sass -T sass --old #{file}`
old_style.gsub!(/(?<=\S)[\t ]+$/, '')
File.open(file, 'w:utf-8') do |f|
f.write old_style
end
puts file
end
@Paxa
Paxa / Задание.md
Last active December 11, 2015 03:39
Тестовые задания

Задание 1

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

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

Задание 2

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

@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 / 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 / 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 / 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 / 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 / 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;