Skip to content

Instantly share code, notes, and snippets.

@mediasota
mediasota / simple_form.rb
Created November 8, 2016 05:46 — forked from gudata/simple_form.rb
simple form initialization for http://materializecss.com/
# Use this setup block to configure all options available in SimpleForm.
# https://github.com/patricklindsay/simple_form-materialize/blob/master/lib/generators/simple_form/materialize/templates/config/initializers/simple_form_materialize.rb
# contribute here: https://github.com/mkhairi/materialize-sass/issues/16
SimpleForm.setup do |config|
config.wrappers :default, class: :input,
hint_class: :field_with_hint, error_class: :field_with_errors do |b|
## Extensions enabled by default
# Any of these extensions can be disabled for a
# given input by passing: `f.input EXTENSION_NAME => false`.
@mediasota
mediasota / rails.history.js
Created February 29, 2016 06:28 — forked from debprado/rails.history.js
Add callbacks to remote links in Rails to manage browser history using pageState and replaceState
function historySupport() {
return !!(window.history && window.history.pushState !== undefined);
}
function pushPageState(state, title, href) {
if (historySupport()) {
history.pushState(state, title, href);
}
}
@mediasota
mediasota / sitemap.xml
Created November 10, 2015 09:48 — forked from maxivak/readme.md
sitemap.xml for Rails 4 application
# Generate sitemap.xml in Rails app
This post shows how to make sitemap.xml for your web site.
The sitemap will be accessible by URL http://mysite.com/sitemap.xml
# Routes
```ruby
Myrails::Application.routes.draw do
@mediasota
mediasota / encode_error_ubuntu_xc3.md
Last active September 15, 2015 06:46
Fix 'encode': "\xC3" on US-ASCII (Encoding::InvalidByteSequenceError) on ubuntu

Sometimes in a newly created server you can get this error when starting a ruby app:

 `encode': "\xC3" on US-ASCII (Encoding::InvalidByteSequenceError)

To fix simple export this variables or add to your ~/.bash_profile

export LANG=en_US.UTF-8
@mediasota
mediasota / gist:737db30234daa31432bc
Created September 8, 2015 04:28
rails-passenger-postgres-ubuntu
# Rails, PostgreSQL with Passenger + Nginx on Ubuntu 14.04 without RVM or rbenv
# https://www.brightbox.com/docs/ruby/ubuntu/
# https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/
# http://www.postgresql.org/download/linux/ubuntu/
# https://github.com/rvm/rvm/blob/493b5bdcec50a2b521a6cad307334a3a4425099f/scripts/functions/requirements/ubuntu#L124
$ ssh-copy-id root@SERVER -i ~/.ssh/id_rsa.pub
$ ssh root@SERVER
# apt-get update && apt-get upgrade
lastActionTime = new Date()
syncInterval = 30000
$('*').on 'blur change click dblclick error focus focusin focusout hover keydown keypress keyup load mousedown mouseenter mouseleave mousemove mouseout mouseover mouseup resize scroll select submit', ->
lastActionTime = new Date()
setInterval (->
currentTime = new Date()
timeLimit = currentTime - lastActionTime
convertPostGisToYandex = (point) ->
coords = /POINT\s*\(\s*([0-9\.]+)\s*([0-9.]+)\s*\)/.exec point
if coords.length != 2
console.error 'Bad parse PostGIS point data', point
return []
return [parseFloat(coords[1]), parseFloat(coords[2])]
@mediasota
mediasota / gist:7c46c8e105acc386d62f
Created March 6, 2015 12:04
config/initializers/simple_form_materialize-sass.rb
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.error_notification_class = 'alert alert-danger'
config.button_class = 'waves-effect waves-light btn'
config.boolean_label_class = nil
config.wrappers :vertical_form, tag: 'div', class: 'input-field', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.optional :maxlength
@mediasota
mediasota / Gemfile
Last active August 29, 2015 14:12 — forked from maxlapshin/Gemfile
source 'https://rubygems.org'
gem 'rails', '~>4.0.2'
gem 'activerecord-session_store'
gem 'pg'
gem 'foreigner'
gem 'airbrake'
gem 'redcarpet'
#app/inputs/collection_check_boxes_input.rb
class CollectionCheckBoxesInput < SimpleForm::Inputs::CollectionCheckBoxesInput
def item_wrapper_class
"checkbox-inline"
end
end