Skip to content

Instantly share code, notes, and snippets.

View we4tech's full-sized avatar

Hossain Khan we4tech

View GitHub Profile
@we4tech
we4tech / nginx_tomcat
Last active August 29, 2015 13:58
nginx-tomcat
server {
listen 80 default;
server_name _;
root /opt/apache-tomcat-7.0.53/webapps/ROOT;
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_max_temp_file_size 0;
@we4tech
we4tech / tomcat.conf
Last active August 29, 2015 13:58 — forked from witscher/tomcat.conf
Tomcat 7 configuration
description "Tomcat Server"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
limit nofile 32000 32000
console output
@we4tech
we4tech / elasticsearch.conf
Last active August 29, 2015 13:58 — forked from rbscott/elasticsearch.conf
ElasticSearch upstart script
# ElasticSearch Service
description "ElasticSearch"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@we4tech
we4tech / Gemfile
Last active August 29, 2015 13:57
Basic standalone rake/thor based project bootstrap
source 'https://rubygems.org'
# Core libraries
gem 'rake'
gem 'activesupport'
gem 'bson_ext'
# Add gems related with content parsing
gem 'nokogiri'
@we4tech
we4tech / before_all_tip.rb
Last active August 29, 2015 13:56
How to speed up your rspec execution
before(:all) { @stuff = create :stuff }
let!(:stuff) { @stuff }
before { Stuff.stub(:find).with(stuff.id.to_s).and_return(stuff) }
@we4tech
we4tech / lazy_attribute.rb
Created December 30, 2013 08:39
Define attribute which value is loaded and stored lazily. Ie. You want to get some data from a 3rd party API call but instead of setting them explicitly you want to get those on demand. Here are few lines of code to get it workable.
module Concerns
module LazyAttribute
extend ActiveSupport::Concern
included do
class_attribute :lazy_attributes
end
module ClassMethods
def attr_lazy(name, &logic_impl)
@we4tech
we4tech / rthread_importer.rb
Last active December 31, 2015 11:59
An illustration how we can use ruby thread for accelerating our normal RAKE tasks. (intended for posting in a local Ruby developers group https://www.facebook.com/groups/rubydevs/)
namespace :somestuffs do
desc 'Importing some big stuff that requies lotta network stuff'
task :import
file, tasks = ENV['FILE'], Queue.new
# Parse out CSV file and retrieve each row and queue them up
# for further processing.
#
# Keeping it a thread allows us to let this process continue while other
# threads are not in RUNNING state.
@we4tech
we4tech / as_active_merchant.rb
Created October 9, 2013 07:15
Simple written "Model Concern" for adding active merchant
# Integrate with ActiveMerchant and Expose active merchant related methods.
#
# This module also includes Validator for ActiveMerchant.
module Concerns::AsActiveMerchant
extend ActiveSupport::Concern
included do
validates_with Validators::ActiveMerchant, if: :cc_number_is_changed?
end
@we4tech
we4tech / with_default_mongoid_methods.rb
Last active December 24, 2015 06:59
What if, we've more pictorial relationship syntax than syntactical sugar ?
class Message
include Mongoid::Document
include Mongoid::Timestamps
field :subject, type: String
field :content, type: String
belongs_to :replied_to, class_name: 'Message', inverse_of: :replies, touch: true
belongs_to :sender, class_name: 'User', inverse_of: :sent_messages
has_many :replies, class_name: 'Message', inverse_of: :replied_to
@we4tech
we4tech / exp_factory_method.rb
Created September 21, 2013 05:48
Instead of relying on 3rd party service, we could wrap them in bridge or expose through factory or facade
def handle_action_created(action)
if action.from.kind_of?(Source)
$redis.lpush(
"#{self.class.name}:#{self.id}",
[action.from.node.id, action.from.node.neo_id].join(":")
)
end
end
# Perhaps we could do