Skip to content

Instantly share code, notes, and snippets.

class Page
include MongoMapper::Document
end
class ContentPage < Page
many :content_blocks #tried :as => :page as well
end
class ContentBlock
include MongoMapper::EmbeddedDocument
$ gem install plist4r --verbose --backtrace --debug
Exception `NameError' at /home/bogn/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/command_manager.rb:177 - uninitialized constant Gem::Commands::InstallCommand
Exception `Gem::LoadError' at /home/bogn/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247 - Could not find psych (>= 1.2.1, ~> 1.2) amongst [RedCloth-4.2.7, aaronh-chronic-0.3.9, abstract-1.0.0, actionmailer-3.0.9, actionmailer-3.0.7, actionmailer-3.0.5, actionmailer-3.0.4, actionmailer-3.0.3, actionmailer-2.3.2, actionmailer-2.1.0, actionmailer-1.3.3, actionpack-3.0.9, actionpack-3.0.7, actionpack-3.0.5, actionpack-3.0.4, actionpack-3.0.3, actionpack-3.0.0.beta3, actionpack-2.3.2, actionpack-2.1.0, actionpack-1.13.3, actionwebservice-1.2.3, activemodel-3.0.10, activemodel-3.0.9, activemodel-3.0.7, activemodel-3.0.6, activemodel-3.0.5, activemodel-3.0.4, activemodel-3.0.3, activemodel-3.0.0.beta3, activerecord-3.0.9, activerecord-3.0.7, activerecord-3.0.5
@bogn
bogn / gist:2769213
Created May 22, 2012 13:51
Ruby 1.9.3p0 hex bug
1.9.3p0 :001 > "​10FFFF".to_i 16
=> 0
1.9.3p0 :002 > exit
bogn@Mojito:~$ irb
1.9.3p0 :001 > "10FFFF".to_i(16)
=> 1114111
1.9.3p0 :002 > "10FFFF".to_i 16
=> 1114111
und noch mal mit p194
1.9.3p194 :001 > "10FFFF".to_i 16
@bogn
bogn / Tire-_type-field-corruption.rb
Created October 11, 2012 14:19
Tire: STI field _type get's corrupted by update_index callback on second call to save
require 'mongo_mapper'
MongoMapper.database = 'testing'
require 'tire'
class Thing
include MongoMapper::Document
include Tire::Model::Search
include Tire::Model::Callbacks
end
@bogn
bogn / example.xml
Last active December 11, 2015 13:38
example.xml is the desired output, but the schema has to repeat the locales for the anyURI variant. Is there any alternative to repeating them?
<?xml version="1.0" encoding="UTF-8"?>
<application>
<title>
<text xml:lang="de"><![CDATA[]]></text>
<text xml:lang="en"><![CDATA[]]></text>
<text xml:lang="fr"><![CDATA[]]></text>
</title>
<picture>
<uri xml:lang="de">file://example1.jpg</uri>
<uri xml:lang="en">file://example2.jpg</uri>
@bogn
bogn / approval_workflow.rb
Last active December 15, 2015 20:19
Approval Workflow on instance level
def approval_by(role)
singleton_class_with_workflow = class << self
approval = self.class.approval_transitions_for[role]
workflow do
(approval || []).each do |state_name, events|
state state_name do
events.each do |event_name|
event event_name, transitions_to: EVENT_RESULTS[event_name]
end
end
@bogn
bogn / ngram-wrong-highlight.sh
Last active December 16, 2015 09:09
A combo analyzer using the sub analyzers German2 snowball and ngram is yielding strange results for me (see comments). elasticsearch 0.20.2. elasticsearch-analysis-combo 1.1.0. Same goes for elasticsearch 0.90.RC2 and elasticsearch-analysis-combo 1.3.0.
curl -XDELETE 'localhost:9200/test'
echo
curl -XPUT 'localhost:9200/test?pretty' -d '{
"mappings" : {
"test" : {
"properties" : {
"text_de" : {
"type" : "string"
}
# multilingual analysis for title search taken from :
# http://jprante.github.com/lessons/2012/05/16/multilingual-analysis-for-title-search.html
# or alternatively here (where the used plugin comes from, is less descriptive but has more technical details)
# https://github.com/yakaz/elasticsearch-analysis-combo
analysis:
filter:
germansnow:
type: snowball
language: German2
ngram_filter:
@bogn
bogn / move_embedded_to_toplevel.rb
Last active December 19, 2015 08:49
Mongoid: Moving embedded records (recursively_embeds_many) to top-level. Not actually happy about it, as I don't have the experience with Mongoid to decide whether setting the state like this is risky. But it seems Mongoid 3.1.4 doesn't offer a more elegant way to do this. Feedback very welcome.
class Group
include Mongoid::Document
recursively_embeds_many
end
# remove from old parent
@group.parent_group.child_groups.delete @group
# set new state
@bogn
bogn / gist:6291691
Last active December 21, 2015 10:28 — forked from powmedia/gist:5161061
Select2
/**
* Select2
*
* Renders Select2 - jQuery based replacement for select boxes
*
* Simply pass a 'config' object on your schema, with any options to pass into Select2.
* See http://ivaynberg.github.com/select2/#documentation
*/
Backbone.Form.editors.Select2 = Backbone.Form.editors.Base.extend({