Skip to content

Instantly share code, notes, and snippets.

@Kolenov
Kolenov / application_helper.rb
Created December 28, 2017 22:22 — forked from attilagyorffy/application_helper.rb
Responsive Images in Rails applications
module ApplicationHelper
def responsive_image_tag(image, options = {})
content_tag(:picture) do
concat content_tag(:source, nil, media: '(max-width: 768px)', srcset: image.url(:thumbnail_mobile))
concat content_tag(:source, nil, media: '(max-width: 960px)', srcset: image.url(:thumbnail_tablet))
concat image_tag(image.url(:thumbnail_desktop), options)
end
end
end
$ psql -d postgres
postgres=# create role "app_name" login createdb;
postgres=# \q
The first line is in your terminal, the next two are inside psql. Then do your rake db:create.

The User user is possibly a default but user is already taken for other purposes in PostgreSQL so 
you'd have to quote it to preserve the case if you wanted to use User as a username:

postgres=# create role "User" login createdb;
@Kolenov
Kolenov / images_helper.rb
Last active May 7, 2018 11:05 — forked from youngbrioche/images_helper.rb
Responsive images helper using srcset in Rails
# frozen_string_literal: true
module ImagesHelper
# Acts as a thin wrapper for image_tag and generates an srcset attribute for regular image tags
# for usage with responsive images polyfills like picturefill.js, supports asset pipeline path helpers.
#
# image_set_tag 'pic_1980.jpg', { 'pic_640.jpg' => '640w', 'pic_1024.jpg' => '1024w', 'pic_1980.jpg' => '1980w' }, sizes: '100vw', class: 'my-image'
# => <img src="/assets/ants_1980.jpg" srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw" class="my-image">
#
# image_set_tag 'logo-amzlenders.png', {'[email protected]' => '2x'}
# => <img srcset="/assets/[email protected] 2x" src="/assets/logo-amzlenders.png" alt="Logo amzlenders">
@Kolenov
Kolenov / svg_helper.rb
Last active November 1, 2017 10:45 — forked from josepmartins/inline_svg_helpers.rb
SVG inline helpers for Rails
# Inline svg from @tomeara https://gist.github.com/tomeara/6515860
def inline_svg(source)
file = File.open("app/assets/images/#{source}", "rb")
raw file.read
end
# SVG internal link
#= svg_tag 'sprite/icons.svg', 'icon-facebook-invers'
module SvgHelper
:root {
font-size: calc(0.6em + 1vw)
}
@mixin for-size($range) {
$phone-upper-boundary: 600px;
$tablet-portrait-upper-boundary: 900px;
$tablet-landscape-upper-boundary: 1200px;
$desktop-upper-boundary: 1800px;
erb
<% unless current_page?('/') || current_page?('/projects') %>
# '/' the same as root_path
show some stuff
<% end %>
slim, haml
- unless current_page?('/') || current_page?('/projects')
| \# '/' the same as root_path
| show some stuff
@Kolenov
Kolenov / gist:d791329d161666bdc7777a9c4049d932
Created October 10, 2017 21:27
анимация для max-height
.slider ul {
max-height: 0;
overflow: hidden;
}
.slider:hover ul {
max-height: 1000px;
transition: .3s ease; /* анимация для max-height */
}
var pageFacade = {
updateMenu: function() {
loadData();
resizeColumn();
updateCounter();
setLog();
},
doSmthElse: function() {
// a lot of methods
}
@Kolenov
Kolenov / mediator.js
Created September 5, 2017 16:55
Mediator
//part 1
function Player(name) {
this.points = 0;
this.name = name;
}
Player.prototype.play = function () {
this.points += 1;
mediator.played();
};
var scoreboard = {