Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
require 'rubygems'
require 'redis'
r = Redis.new
r.config("SET","maxmemory","2000000")
r.config("SET","maxmemory-policy","allkeys-lru")
r.config("SET","maxmemory-samples",1000)
r.config("RESETSTAT")
r.flushall
# register services
Application.register :session do
SessionStore.new(store: Application.lookup(:database_store))
end
Application.register :database_store do
# code to initialize database storage for session
end
# inject session service into every action
@runlevel5
runlevel5 / gist:76a0535c88c06f753d9a
Last active August 29, 2015 14:02
Generate sdoc of lotus
git clone git@github.com:lotus/lotus.git
git clone git@github.com:lotus/model.git
git clone git@github.com:lotus/controller.git
git clone git@github.com:lotus/view.git
git clone git@github.com:lotus/router.git
git clone git@github.com:lotus/helpers.git
git clone git@github.com:lotus/utils.git
sdoc -o doc/lotus -T direct --exclude="CHANGELOG.md" --exclude="LICENSE.txt" --exclude="LICENSE.md" --exclude="CONTRIBUTING.md" --exclude="test" --exclude="Gemfile*" --exclude=".*gemspec" --exclude="Rakefile" --no-dry-run -t lotus -a lotus
sdoc -o doc/model -T direct --exclude="CHANGELOG.md" --exclude="LICENSE.txt" --exclude="LICENSE.md" --exclude="CONTRIBUTING.md" --exclude="test" --exclude="Gemfile*" --exclude=".*gemspec" --exclude="Rakefile" model
@arthurgeek
arthurgeek / lotus.patch
Created August 19, 2014 20:14
Lotus Patch 2
diff --git a/lib/lotus/loader.rb b/lib/lotus/loader.rb
index e038d7f..9221840 100644
--- a/lib/lotus/loader.rb
+++ b/lib/lotus/loader.rb
@@ -23,7 +23,6 @@ module Lotus
load_configuration!
load_frameworks!
load_application!
- finalize!
end
@anthonyjsmith
anthonyjsmith / gist:53fccd30ee0873b06c8b
Created November 25, 2014 16:39
Non-expiring flash
# Visit:
# /main/set_flash
# /main/show_no_flash (as many times as you like)
# /main/show_flash ... and it shows the flash message
# (Rails 4.1.8, Ruby 2.1.1)
# app/controllers/main_controller.rb
class MainController < ApplicationController
def show_flash
render inline: flash[:notice] || "Flash is blank!"
@angeloashmore
angeloashmore / repository_timestamps.rb
Created February 20, 2015 20:38
Lotus::Model timestamps handling using an entity's @created_at and @updated_at via its Repository.
module Lotus
module Repository
# Timestamps handling using an entity's @created_at and @updated_at.
#
# @since 0.2.4
module Timestamps
# Override existing public API into hosting class to support @created_at
# and @updated_at using Ruby implementations (database agnostic).
#
# @since 0.2.4
@fidothe
fidothe / gist:39d4ef9b8d84f8ddde77
Created March 18, 2015 09:14
Use PG JSON datatype with Lotus::Model (hacky hacky)
require 'lotus/model'
require 'json'
module Lotus::Model::Mapping::Coercions
def self.JSON(arg)
return nil if arg.nil?
case arg
when String
JSON.parse(arg)
else
class AgencyVisitPolicy
def initialize(user)
@user = user
end
def to_proc
Proc.new { |visit| visit.agency_id.in?([@user.agency_id, nil]) }
end
end
# Basic text search with relevancy for MongoDB.
# See http://blog.tty.nl/2010/02/08/simple-ranked-text-search-for-mongodb/
# Copythingie 2010 - Ward Bekker - ward@tty.nl
#create (or empty) a docs collection
doc_col = MongoMapper.connection.db('example_db').collection('docs')
doc_col.remove({})
#add some sample data
doc_col.insert({ "txt" => "it is what it is"})
# make an alternative for send_later that accepts a run_at time
#
module Delayed
module MessageSending
def send_later_at(at, method, *args)
Delayed::Job.enqueue(
Delayed::PerformableMethod.new(self, method.to_sym, args),
0, #priority
at #run_at
)