View array_iteration_thoughts.md

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

View flatten_my_array.rb
# This is a custom method to flatten any given array
# this is simple one to read and understand
# by name it means to accept only array, so it is known that passing any other object than array will fail
def flatten_my_array arr
new_arr = []
arr.each do |element|
if element.is_a? Array
new_arr = new_arr.concat flatten_my_array(element)
# know that Array#concat is faster way to concat two arrays in ruby
View annualized_return.rb
if investment and investment.deal and investment.deal.annual_return.present?
return investment.deal.annual_return.to_i
end
return 0 if projected_earnings.blank?
return 0 if percent_profit.blank?
return 0 if percent_profit.to_f < 1
year_diff = projected_earnings.last.distribution_date.d_date.year.to_i - DateTime.now.year.to_i
View simple_captcha.rb
module Liquid
module Tags
module SimpleCaptcha
class HumanTest < ::Liquid::Tag
include ::ActionView::Helpers::FormTagHelper
include ::SimpleCaptcha::ViewHelper
attr_accessor :request, :session
def render(context)
View 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
#
View egauge_simulator.py
push_url = None
auth_string = None
register_names = []
reporting_interval = 60
min_reporting_interval = 5
max_reporting_interval = 600
sampling_interval = 1
View mongodb_data_modeling_and_implementations_notes.md

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

View DBCon.java
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;
View spec_helper.rb
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
View transaction_spec.rb
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