Skip to content

Instantly share code, notes, and snippets.

View manojnaidu619's full-sized avatar
🎯
Focusing

Manoj Kumar manojnaidu619

🎯
Focusing
  • Bangalore,India
View GitHub Profile

Keybase proof

I hereby claim:

  • I am manojnaidu619 on github.
  • I am manojkumar619 (https://keybase.io/manojkumar619) on keybase.
  • I have a public key ASBRwy21N3auADlR8_n5A1M67ydjVsOAc6A56SOF6fKRiQo

To claim this, I am signing this object:

@manojnaidu619
manojnaidu619 / article_image_uploader.rb
Created August 25, 2021 14:47 — forked from jcsrb/article_image_uploader.rb
CarrierWave extension fix_exif_rotation, strip, quality, resize_to_fill_if_larger
class ArticleImageUploader < ImageUploader
process :fix_exif_rotation
process :strip
process :convert => 'jpg'
process :quality => 85 # Percentage from 0 - 100
version :gallery_thumb do
process :resize_to_fill => Settings.images.article_images.processing.gallery_thumb #44x44
end
@manojnaidu619
manojnaidu619 / rails_eager_load.md
Created January 15, 2021 12:39 — forked from johncip/rails_eager_load.md
Active Record eager loading strategies

N+1 query problem

  • ORMs make it easy to a query per loop iteration, which we want to avoid

eager_load

  • single query (left outer join)
  • can reference the other table's columns in where

preload

  • a few queries (one per table)
  • typically faster
@manojnaidu619
manojnaidu619 / combinations.js
Created December 22, 2020 12:16
Generate all combinations
function subset(nums) {
var result = [];
dfs(0, [], nums, result);
console.log(result);
}
function dfs(index, path, nums, res) {
res.push([...path])
for (var i = index; i < nums.length; i += 1){
path.push(nums[i]);
@manojnaidu619
manojnaidu619 / grid_traveler.js
Created December 18, 2020 06:34
You are a traveller on a 2d grid. You begin in the top-left corner and your goa is to travel to the bottom-right corner. You may only move down/right
const gridTraveler = (m, n, memo={}) => {
const key = `${m},${n}`
if (key in memo) return memo[key]
if (m === 1 && n === 1) return 1
if (m === 0 || n === 0) return 0
memo[key] = gridTraveler(m - 1, n, memo) + gridTraveler(m, n - 1, memo)
return memo[key]
}
console.log(2,2) // 2
console.log(gridTraveler(18,18)) //2333606220
@manojnaidu619
manojnaidu619 / alphavantage-bot.py
Last active October 2, 2020 16:31
A script to render real-time stocks/cryptocurrency charts📈 inside readme.
import pandas, os, random
import matplotlib.pyplot as plt
from datetime import datetime
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.cryptocurrencies import CryptoCurrencies
####### Values could be customized (Right now we are choosing random values) ############
CHARTDOMAIN = random.choice(['stock', 'cryptocurrency'])
@manojnaidu619
manojnaidu619 / gist:3c0b973d2c8f4507eb518433253c1c7b
Created August 14, 2020 05:29 — forked from jrochkind/gist:59b6330e3f52710cc49e
Monkey patch to ActiveRecord to forbid
######################
#
# Monkey patch to ActiveRecord to prevent 'implicit' checkouts. Currently tested with Rails 4.0.8, prob
# should work fine in Rails 4.1 too.
#
# If you create a thread yourself, if it uses ActiveRecord objects without
# explicitly checking out a connection, one will still be checked out implicitly.
# If it is never checked back in with `ActiveRecord::Base.clear_active_connections!`,
# then it will be leaked.
#
@manojnaidu619
manojnaidu619 / rails-jsonb-queries
Created July 16, 2020 16:27 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@manojnaidu619
manojnaidu619 / SLL_construction.py
Last active June 20, 2020 05:45
Linked list construction in python
class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def form_ll(self, length):
@manojnaidu619
manojnaidu619 / pythagorean_triplet.py
Created June 18, 2020 10:59
Pythagorean Triplet in an array
# Problem here -> https://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-unsorted-array/
nums = [10, 4, 6, 12, 5]
found = False
for x in range(0, len(nums)): nums[x] *= nums[x]
nums.sort()
checker = len(nums) - 1