Skip to content

Instantly share code, notes, and snippets.

View vparihar01's full-sized avatar

Vivek Parihar vparihar01

View GitHub Profile
@vparihar01
vparihar01 / varnish_cache_dummy_request.rb
Last active August 29, 2015 14:12
dummy request for creating dummy request and cache
test = ["Motorola", "X", "2nd", "Gen", "Moto", "Blackbery"]
test.each do |i|
uri = URI.parse("http://xyz#{i}")
res = Net::HTTP.get(uri)
end
assests_types = ["/images/dummy/","/js/vendor/","/css/vendor"]
assets_base_path ="/JavascriptProjects/frontend/src/main/webapp/resources"
@vparihar01
vparihar01 / gist:c00f5d3ea578de6d8f46
Created December 26, 2014 10:17
Varnish default configuration works for each varnish cache.
# Gzip Initial GZIP Rule javascript only
if ((beresp.status == 200 || beresp.status == 404) && (beresp.http.content-type ~ "^(text\/html|application\/x\-javascript|aapplication\/javascript|text\/javascript)\s*($|;)" || req.url ~ "\.(js|ttf|woff)($|\?)" ) ) {
# always set vary to make sure uncompressed versions dont always win
if (!beresp.http.Vary ~ "Accept-Encoding") {
if (beresp.http.Vary) {
set beresp.http.Vary = beresp.http.Vary ", Accept-Encoding";
} else {
set beresp.http.Vary = "Accept-Encoding";
}
Architecture: Rails 3.2, Solr 1.4 with sunspot_solr gem, Apache HTTP server as reverse proxy to
Rails app, Jquery UI
Note: I don't care about the distinction between autocomplete and autosuggest. I am implementing what some
people call autosuggest, and I'm calling it autocomplete.
Given the above existing architecture, I want to add an autocomplete field into my app for a single
attribute on a single model. It needs to be fast and secure (duh). The search target field could have
white space and the search input should allow it, e.g., if I search with "iker's gui" it should return
if ( u_has_birthday_today() )
{
say_happy_birthday();
while ( !is_stomach_full() )
{
aquire_cake();
}
}
else
{
db.notifications.aggregate({ "$group" => {
"_id" => {
"nagios_hostname" => "$nagios_hostname",
"nagios_state" => "$nagios_state",
"nagios_service" => "$nagios_service",
"nagios_epoch" => "$nagios_epoch"
},
"stateCount" => { "$sum" => 1 }
}},
{ "$group" => {
@vparihar01
vparihar01 / postgres_table_size.rb
Last active August 29, 2015 14:06
Ruby script to get the postgres database tables sizes and store them into the hash.
sql = "SELECT tablename FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename;"
tables = ActiveRecord::Base.connection.execute(sql)
tables_size={}
tables.each do |table|
name = table['tablename']
sql = "SELECT pg_size_pretty(pg_total_relation_size('#{name}'));"
res = ActiveRecord::Base.connection.execute(sql)
puts "#{name} #{res[0]['pg_size_pretty']}"
tables_size["#{name}"] = res[0]['pg_size_pretty']
puts tables_size
@vparihar01
vparihar01 / application_controller.rb
Created August 27, 2014 11:41
This particular gist it to make sure your CAS backed application is intercepting the Sign Out request for all your Rails applications which been using devise+CAS Authenticable Module for sign in and sign out. To use this We first need to place the single_sign_out.rb file in our lib folder. And then just include this SingleSignOut in your applica…
class ApplicationController < ActionController::Base
require "single_sign_out"
before_filter :authenticate_user!
include SingleSignOut
#NOTE: Define this will inspect logger info of paramenter,controller name and action
def print_logger_info parameter
logger.info "######{" Controller : "+params[:controller]+" "}#################{" Action : "+params[:action]+" "}###########{" Parameters : "+parameter.inspect+" "}#############}" if Rails.env.development?
logger.info "###=>>>>>>>>>>>>>>>>>>session['cas_last_valid_ticket']###{session['cas_last_valid_ticket'].inspect}"
@vparihar01
vparihar01 / spree_error.log
Created August 26, 2014 11:45
Spree error log for variants.
tarted POST "/nfhs_shop/orders/update_order" for 72.49.253.235 at 2014-08-26 11:03:07 +0000
Processing by Spree::OrdersController#update_order as */*
Parameters: {"option_id"=>"", "product_id"=>"419", "previous_variant"=>"578976", "buy_type"=>"Yourself"}
undefined method `variants' for nil:NilClass
["/var/www/www.nfhslearn.com/releases/20140826103506/app/controllers/spree/orders_controller_decorator.rb:48:in `update_order'", "/var/www/www.nfhslearn.com/shared/Installed_bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/implicit_render.rb:4:in `send_action'", "/var/www/www.nfhslearn.com/shared/Installed_bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/base.rb:167:in `process_action'", "/var/www/www.nfhslearn.com/shared/Installed_bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/rendering.rb:10:in `process_action'", "/var/www/www.nfhslearn.com/shared/Installed_bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/abstract_controller/callbacks.rb:18:in `block in proc
users = ["xxxxx@xxxxx.com","xxxx@xxxx.com"]
users.each do |i|
user = User.where(:email => i).first
puts "USER ADMIN CREATION=>>>> #{user.class}"
user.add_role :SuperAdmin
end
@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;
}