Skip to content

Instantly share code, notes, and snippets.

View kaineer's full-sized avatar
:octocat:
⌨️ 🖱️

Sergey Kluchkovsky kaineer

:octocat:
⌨️ 🖱️
View GitHub Profile
@kaineer
kaineer / itsu.rb
Created September 16, 2010 07:12
Транслитерация qwerty -> йцукенг
localhost@~:$ itsu "eue? z nfr b levfkf? xnj xnj-nj ghjgecnbkb"
угу, я так и думала, что что-то пропустили
@kaineer
kaineer / integer_pluralize.rb
Created September 17, 2010 05:56
Плюрализатор на ruby
## Output
1 фонарь
21 фонарь
11 фонарей
2 фонаря
20 фонарей
100 фонарей
@kaineer
kaineer / author.rb
Last active July 20, 2019 13:31
SQL-запросы (ActiveRecord)
class Author < ActiveRecord::Base
has_many :links, :class_name => "BookAuthorLink"
has_many :books, :class_name => "Book", :through => :links, :source => :books
# Получение списка авторов, не имеющих книг
def self.without_books
self.find_by_sql( "SELECT a.* FROM authors AS a " +
"LEFT OUTER JOIN book_author_links AS l ON l.author_id = author.id " +
"WHERE l.id IS NULL" )
# Использован один и тот же рецепт из "SQL. Сборник рецептов" Энтони Молинаро
@kaineer
kaineer / btree.rb
Created November 18, 2010 11:45
Имплементация btree
#!/usr/bin/ruby
class BTree
class Node
def initialize( tree, offset, start_value )
@tree = tree
@offset = offset
@values = [ start_value ]
@subtree_offsets = [ nil ] * ( @tree.elements_per_node + 1 )
@kaineer
kaineer / test_helper.rb
Created November 24, 2010 05:23
Определяем, что тесты запущены из Emacs Shell
require 'rubygems'
require 'test/spec'
require 'mocha'
# Do not load redgreen when loaded from eshell
#
unless ENV[ "EMACS" ] == "t"
require 'redgreen'
end
@kaineer
kaineer / gist:785790
Created January 19, 2011 06:46
Rake task for copying files from previous sinatra project
desc "Call this when creating new project"
task :bootstrap do
# Clean just edited rakefile ;)
sh( "rm *~" ) unless Dir[ "*~" ].empty?
# Directories..
@prev = ENV[ "PREV" ] || "azsservice"
sh( "mkdir -p app/controllers" )
sh( "mkdir -p app/views" )
sh( "mkdir -p app/models" )
@kaineer
kaineer / gist:836908
Created February 21, 2011 10:37
~/bin/mkram - creating temporary ram-disk
#!/usr/bin/env ruby
module MkRam
class Path
def initialize
@path = File.expand_path( "~/ram" )
end
def to_s
@path
end
@kaineer
kaineer / gist:948198
Created April 29, 2011 11:47
Пример конфигурации, как оно может выглядеть
== config/queries.yml
output_encoding: cp1251 # utf-8, cp866 etc.
input_encoding: cp1251
query_sources:
google: # name for query engine
base: "http://news.google.com/news/search?pz=1&cf=all&ned=ru_ru&hl=ru&q=%s"
stories:
css: "#search-stories .story"
title:
@kaineer
kaineer / RUBY STYLE.md
Created May 12, 2011 09:27
devmen styleguides

Christian Neukirchen's Ruby Style Guide

Original here

You may not like all rules presented here, but they work very well for me and have helped producing high quality code. Everyone is free to code however they want, write and follow their own style guides, but when you contribute to my code, please follow these rules:

@kaineer
kaineer / gist:1079920
Created July 13, 2011 08:14
Codemirror guts
+-wrapper-----------------------------------------------------------+ // wrapper element
: +--inputDiv---------------------------------------------------+ :
: : * input : : // textarea replace
: +-------------------------------------------------------------+ :
: +--scroller---------------------------------------------------+ :
: : +--code-------------------------------------------------+ : :
: : : * measure : : :
: : : +--mover------------------------------------------+ : : :
: : : : +--gutter-----------------------------------+ : : : :
: : : : : *gutterText : : : : :