require 'fileutils'
pid_file = 'tmp/pids/server.pid'
if File.exist?(pid_file)
pid = File.read(pid_file).to_i
Process.kill 'TERM', pid
puts "SERVER STOPPED"
else
puts "SERVER NOT STARTED"
end
Process.exec( "/usr/bin/env rails s -p 8090" )
attr_accessor :cache_file
after_initialize :fetch_upload
def fetch_upload
options = { namespace: 'upload_cache', expire_in: 10.minutes }
file = attach.queued_for_write[:original]
if file.present?
self.cache_file = attach.original_filename
Rails.cache.write(cache_file, File.read(file.path), options)
elsif cache_file.present?
file = StringIO.new(Rails.cache.read(cache_file, options))
if file.present?
self.attach = file
self.attach.instance_write(:file_name, cache_file)
end
end
end
<%= f.text_field :cache_file %>
<%= f.file_field :attach %>
Rails.application.config.session_store :cache_store, key: '_super_app_session_key'
where("i18n_field @> hstore(:lang, :data)", lang: lang, data: data)
WHERE to_tsvector('russian', i18n_field->'lang') @@ to_tsquery('russain, 'Запрос')
ORDER BY i18n_field->'lang' ASC
gem 'thin', github: 'macournoyer/thin', branch: 'streaming'
def stream
response.headers['Content-Type'] = 'text/event-stream'
sse = SSE.new(response.stream, retry: 5000, event: 'notify')
3.times do |a|
sse.write({ class_id: __id__ })
sleep 3
end
rescue IOError
logger.info('Client alive channel')
ensure
response.stream.close
end
event = new EventSource('/stream')
event.addEventListener 'notify', (e)->
console.log(e.data)
def current_link_to label, path
from_path = controller._routes.recognize_path(path).values rescue nil
css = from_path & [controller_name, action_name] == from_path ? 'active' : nil
link_to label, path, class: css
end
get '/posts(/:locale)'
# или
scope "/:locale" do
...
<div class="msg"></div>
<div class="form-wrap" style="display:block">
<%= form_tag('/feedback', remote: true, format: :json, id: 'feedback') do %>
....
def send_email
....
respond_to do |format|
# if success
msg = success ? 'You request will be success processed'
: 'Ooops. Error occurred. Try later.'
format.json { render json: {msg: msg}.to_json }
end
end
$('#feedback')
.on 'ajax:before', ()->
$('.form-wrap').hide()
$('.msg').html('Sending...')
.on 'ajax:success', (e, data)->
$('.msg').html(data.msg)
memcahed -m 64M -I 10M
config.cache_store = :dalli_store, {:value_max_bytes => 10.megabytes}
Rails.cache.fetch('10mb'){ 'x' * 10.megabytes }.size
Cache read: 10mb
Cache generate: 10mb
Cache write: 10mb
Value for 10mb over max size: 10485760 <= 10485773
Rails.cache.fetch('9mb'){ 'x' * 9.megabytes }.size
Cache read: 9mb
Cache fetch_hit: 9mb
a = [{"yyyy-mm-dd" => 2}, {"yyyy-mm-dd" => 6}]
b = [{"2014-01-01" => 0} ... {"2014-12-31" => 0}]
ah = Hash[*a.map(&:to_a).flatten]
bh = Hash[*b.map(&:to_a).flatten]
result = bh.merge(ah).map{|k,v| {k => v}}
ah = {}.tap{ |out| a.each{ |h| h.each{ |k,v| (out[k]||=[]) << v } } }
bh = Hash[*b.map(&:to_a).flatten]
result = bh.merge(ah).map{|k,v| {k => v}}
params[:pages].each_with_index
def to_partial_path
priority? ? 'mini_post' : super
end
<%= render @posts %>
find("label[for^='cat-17']").click
expect(page).to have_selector("#task_subcategories_12")
expect(page).to have_selector("#task_subcategories_12", visible: false)