Skip to content

Instantly share code, notes, and snippets.

View amolpujari's full-sized avatar
💭
I may be slow to respond.

Amol Pujari amolpujari

💭
I may be slow to respond.
  • Pune
View GitHub Profile
@amolpujari
amolpujari / transaction_spec.rb
Last active August 29, 2015 13:56
dummy transactions
require 'spec_helper'
describe "Transaction" do
it "should handle dummy numerals" do
transaction_input(%{
x1 is I
x5 is V
x10 is X
x50 is L
x100 is C
@amolpujari
amolpujari / spec_helper.rb
Last active August 29, 2015 13:56
spec_helper.rb reading STDIO
require "#{File.dirname(__FILE__)}/../lib/transactions.rb"
include Transactions
def capture_stdout(&block)
original_stdout = $stdout
$stdout = fake = StringIO.new
begin
yield
ensure
$stdout = original_stdout
@amolpujari
amolpujari / DBCon.java
Created February 11, 2014 21:38
my first attempt of writing a java class that would hanlde multiple db connections and their status
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
@amolpujari
amolpujari / mongodb_data_modeling_and_implementations_notes.md
Created February 12, 2014 05:21
MongoDB Data Modeling and Implementations Notes

MongoDb Data Modeling Notes - v1.0

This is a rough document getting prepared for db design and architect level decisions to be made while dealing with area where one wants to consider MongoDB abd web services.

The tools would mainly include mongoDb, RSTful resources, background jobs, and possible queuing engine(RabbitMQ) to provide unit inputs to the background jobs. After measurements caching layers like ElasticSearch can be introduced as require. MySQL can be considered in few cases to support non-relational data storage as per need.

RESTful services and background jobs can be implemented using best frameworks available in Java. Or now a days extreme-service-developers are talking about wonders of Go language, hence would be great if Go language is considered for writing service layer. This is one very nice article about the REST services in Go

@amolpujari
amolpujari / egauge_simulator.py
Created February 25, 2014 06:33
egauge data simulator
push_url = None
auth_string = None
register_names = []
reporting_interval = 60
min_reporting_interval = 5
max_reporting_interval = 600
sampling_interval = 1
@amolpujari
amolpujari / pipable.rb
Last active August 29, 2015 14:06 — forked from pcreux/pipable.rb
# Elixir has pipes `|>`. Let's try to implement those in Ruby.
#
# I want to write this:
#
# email.body | RemoveSignature | HighlightMentions | :html_safe
#
# instead of:
#
# HighlightMentions.call(RemoveSignature.call(email.body)).html_safe
#
@amolpujari
amolpujari / simple_captcha.rb
Created June 9, 2015 05:21
show_simple_captcha in a liquid template
module Liquid
module Tags
module SimpleCaptcha
class HumanTest < ::Liquid::Tag
include ::ActionView::Helpers::FormTagHelper
include ::SimpleCaptcha::ViewHelper
attr_accessor :request, :session
def render(context)
@amolpujari
amolpujari / test_alert.rb
Created August 2, 2012 19:03
adding a new alert to the rails app
class TestAlert < AlertComposer
set_alert :name => 'Test alert',
:description => 'budget reached and get alerts',
:level => 'error', # or 'warning', 'danger' or default => 'info'
:flash => true # default false, to ensure system notification is flashed to get attention
def notify receiver, related_id, extra={}
"this is test system alert :) or return nil to avoid"
end
@amolpujari
amolpujari / main.rb
Created August 13, 2012 02:15
app/channels/
require 'goliath'
require 'active_record'
require 'active_support'
#require 'em-synchrony'
#require 'em-synchrony/em-http'
# The location of the Rails app to integrate
RAILS_APP ||= "#{File.expand_path File.dirname(__FILE__)}/../.."
@amolpujari
amolpujari / gist:3887565
Created October 14, 2012 06:08
override rassoc
class Array
def rassoc obj, place=1
if place
place = place.to_i rescue -1
return if place < 0
end
self.each do |item|
next unless item.respond_to? :include?