Skip to content

Instantly share code, notes, and snippets.

View vparihar01's full-sized avatar

Vivek Parihar vparihar01

View GitHub Profile

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@vparihar01
vparihar01 / nokogiri_ruby_xml.rb
Created May 21, 2014 06:48
Gitst to test xml parsing the quizes and its sample data
def parse_xml(xml)
doc = Nokogiri::XML.parse(File.read(xml))
puts"___________________________"
puts File.basename(xml)
puts"___________________________"
#doc = Nokogiri::XML.parse(File.read(Rails.public_path+"/courses/fundOfCoaching/v2_0/Course/pages/xml/1-2-6.xml"))
#doc.root.elements.each do |i|
# #puts "#{i['type']}!!!!!!!!!!!!!#{i['subtype']}"
# #puts i["type"].eql? "interactive"
# if (i["type"].eql? "interactive") && (i["subtype"].eql? "quiz")
SELECT o.saleTypeID,o.userID, cv.versionID as courseVersionID, cv.courseID , s.stateID, s.stateName
FROM CoursePurchases as cp , OrderItems as oi, Orders as o , CourseVersions as cv, States as s
where certificateStatusID = 1
and cp.orderItemID = oi.orderItemID
and oi.orderID = o.orderID
and cp.versionID = cv.versionID
and cv.stateID = s.stateID
def my_logger
@@mdefy_logger ||= Logger.new("#{Rails.root}/log/quiz.log")
end
c = LegacyCourses.find(11111)
c.legacy_course_units.each_with_index do |i,index|
num = index
#my_logger.info "Chapter #{i.title}"
i.legacy_course_sections.all.each_with_index do |j,index|
@vparihar01
vparihar01 / copy_s3_to_another_acount.rb
Created June 28, 2014 12:33
Copying files between S3 accounts.
#!/usr/bin/ruby
require 'rubygems'
require 'right_aws'
# ACL property differences
old_owner_id='xxxxxxx'
new_owner_id='xxxxx'
oldAWS = RightAws::S3Interface.new('access_key_old','secret_key_old')
newAWS = RightAws::S3Interface.new('access_key_new','secret_key_new')
@vparihar01
vparihar01 / update_empty_refeence.rb
Last active August 29, 2015 14:03
this to find and update all empty questions reference.
Course.find(x).assessments.each do |i|
i.questions.each do |j|
puts j.test_reference= {"page"=>"4753", "section"=>"61813"} unless j.test_reference.present?
j.save
end
end
Course.find(x).assessments.each do |i|
@vparihar01
vparihar01 / rake_db_tasks.rake
Created July 1, 2014 16:13
List of rake task related to db migrations.
rake db:create[:all]: If :all not specified then create the database defined in config/database.yml for the current RAILS_ENV. If :all is specified then create all of the databases defined in config/database.yml.
rake db:fixtures:load: Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y
rake db:migrate [VERSION=n]: Migrate the database through scripts in db/migrate. Target specific version with VERSION=n
rake db:migrate:redo [STEP=n]: (2.0.2) Revert the database by rolling back "STEP" number of VERSIONS and re-applying migrations.
rake db:migrate:reset: (2.0.2) Drop the database, create it and then re-apply all migrations. The considerations outlined in the note to rake db:create apply.
rake db:reset: Drop and re-create database using db/schema.rb. The considerations outlined in the note to rake db:create apply.
rake db:rollback [STEP=N]: (2.0.2) Revert migration 1 or n STEPs back.
rake db:schema:dump: Create a db/schema.rb file that can be portably used against an
@vparihar01
vparihar01 / unicorn_init.sh
Created July 10, 2014 18:17
Unicorn Bash script for Zero DownTime Deployment. We can deploy as many as time on production environment without showing application down page. This gives us one extra hand to do continuos deployment and integration on live server. Things like this can't be achieved using the passenger.
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn
@vparihar01
vparihar01 / nginx_multiple_ip_bypass.conf
Created July 10, 2014 18:26
Just a simple nginx script, which let certain user ip to use app and all other people would see maintenance page. Very handy when going live but dev can access the page as it. Serve the Maintenance Page To All Visitors But Allow Full Access To Certain IP
if ($remote_addr !~ "^(x.x.x.122|x.x.x.122x.x.x.122|x.x.x.122x.x.x.122|x.x.x.122x.x.x.122|x.x.x.122x.x.x.122|x.x.x.122)$") {
return 503;
}
error_page 503 @maintenance;
location @maintenance {
root /var/www/nfhs;
rewrite ^(.*)$ /index.html break;
}
@vparihar01
vparihar01 / server_static_assets_with_nginx.conf
Created July 10, 2014 18:31
Its very costly to server assets from application server like Passenger or Unicorn or Puma. In this case we would prefer to server our statics directly from nginx. This will help application performance and decrease down the memory consumption.
# if the request is for a static resource, nginx should serve it directly
location ~ ^/(images|javascripts|stylesheets|system|assets|jwplayer)/* {
root /var/www/www.example.com/current/public;
add_header Last-Modified "";
add_header ETag "";
expires max;
break;
}