This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RssSqliteModel | |
def initialize(path) | |
# logs display | |
DataMapper::Logger.new($stdout, :debug) | |
DataMapper.setup(:default, "sqlite://#{path}") | |
DataMapper.finalize | |
DataMapper.auto_migrate! | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
require 'rubygems' | |
require 'data_mapper' | |
class Feed | |
include DataMapper::Resource | |
property :id, Serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bcrypt' | |
class User | |
include DataMapper::Resource | |
attr_accessor :password, :password_confirmation | |
timestamps :at | |
property :id, Serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"posts" : { | |
"post" : { | |
"properties" : { | |
"converted_text" : { | |
"type" : "string" | |
}, | |
"converted_text_size" : { | |
"type" : "long" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'json' | |
require 'json-schema' | |
schema = '{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"title": "demo", | |
"type": "object", | |
"properties": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'json' | |
require 'json-schema' | |
schema = '{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"title": "demo", | |
"type": "object", | |
"properties": { |
OlderNewer