Skip to content

Instantly share code, notes, and snippets.

View GargNishant's full-sized avatar
💭
Next Stop Found

Nishant Garg GargNishant

💭
Next Stop Found
View GitHub Profile
@GargNishant
GargNishant / Dockerfile
Created December 8, 2022 17:24
Initialize PostgreSQL with init
FROM postgres:15.1-alpine
ENV POSTGRES_USER=admin
ENV POSTGRES_PASSWORD=admin
ENV POSTGRES_DB=database
COPY init.sql /docker-entrypoint-initdb.d/
# docker build -t db_image .
# docker run -d --name db_container -p 5432:5432 db_image
@GargNishant
GargNishant / JenkinsFile
Created February 9, 2021 05:59
JenkinsFile with Dockerfile Agent
pipeline {
agent {
dockerfile { // Pick up the DockerFile in root repo. And excute every command inside the container
args '-u root:sudo' // Run docker run commands with these args
}
}
stages {
stage('Build') {
steps {
sh 'chown -R `id -u` /code' //Change the Permission
@GargNishant
GargNishant / functions.sql
Created December 14, 2020 10:31
MySql Functions
-- Create a function
CREATE FUNCTION full_name (first_name CHAR(20), last_name CHAR(30))
RETURNS CHAR(55) DETERMINISTIC
RETURN CONCAT(first_name,' ',last_name);
-- Usage. From same Db
SELECT full_name(f_name, l_name) FROM people AS fn
-- Result
--| fn |
@GargNishant
GargNishant / foreign_key.sql
Last active December 14, 2020 07:01
Mysql Foreign Key Constraint
CREATE TABLE races (
race_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
race_name VARCHAR(30) NOT NULL
)ENGINE=INNODB;
CREATE TABLE characters(
char_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
char_name VARCHAR(50) NOT NULL,
race_id TINYINT UNSIGNED NOT NULL,
CONSTRAINT `fk_char_race`
def longestPrefix(data):
n = len(data)
# break the string from middle and start matching left and right string.
# If they are equal return size of any one string else try for shorter lengths on both sides.
for i in range(n//2, 0, -1):
prefix = data[0:i]
suffix = string[n-i:n]
if prefix == suffix:
@GargNishant
GargNishant / main.py
Created November 2, 2020 10:20
Hackerrank New Year Chaos: https://bit.ly/34QxmKy
import math
import os
import random
import re
import sys
def minBride(input_):
steps = 0
input_ = [P-1 for P in input_]
@GargNishant
GargNishant / left_rotation.py
Created November 1, 2020 04:54
Hacker rank Left Rotation: https://bit.ly/3eeZPfT
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the rotLeft function below.
def rotLeft(list_, rot):
@GargNishant
GargNishant / class_methods.py
Created October 25, 2020 10:04
Different type of method in Python Class
from datetime import date
class Person:
def __init__(self, age, name): # Instance Method. Has access to Object instance
self.age = age
self.name = name
@classmethod
def old_person(cls, name): # Class Method. Factory Method implementation
return cls(age=60, name=name)
@GargNishant
GargNishant / python_patterns.py
Created October 19, 2020 15:41
Simple pattern printing in python
"""
*
**
***
****
*****
"""
len = int(input("Enter a positive number"))
count = 1
while(count <= len):
@GargNishant
GargNishant / main.py
Created October 17, 2020 10:58
Python Multiple Inheritance
"""
Multiple inheritance with same method name, but no override of parent class
method
"""
class Add:
def perform(self,a,b):
return a+b;
class Subtract: