Skip to content

Instantly share code, notes, and snippets.

View we4tech's full-sized avatar

Hossain Khan we4tech

View GitHub Profile
@we4tech
we4tech / Gemfile
Created February 28, 2015 17:45
Gemfile for Rails 4.2.0 with Angularjs, Jasmin, Rspec, FactoryGirl and so on.
source 'https://rubygems.org'
source 'https://rails-assets.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
@we4tech
we4tech / state.rb
Last active August 29, 2015 14:15
Countries with states
class State
STATES = {
'US' => {
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
@we4tech
we4tech / app_logrotate.conf
Last active August 29, 2015 14:05
Rails or ruby application logrotate configuration.
"/path/to/application/current/log/*.log" {
daily
su user_name group_name
size 5M
missingok
rotate 5
compress
delaycompress
notifempty
copytruncate
@we4tech
we4tech / site.conf
Created August 15, 2014 10:41
Rails4 and Angularjs with Nginx + Proxy cache
upstream puma {
server 127.0.0.1:8080 fail_timeout=0;
}
proxy_cache_path /home/of/all/evil/stuffs/as/shared/tmp/cache/nginx levels=1:2 keys_zone=api-cache:10m max_size=1000m inactive=200m;
# HTTP server
#
server {
@we4tech
we4tech / cleanup.rb
Created July 13, 2014 18:07
Replace none alpha numeric unicode characters.
text.gsub(/[^[[:alnum:]]]/, ' ').gsub(/\s+/, ' ')
@we4tech
we4tech / common_api_response.rb
Last active August 29, 2015 14:02
A simple and quick way to generate restful api for any model.
# spec/support/shared/common_api_response.rb
shared_examples 'common api response' do |param_key|
it 'responds in json' do
expect(response.content_type).to be == 'application/json'
end
it "assigns #{param_key}" do
expect(assigns(param_key.to_sym)).not_to be_nil
end
@we4tech
we4tech / convert_to_csv_from_mongodb.rb
Created June 12, 2014 08:41
Converts data from mongodb to CSV, just an example code (which utilizes multi threads and queue in ruby)
require 'rubygems'
require 'bundler/setup'
require 'csv'
require 'pp'
# Configure and load dependencies
env = :development
config = {
'development' => {
'uri' => 'mongodb://localhost:27017/some_database'
@we4tech
we4tech / bootstrap.sh
Last active August 29, 2015 14:01 — forked from elvio/bootstrap.sh
With ruby 2.0
#!/usr/bin/env bash
sudo apt-get -y update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev git
sudo mkdir /tmp/ruby_install && cd /tmp/ruby_install
wget -O ruby-install-0.4.2.tar.gz https://github.com/postmodern/ruby-install/archive/v0.4.2.tar.gz
tar -xzvf ruby-install-0.4.2.tar.gz
cd ruby-install-0.4.2/
sudo make install
sudo ruby-install -i /usr/local -p https://gist.githubusercontent.com/plexus/10021261/raw/305492ebd17308e55eee1baab27568fafaa940cb/ruby-2.0-p451-readline.patch ruby 2.0
gem install chef --no-ri --no-rdoc
@we4tech
we4tech / steps.md
Last active August 29, 2015 14:00
Setting up a Mongodb instance with RAID 10 and separate disk for Journal and Log

Mongodb Server Setup

At the end of process we will have /mdb/data for mongodb database directory which is on RAID 10. /mdb/journal which is used for storing journal files with IOPS 250 and /mdb/log with IOPS 125.

  1. Let's assume we have xvdb, xvdc for /mdb/data
  2. We have xvdd for /mdb/journal
  3. And xvde for /mdb/log
  4. Let's follow the following commands
@we4tech
we4tech / es_result_transformer.js
Created April 9, 2014 09:01
ElasticSearch result transformer example
var data = [],
now = new Date().getTime();
root.hits.hits.forEach(function(hit) {
var d = new Date(),
ts = hit.fields.expired_at_de * 1000;
d.setTime(ts);
var diffInHours = (now - ts) / 1000.0 / 60.0 / 60.0;