Skip to content

Instantly share code, notes, and snippets.

View ricardokrieg's full-sized avatar

Ricardo Andrade ricardokrieg

View GitHub Profile
@ricardokrieg
ricardokrieg / migration.rb
Created October 17, 2013 00:13
Dont allow more than one promotional item in a Spree Order
add_column :spree_products, :promotional, :boolean
@ricardokrieg
ricardokrieg / packer_decorator.rb
Created October 4, 2013 17:42
Monkey Patch to make Spree skips inventory check for only a kind of products
Spree::Stock::Packer.class_eval do
def default_package
package = Spree::Stock::Package.new(stock_location, order)
order.line_items.each do |line_item|
# on_demand? will say if this kind of product has inventory
if Spree::Config.track_inventory_levels and not line_item.variant.product.on_demand?
next unless stock_location.stock_item(line_item.variant)
on_hand, backordered = stock_location.fill_status(line_item.variant, line_item.quantity)
package.add line_item.variant, on_hand, :on_hand if on_hand > 0
# Model Record (Protuário)
class Record < ActiveRecord::Base
belongs_to :patient
has_many :appointments
attr_accessible :data, :patient_id
end
@ricardokrieg
ricardokrieg / capistrano task
Last active December 19, 2015 09:59
Nginx Maintenance Page
cp #{latest_release}/system/maintenance.html #{shared_path}/system/maintenance.html.not_active
# Swap in the maintenance page
namespace :web do
task :disable, roles: :web do
on_rollback {run "rm #{shared_path}/system/maintenance.html"}
run "if [[ !(-f #{shared_path}/system/maintenance.html) ]] ; then ln -s #{shared_path}/system/maintenance.html.not_active #{shared_path}/system/maintenance.html ; else echo 'maintenance page already up'; fi"
end
@ricardokrieg
ricardokrieg / haproxy.init
Created August 17, 2012 01:56
HAProxy daemon script
#!/bin/sh
#
# processname: haproxy
# config: /opt/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid
[ -f /opt/haproxy/haproxy.cfg ] || exit 1
RETVAL=0
@ricardokrieg
ricardokrieg / jail.conf
Created August 15, 2012 20:26
Fail2Ban config
# Fail2Ban configuration file.
#
# This file was composed for Debian systems from the original one
# provided now under /usr/share/doc/fail2ban/examples/jail.conf
# for additional examples.
#
# To avoid merges during upgrades DO NOT MODIFY THIS FILE
# and rather provide your changes in /etc/fail2ban/jail.local
#
# Author: Yaroslav O. Halchenko <debian@onerussian.com>
@ricardokrieg
ricardokrieg / logcheck.conf
Created August 15, 2012 20:21
Config for logcheck
# The following variable settings are the initial default values,
# which can be uncommented and modified to alter logcheck's behaviour
# Controls the format of date-/time-stamps in subject lines:
# Alternatively, set the format to suit your locale
DATE="$(date +'%d/%m/%Y %H:%M')"
# Controls the presence of boilerplate at the top of each message:
# Alternatively, set to "0" to disable the introduction.
@ricardokrieg
ricardokrieg / app.com.br
Created January 24, 2012 17:51
Nginx example site
upstream unicorn_app {
server unix:/home/ubuntu/www/app.com.br/current/tmp/.sock
fail_timeout=0;
}
server {
listen 81;
server_name .app.com.br;
root /home/ubuntu/www/app.com.br/current/public;
@ricardokrieg
ricardokrieg / nginx.conf
Created January 24, 2012 17:49
Nginx configuration file
user www-data;
worker_processes 4;
worker_rlimit_nofile 2048;
worker_priority 0;
worker_cpu_affinity 0001 0010 0100 1000;
error_log /var/log/nginx/error.log;
events {
@ricardokrieg
ricardokrieg / haproxy.cfg
Created January 24, 2012 17:46
HAProxy configuration file
frontend all 0.0.0.0:80
mode tcp
maxconn 200000
timeout client 86400000
default_backend www_backend
acl is_socket_staging hdr_beg(host) socket.teste
acl is_socket hdr(Upgrade) -i WebSocket