Skip to content

Instantly share code, notes, and snippets.

View pacifists's full-sized avatar

Rytis Lukosevicius pacifists

View GitHub Profile
@pacifists
pacifists / CustomField.php
Created February 27, 2013 10:08
This shows how to use CakePHP Expandable behavior with single table and make kind of polymorphic association. This uses a little bit modified version of expandable behavior so that it automatically adds model name to correct field for the associations.
<?php
class CustomField extends AppModel {
var $name = 'CustomField';
var $actsAs = array('Search.Searchable');
public $filterArgs = array();
}
@pacifists
pacifists / duk_data.rb
Created June 21, 2012 13:59
How to use selenium web driver few example files of my own
# encoding: utf-8
require "selenium-webdriver"
require "net/http"
require 'pathname'
require 'json'
driver = Selenium::WebDriver.for :chrome, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate]
driver.navigate.to "http://localhost:3000/admin"
login_email = driver.find_element(:id, 'admin_email')
@pacifists
pacifists / ability.rb
Created November 13, 2011 10:01
How to extend locomotive cms permissions onto custom models and controllers
# app/models/ability.rb
class Ability
def setup_author_permissions_with_myliufoto!
self.setup_author_permissions_without_myliufoto!
can :manage, [Album, Photo]
end
alias_method_chain :setup_author_permissions!, :myliufoto
@pacifists
pacifists / application.rb
Created November 6, 2011 12:29
Files needed to render locomotive pages from your own controllers
# config/application.rb
...
module Myliufoto
class Application < Rails::Application
def self.activate
if Rails.env.development?
load File.join(config.root, 'lib', 'locomotive', 'rails', 'render.rb')
else
require File.join(config.root, 'lib', 'locomotive', 'rails', 'render.rb')
module Liquid::Tags
class PageBanners < ::Liquid::Tag
Syntax = /(#{::Liquid::Expression}+)\s+max\s+([0-9]+)/
def initialize(tag_name, markup, tokens, context)
if markup =~ Syntax
@collection_name = $1
@max_number = $2
@pacifists
pacifists / loco_tip_1.html
Created October 7, 2011 06:27 — forked from did/loco_tip_1.html
How to post a comment related to an artist
<h2>{{ artist.name }}</h2>
<div>{{ artist.bio }}</div>
{% with_scope artist: artist._id %}
{% assign comments = contents.comments %}
{% if comments == empty %}
require 'active_support/dependencies'
module ActiveSupport::Dependencies
alias_method :require_or_load_without_multiple, :require_or_load
def require_or_load(file_name, const_path = nil)
if file_name.starts_with?(Rails.root.to_s + '/app')
relative_name = file_name.gsub(/^#{Rails.root.to_s}/, '')
@engine_paths ||= Rails::Application.railties.engines.collect{|engine| engine.config.root.to_s }
@engine_paths.each do |path|
engine_file = File.join(path, relative_name)
module MyApp
class IncViewsCounterFor < ::Liquid::Tag
Syntax = /(#{::Liquid::Expression}+)?/
def initialize(tag_name, markup, tokens, context)
if markup =~ Syntax
@name = $1
else
raise ::Liquid::SyntaxError.new("Syntax Error in 'inc_views_counter_for' - Valid syntax: inc_views_counter_for <content>")
@pacifists
pacifists / gist:1151212
Created August 17, 2011 09:46
ca-certificate-java install errors
error adding brasil.gov.br/brasil.gov.br.crt
error adding cacert.org/cacert.org.crt
error adding debconf.org/ca.crt
error adding gouv.fr/cert_igca_dsa.crt
error adding gouv.fr/cert_igca_rsa.crt
@pacifists
pacifists / gist:1151211
Created August 17, 2011 09:45
java memory error
java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.