Skip to content

Instantly share code, notes, and snippets.

View lappi-lynx's full-sized avatar
🚴
Cycling from home

Stanislav Kniazev 🇺🇦 lappi-lynx

🚴
Cycling from home
View GitHub Profile
@lappi-lynx
lappi-lynx / bootstrap_breadcrumbs_builder.rb
Last active August 29, 2015 13:56
bootstrap builder for breadcrumbs_on_rails gem
# bootstrap builder for breadcrumbs_on_rails gem
class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder
def render
@context.content_tag(:ul, class: 'breadcrumb') do
@elements.collect do |element|
render_element(element)
end.join.html_safe
end
end
@lappi-lynx
lappi-lynx / popup
Created November 30, 2012 06:57
create popup
def create_popup(discipline)
if discipline.short_description.present?
options = {:content => discipline.short_description, "original-title" => t("discipline.short_description_title"),
:trigger => "hover" }
end
content_tag(:div, :data => options ) do
discipline.name
end
end
@lappi-lynx
lappi-lynx / gist:4222728
Created December 6, 2012 08:25
Pagination align
$(".pagination").each ->
parent_width = $(this).parent().width()
pwidth = $(this).width()
align = (parent_width - pwidth) / 2
$(this).css "margin-left", align
@lappi-lynx
lappi-lynx / gist:5758489
Created June 11, 2013 16:43
Rails group_by_day method
# Method for grouping users by the day (for postgresql):
User.order("DATE(created_at)").group("DATE(created_at)").count
head
title = content_for?(:title) ? yield(:title) : 'Nathaniel Paul'
meta charset="utf-8"
meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"
meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0"
meta name="description" content="#{content_for?(:description) ? yield(:description) : 'Nathaniel Paul description text'}"
meta name="keywords" content="#{content_for?(:keywords) ? yield(:keywords) : 'Nathaniel Paul, designer, emerged'}"
@lappi-lynx
lappi-lynx / prawn_multi_column.rb
Last active January 29, 2016 12:15
Multi-column PDF generating with Prawn in ruby
# Not breaking the page but continue on the next column
# Example of 2 columns table with some styling
def render_left_products_list
column_box([-5, cursor], columns: 2, height: cursor, position: :left, width: bounds.width, spacer: 40) do
@categories.each do |category|
move_down 6
table line_item_rows(category), position: :left, cell_style: { size: 7, text_color: "000000", borders: [:bottom], border_lines: [:dotted], padding: [2, 0, 4, 0] } do
column(1).style align: :right
style(row(0), text_color: 'FF0000')
@lappi-lynx
lappi-lynx / sql_to_csv.rb
Last active January 29, 2016 12:16
Allows you to convert data from SQL into CSV format
# First connect to DB with needed sql data
class T < ActiveRecord::Base
establish_connection({adapter:'mysql2', database:'db_for_test', encoding:'utf8',user:'', password: ''})
set_table_name 'utility_company'
end
CSV.open("data.csv", "wb") do |csv|
csv << T.first.attribute_names # adds the attributes name on the first line
T.all.each do |hash|
@lappi-lynx
lappi-lynx / es.sh
Last active January 29, 2016 12:17
Elastic search install
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
# NEW WAY / EASY WAY
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.0.deb
sudo dpkg -i elasticsearch-1.1.0.deb
@lappi-lynx
lappi-lynx / ckeditor_toolbar_config.js
Last active January 29, 2016 12:18
CKeditor custom tollbar in rails 4
// Create /app/assets/javascripts/ckeditor/config.js file:
CKEDITOR.editorConfig = function( config )
{
config.toolbar = 'MyToolbar';
config.toolbar_MyToolbar =
[
{ name: 'document', items : [ 'NewPage','Preview' ] },
{ name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
@lappi-lynx
lappi-lynx / slickgrid_autocomplete_editor.js
Last active May 17, 2017 07:30
jQuery Autocomplete editor for SlickGrid js table
function AutoCompleteEditor(args) {
var $input;
var defaultValue;
var scope = this;
var calendarOpen = false;
this.init = function () {
$input = $("<INPUT type=text class='editor-text' />");
$input.appendTo(args.container);