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
module Blah | |
include DataMapper::SphinxResource | |
property :id, Serial | |
property :name, String | |
# No dm-is-searchable, we need to order by :weight. | |
def self.my_search(search_options = {}, options = {}) | |
docs = repository(:search){self.all(search_options)} | |
ids = docs.map{|doc| doc[:id]} | |
results = self.all(options.merge(:id => ids)) |
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
DataMapper.setup(:default, options = {}) # Your :default repo. | |
DataMapper.setup(:search, :adapter => 'sphinx') | |
class Item | |
include DataMapper::Resource | |
# .. normal properties and such for :default | |
# This property is a computed field that only exists in :search aka your sphinx index{}. | |
# They do not have to exist in :default. | |
repository(:search) do |
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
module Blah | |
include DataMapper::SphinxResource | |
# repository(:default) properties | |
# repository(:search) sphinx properties | |
#-- | |
# Pagination provided by dm-is-paginated | |
# http://github.com/lholden/dm-is-paginated/tree | |
# You could just as easily brew the pagination yourself, it's very simple: | |
# http://github.com/lholden/dm-is-paginated/blob/670509c97d6fe298d2314dafbe1db91eff759ee5/lib/dm-is-paginated/is/paginated.rb |
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 | |
log = IO.popen("varnishlog -o") | |
loop do | |
Signal.trap('INT'){ exit 0} | |
while line = log.readline | |
next unless line =~ /^\s+\d+\s+([A-Z]\w+)\s+[-cb]\s(.*)$/ | |
head, line = $1, $2 | |
colour = case head |
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
diff --git a/lib/sinatra_warden/sinatra.rb b/lib/sinatra_warden/sinatra.rb | |
index a6bf5e3..652bdd6 100644 | |
--- a/lib/sinatra_warden/sinatra.rb | |
+++ b/lib/sinatra_warden/sinatra.rb | |
@@ -35,7 +35,10 @@ module Sinatra | |
def self.registered(app) | |
app.helpers Warden::Helpers | |
- | |
+ app.use Warden::Manager do |manager| |
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
<?php | |
# Mysql | |
# | |
# require_once('mysql.php'); | |
# $db = new Mysql(dbname, server, user, pass); | |
# $sth = $db->query('select * from blah where name = ? limit 1', 'fred') || die($db->error()); | |
# while ($row = mysql_fetch_assoc($sth)) | |
# ... | |
# |
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 'benchmark' | |
def each_acc list | |
foos = [] | |
list.each do |letter| | |
foos << letter.to_i | |
end | |
foos | |
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
#-- | |
# TODO: Ask about this monkey patch or alternatively I was thinking repository.create_query(*args) which would in turn | |
# call the same method on the adapter. The command stuff in data objects works the same way so I don't see a good | |
# argument against it other than the extra dispatch would be slightly slower. | |
module DataMapper | |
class Query | |
extend Chainable | |
chainable do | |
def self.new(*args, &block) |
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
# Write for and in Ruby 1.9 with 1.8 support in mind. | |
if RUBY_VERSION < '1.9' # or unless RUBY_VERSION >= '1.9' | |
# compatibility backports, monkey patches get required here. | |
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
# Used in 0.9.something but not in 0.10.something so far. | |
# Could probably replace the hook code with chainable save code these days? | |
require 'digest/md5' | |
require 'digest/sha1' | |
require 'dm-core' | |
require 'zlib' | |
module DataMapper | |
module Types | |
# Before saving/validating digest multiple properties. |
OlderNewer