Skip to content

Instantly share code, notes, and snippets.

View lumpidu's full-sized avatar

Daniel lumpidu

View GitHub Profile
@lumpidu
lumpidu / gist:943360
Created April 26, 2011 22:48
datamapper prob1
class Feed
include DataMapper::Resource
property :id, Serial
property :title, String, :key => true
property :url, Text
has n, :feed_posts
has n, :posts, :through => feed_posts
@lumpidu
lumpidu / gist:943399
Created April 26, 2011 23:22
Initialize DataMapper connections in different classes
class RssSqliteModel
def initialize(path)
# logs display
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, "sqlite://#{path}")
DataMapper.finalize
DataMapper.auto_migrate!
end
end
@lumpidu
lumpidu / gist:975349
Created May 16, 2011 20:51
DataMapper multiple Contexts: Error Case
#!/usr/bin/env ruby
#
require 'rubygems'
require 'data_mapper'
class Feed
include DataMapper::Resource
property :id, Serial
@lumpidu
lumpidu / user.rb
Created January 6, 2012 21:44 — forked from namelessjon/user.rb
Example user with a BCrypt password
require 'bcrypt'
class User
include DataMapper::Resource
attr_accessor :password, :password_confirmation
timestamps :at
property :id, Serial
@lumpidu
lumpidu / valid_utf8.rb
Created April 3, 2012 21:12
Test valid UTF-8
# Tests str for valid UTF-8 as described here:
# https://secure.wikimedia.org/wikipedia/en/wiki/Utf8
#
# The following options are supported:
#
# :bmp_only Basic Multilingual Plane: only 1,2 byte characters are valid
# :debug prints debug info to stdout in case of an error
#
def valid_utf8?(str, options={})
debug = options[:debug] || false
@lumpidu
lumpidu / gist:2710254
Created May 16, 2012 13:12
Search ES
# Searches ElasticSearch fulltext engine via Tire
#
# @param term Search term to be used
# It has to start with a prefix specifying the field(s) to be searched:
# e.g.
# _all:Apple
# converted_text:Apple
# field_summary:Apple, etc.
#
# Each Lucene search term can be used
@lumpidu
lumpidu / Model.rb
Created May 22, 2012 08:08
Post Model
class Post < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :id, :index => :not_analyzed
indexes :title, :analyzer => 'snowball', :boost => 3
indexes :url, :analyzer => 'url'
indexes :created_at, :type => 'date', :include_in_all => false
@lumpidu
lumpidu / gist:2768030
Created May 22, 2012 10:00
Post Mapping to ES
{
"posts" : {
"post" : {
"properties" : {
"converted_text" : {
"type" : "string"
},
"converted_text_size" : {
"type" : "long"
},
#!/usr/bin/ruby
require 'json'
require 'json-schema'
schema = '{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "demo",
"type": "object",
"properties": {
#!/usr/bin/ruby
require 'json'
require 'json-schema'
schema = '{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "demo",
"type": "object",
"properties": {