Skip to content

Instantly share code, notes, and snippets.

View s0ber's full-sized avatar

Sergey Shishkalov s0ber

View GitHub Profile
@s0ber
s0ber / gist:0f5509635bcd06d37667
Last active August 29, 2015 14:23
BOA: front-end point of view
# When mounting an action, action will have reference to two urls: :confirm_path and :action_path.
routes.rb:
namespace: :developer ->
business_action Developer::Reject
# Renderers (`ConfirmButton` and `Modal`) can access action's :confirm_path and :action_path to render a button or a modal.
# As you see, renderers expect an action to have such methods.
# The main rule: I want to see a method call. Brackets are the most simple way to make it.
# if there is single argument and it is not a string, brackets required
fn()
fn(1)
fn(variable)
# if just single string, quotes are some kind of brackets here, and brackets can be omitted
fn 'string'
@s0ber
s0ber / menu.sass
Last active December 12, 2015 00:09
Menu states styles
// NOT recommended
.header
.menu
// styles for menu in header
.footer
.menu
// styles for menu in footer
// when we doing like this, blocks .menu, .header and .footer became dependent,
@s0ber
s0ber / menu.haml
Last active December 12, 2015 00:09
Menu states markup
.header
- # our header with lots content
.menu.for-header
- menu_items.each do |item|
.menu__item{class: "has-#{item.icon}_icon #{'is-active' if item.active?}"}
.content
- # ...
.footer
@s0ber
s0ber / posts_list.sass
Last active December 12, 2015 00:08
Posts list styles (SCSS)
.posts_list
// common styles for all blocks
// ...
// styles for modified blocks
&.for-most_popular
background-color: gray
.posts_list__title
color: green
@s0ber
s0ber / posts_list.haml
Last active December 12, 2015 00:08
Posts list markup (HAML)
- # in controller
- @posts_most_popular = Post.where('likes_count > ?', 100)
- @posts_most_commented = Post.where('comments_count > ?', 20)
- @posts_draft = Post.where(status: :draft)
- # in view
- if @posts_most_popular.any?
.posts_list.for-most_popular
.posts_list__title Most popular
- @posts_most_popular.each_with_index do |post, i|
@s0ber
s0ber / blog_post.sass
Last active December 12, 2015 00:08
Blog post styles (SCSS)
.blog_post
font-size: 12px
line-height: 18px
.blog_post__title
font-size: 20px
line-height: 24px
.blog_post__meta_data
text-align: right
@s0ber
s0ber / blog_post.haml
Last active December 12, 2015 00:08
Blog post markup (HAML)
- @posts # we are getting it from controlle
- @posts.each do |post|
.blog_post
.blog_post__title= post.title
.blog_post__meta_data
.blog_post__date= post.created_at
.blog_post__author= post.author.full_name
@s0ber
s0ber / ruby_chef
Last active December 10, 2015 15:08
Installing ruby from sources + chef
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline5-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p362.tar.gz
tar -xvzf ruby-1.9.3-p362.tar.gz
cd ruby-1.9.3-p362/
./configure --prefix=/usr/local
make
make install
@s0ber
s0ber / checkbox.js
Created June 6, 2012 11:35
Простановка чекбокса при отрисовке шаболона (для группы чекбоксов). data.weekItem - данные модели, data.weekDays - чекбоксы. Если элемент в модели true, то и чекбокс будет отмечен.
(function() {
for (var j = 0; j < weekDays; j++) {
if (data.weekItem[j].Day == data.weekDays[i].Id) {
return true;
}
};
return false;
})()