Skip to content

Instantly share code, notes, and snippets.

View tejasbubane's full-sized avatar
💭
WFH 🏡

Tejas Bubane tejasbubane

💭
WFH 🏡
View GitHub Profile
@tejasbubane
tejasbubane / README.md
Last active December 26, 2015 09:59
Server installation with RVM, ruby, rails, nginx and passenger

if server name is too long change server_names_hash_bucket_size in nginx configuration file at /opt/nginx/conf/nginx.conf

If everything goes right passenger_root /usr/local/rvm/gems/ruby-1.9.3-p448/gems/passenger-4.0.21; passenger_ruby /usr/local/rvm/wrappers/ruby-1.9.3-p448/ruby; else make changes in the nginx.conf file (/opt/nginx/conf/nginx.conf)

Later steps:

@tejasbubane
tejasbubane / s3_bucket_mount.sh
Last active July 17, 2019 17:26
Steps to be done for mounting s3 bucket on an amazon ec2 instance
# download the proper versions of s3fs and fuse
wget http://s3fs.googlecode.com/files/s3fs-1.61.tar.gz
wget http://downloads.sourceforge.net/project/fuse/fuse-2.X/2.8.4/fuse-2.8.4.tar.gz
# unpack them
tar -xzf s3fs-1.61.tar.gz
tar -xzf fuse-2.8.4.tar.gz
# install dependencies
yum install gcc libstdc++-devel gcc-c++ curl-devel libxml2-devel openssl-devel mailcap
@tejasbubane
tejasbubane / ssh_local.sh
Created November 13, 2013 09:18
Commands to ssh into local machine
avahi-browse -tl _workstation._tcp
ssh <username>@<computer-name>.local
@tejasbubane
tejasbubane / mongo_rails_parse.rb
Last active December 28, 2015 04:59
Parser for all log file in my directory and put the data into mongodb
require 'mongo'
require 'time'
include Mongo
mongo_client = MongoClient.new("localhost",27017)
db = mongo_client.db("logs")
requests = db.collection("requests") # master database
date_logs = db.collection("date_logs") # One record per day
user_details = db.collection("user_details")
@tejasbubane
tejasbubane / will_paginate_bootstrap.js
Created November 19, 2013 10:56
This snippet of javascript will convert the will_paginate's default html into the one suitable for bootstrap pagination.
// Just paste this code into the script tag on page and see the will_paginate links applied with pretty bootstrap
// This one is awesome! :)
// PS: Bootstrap required for this to work. Duh!
$(document).ready(function () {
$('.pagination .previous_page').text('«');
$('.pagination .next_page').text('»');
$('.pagination').each(function () {
var $bar = $(this);
$bar.find('a, .current, span').wrapAll('<ul>');
@tejasbubane
tejasbubane / mongo_install_instructions.txt
Last active December 28, 2015 23:39
Instructions for setting up mongo server on Amazon EC2 instance with CentOS(x86_64)
nano /etc/yum.repos.d/mongodb.repo
Paste the following code in this file:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
yum install mongo-10gen mongo-10gen-server
@tejasbubane
tejasbubane / sources.list
Last active December 29, 2015 15:09
Using IIT Kanpur ubuntu mirror when the default ubuntu mirrors are blocked
# Mirrors of IIT kanpur
deb http://mirror.cse.iitk.ac.in/ubuntu/ precise main restricted universe multiverse
deb-src http://mirror.cse.iitk.ac.in/ubuntu/ precise main restricted universe multiverse
# Do not forget to change the version of ubuntu (precise to something else) if needed.
@tejasbubane
tejasbubane / mongo_changes.js
Created December 5, 2013 12:44
Remove records corresponding to some dates. To be done if something goes wrong and process files again
db.snapshot_date_logs.remove({"_id.trans_date": ISODate("2013-12-04T05:00:00Z")})
db.snapshot_date_logs.remove({"_id.trans_date": ISODate("2013-12-05T05:00:00Z")})
db.date_logs.remove({"_id.trans_date": ISODate("2013-12-05T05:00:00Z")})
db.date_logs.remove({"_id.trans_date": ISODate("2013-12-04T05:00:00Z")})
user_details.remove("trans_date":{"$gte":Time.parse("2013-12-04")})
filenames.remove("_id"=>"/s3-rbi/log/rails_log_analytics/log_metrics_2013-12-04-00.log") ... upto 24 and next date if necessary
no need to change anything in items table since parser checks if open_id exists and only then inserts
@tejasbubane
tejasbubane / csv_to_hash.rb
Last active January 1, 2016 07:09
Convert a csv file to array of hashes (just like SmarterCSV), useful when SmarterCSV throws wierd errors
require 'csv'
def csv_to_array(file_location)
csv = CSV::parse(File.open(file_location, 'r') {|f| f.read })
fields = csv.shift
fields = fields.map {|f| f.downcase.gsub(" ", "_").to_sym}
csv.collect { |record| Hash[*fields.zip(record).flatten ] }
end
test = csv_to_array('test.csv')
;; call howdoi, https://github.com/gleitz/howdoi
;; Make sure this is installed first
(defvar howdoi-history nil "History for howdoi lookups, see `howdoi'")
(defun howdoi ()
"Interactive function for howdoi queries. It takes the current
word and invokes a minibuffer where the user can accept or change
the query."
(interactive)
(shell-command