Skip to content

Instantly share code, notes, and snippets.

View vlado's full-sized avatar

Vlado Cingel vlado

View GitHub Profile
.DS_Store
log/*.log
tmp/**/*
doc/api
doc/app
script/dev
@vlado
vlado / formtastic_mark_it_up_editor.rb
Last active September 5, 2015 09:04
FormtasticExtension for MarkItUpEditor
module FormtasticExtensions
module Formtastic
module MarkItUpEditor
def self.included(base)
base.class_eval do
@mark_it_up_dependencies_included = false
end
end
@vlado
vlado / gist:1877457
Last active April 3, 2018 08:36
Postgres on macos or OSX - Fix
# ** ERROR 1 **
# FATAL: lock file "postmaster.pid" already exists
# HINT: Is another postmaster (PID 4646) running in data directory "/usr/local/var/postgres"?
#
# ** ERROR 2 **
# Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
#
# To fix one of this errors:
cat /usr/local/var/postgres/postmaster.pid # pid is the number on first line
@vlado
vlado / gist:2028727
Created March 13, 2012 13:26
Placeholder text does not disappear in webkit (safari, chrome)
input:focus::-webkit-input-placeholder {
color: transparent;
}
@vlado
vlado / gist:3750538
Created September 19, 2012 16:13
Example js organization code
// ================================================
// We can put everything under "bd" namespace
// ================================================
window.bd = {};
// define some util functions and/or classes under util namespace
bd.util = {};
bd.util.toFloat = function(obj) {
return parseFloat(obj);
};
@vlado
vlado / you_tube_embed_example.html.erb
Last active May 8, 2017 17:37
How to embed youtube video in Rails view
<%
video_code, video_width, video_height = 'nkYA1xqrdGw', 938, 555
video_embed_params = { :fs => 1, :rel => 0, :hd => 1, :autoplay => 1, :modestbranding => 1, :version => 3, :enablejsapi => 1, :playerapiid => "ytplayer" }
player_wrapper_id, player_id = 'ytPlayerWrapper', 'ytPlayer'
%>
<% unless mobile_safari_request? %>
<% content_for :head do %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" %>
<% end %>
@vlado
vlado / soft_delete.rb
Last active December 21, 2015 17:28
Soft Delete for Rails (ActiveRecord)
module SoftDelete
def self.included(within)
within.class_eval do
scope :deleted, where("#{quoted_table_name}.deleted_at IS NOT NULL")
scope :not_deleted, where("#{quoted_table_name}.deleted_at IS NULL")
end
end
def not_deleted!
@vlado
vlado / gist:6592660
Created September 17, 2013 10:37
FATAL: remaining connection slots are reserved for non-replication superuser connections
# http://t5865.codeinpro.us/q/5150158be8432c042603131d
# http://stackoverflow.com/questions/2369744/rails-postgres-drop-error-database-is-being-accessed-by-other-users
@vlado
vlado / gem_config.rb
Last active December 23, 2015 12:19
How to write config block for gems. Inspired by http://rarlindseysmash.com/posts/config-and-generators-in-gems
module Jem
class << self
attr_accessor :configuration
end
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
@vlado
vlado / ar_enhanced_query_objects.rb
Created September 20, 2013 08:45
ActiveRecord: Enhanced Query Objects
# Hamed Asghari post: http://hasghari.github.io/2013/09/15/active-record-enhanced-query-objects.html
class PopularProductQuery
def initialize(relation = Product.scoped)
@relation = relation.extending(Scopes)
end
def popular(time)
@relation.with_recent_activity(time).with_available_reviews
end