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
@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 / 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 / rails_deployment.md
Last active May 12, 2022 14:34
Rails deployment to AWS EC2

Rails Deployment to AWS EC2

Stack : (Nginx + Phusion Passenger + Postgresql)

  • Step -1

    To Launch an EC2 instance from aws console with all the credentials and configurations hooked.

  • Step-2

@manojnaidu619
manojnaidu619 / PaytmController.rb
Last active October 26, 2019 18:02
Controller file for Paytm integration in ROR (Edits required in line no's : 5, 264-273, 358)
class PaytmController < ApplicationController
skip_before_action :verify_authenticity_token
def paytm
@checksum = new_pg_checksum(params, MERCHANT_KEY) # MERCHANT_KEY = your Merchant key
end
def handle_payment
if params["CHECKSUMHASH"]
paytmHash = Hash.new
@manojnaidu619
manojnaidu619 / contentful.rb
Created October 2, 2019 00:47
Contentful Ruby SDK usage
require 'contentful'
client = Contentful::Client.new(
space: '<spacd_id>',
access_token: '<access-token>',
dynamic_entries: :auto
)
entries = client.entries # For grabbing entries
entries.each do |entry|
@manojnaidu619
manojnaidu619 / level_order_traversal.cpp
Created August 8, 2019 04:58
BFS / Level order Traversal in CPP
queue<TreeNode*> q; // To store the node addresses
vector<int> result; // To store the values in the node
result.push_back(root->val);
q.push(root);
while (!q.empty()) {
node = q.front();
q.pop();
if(node->left){
result.push_back(node->left->val);
q.push(node->left);
@manojnaidu619
manojnaidu619 / hash_table_insertion&deletion(chaining).cpp
Last active July 8, 2019 07:18
Insertion & Deletion to/from Hash Table(Chaining) in CPP
#include <iostream>
using namespace std;
struct Node{
int data;
struct Node *next;
};
int hash_(int key)
{
@manojnaidu619
manojnaidu619 / hash_table_creation(chaining).cpp
Created July 7, 2019 15:14
Creation of Hash Table(chaining) in CPP
#include <iostream>
using namespace std;
struct Node{
int data;
struct Node *next;
};
int main(){
@manojnaidu619
manojnaidu619 / max_heap.cpp
Last active July 6, 2019 12:05
Creation and insertion into Binary max heap
#include <iostream>
#include <vector>
using namespace std;
vector <int> a = {0};
void insert(int ele){
int temp;
a.push_back(ele);
long last = a.size()-1;
@manojnaidu619
manojnaidu619 / bitwise_complement.rb
Last active July 4, 2019 17:46
Leetcode Solution for "Number Complement" problem in Ruby
=begin
687.to_s(2) # "1010101111"
"1010101111".to_i(2) # 687
=end
def find_complement(num)
num = num.to_s(2).chars
num.map!{|i| i.to_i}
for x in 0..num.size-1 do
if num[x]==0