Skip to content

Instantly share code, notes, and snippets.

View ParthBarot-BoTreeConsulting's full-sized avatar

Parth Barot ParthBarot-BoTreeConsulting

View GitHub Profile
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / 1.first_framework_code.py
Last active September 25, 2017 07:49
Python client for CryptoCompare
class Client:
def coin_list(self):
return False
def coin_snapshot_full_by_id(self, coin_id):
return False
def coin_snapshot(self, fsym, tsym):
return False
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / ruby_python_golang.md
Last active August 31, 2017 12:06
Ruby Vs Python Vs Golang

Ruby version

#Recursive version which we will write mostly!
def fibonacciVal(n)
  if n == 0
    return 0
  elsif n == 1
    return 1
  else
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / video_youtube_integration.rb
Last active August 10, 2017 09:54
Youtube API integration using YT gem
#
# Old code, which has a loop and sends API call for each video ID
#
video_ids.map do |video_id|
Yt::Video.new(id: video_id).select(:snippet, :content_details, :statistics, :status)
end

Problem

Assuming there is an array A = [1,3,-1,4,2], We have the linked list built as following,

A[0] = 1
A[1] = 3
A[3] = 4
A[4] = 2
A[2] = -1
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / js_integer_to_bytes.js
Created June 28, 2017 05:52
JS - 32 bit integer to bytes
~$ node
> var calculatedChecksum = 1513135
// Anding an integer with 0xFF leaves only the least significant byte.
// For example, to get the first byte, we can write "<int value> & 0xFF"
// This is typically referred to as "masking"
> var firstByte = calculatedChecksum & 0XFF
// 0XFF00 is hexadecimal, We are masking out the lower byte of your number,
// then bit-shifting all of the bits to the right by 8.
// Final code
var MayApp = {};
MyApp.Base = {
data: {
rules: {
FirstSet:{
"0-12": {
"0-12000":{
"0-90" :{
fixedVal: 0.4
// intermediate code
var MyApp = {};
MyApp.Base = {
data: {
rules: {
FirstSet:{
"0-12": {
"0-12000":{
"0-90" :{
DEFINE amount, fixedVal, myDataVal
IF RANGE(0 - 12) INCLUDES myDataVal
IF RANGE(0,12000) INCLUDES amount
IF RANGE(0,95) INCLUDES calculatedVal
RETURN 0.8
ELSEIF RANGE(95,*) INCLUDES calculatedVal
RETURN 0.7
var MyApp = {};
MyApp.Base = {
getFixedVal: function(){
//Javascript code before refactoring
var myDataVal = someCalculationHere();
var amount = someInputFieldValue;
var fixedVal = 0;
if(myDataVal > 12){
if(0 < amount && amount <= 12000){
@ParthBarot-BoTreeConsulting
ParthBarot-BoTreeConsulting / js_refactor_final_version.js
Last active May 17, 2017 18:57
Javascript Refactoring - Nested conditions to readable code using recursion
// Final code
var MayApp = {};
MyApp.Base = {
data: {
rules: {
FirstSet:{
"0-12": {
"0-12000":{
"0-90" :{
fixedVal: 0.4