Skip to content

Instantly share code, notes, and snippets.

View prince-mishra's full-sized avatar

Prince Mishra prince-mishra

  • Gurgaon
View GitHub Profile
@prince-mishra
prince-mishra / history_stuff.sql
Created September 22, 2023 18:57 — forked from slotrans/history_stuff.sql
Building blocks for generic history-keeping in Postgres.
/*
Replace "your_schema" with whatever schema is appropriate in your environment.
It is possible to use "public"... but you shouldn't!
*/
/*
Function to stamp a "modified" timestamp. Adjust the name to suit your environment,
but that name is hard-coded so it is assumed that you only use _one_ such name.
@prince-mishra
prince-mishra / git-mv-with-history
Created January 26, 2021 09:56 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@prince-mishra
prince-mishra / chromedriver_options.py
Created April 12, 2020 13:53
Options to make Chrome Webdriver work in headless mode
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("--disable-infobars")
chrome_options.headless = True
chrome_options.add_argument("--single-process")
chrome_options.add_argument("--remote-debugging-port=9222")
@prince-mishra
prince-mishra / chrome_virtual_display.py
Created April 12, 2020 13:36
run chrome in pyvirtualdisplay
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Chrome will run in a virtual display.
# you will not see the browser.
browser = webdriver.Chrome()
browser.get('http://www.google.com')
#!/bin/bash
#
# Bash script to setup headless Selenium (uses Xvfb and Chrome)
# (Tested on Ubuntu 12.04) trying on ubuntu server 14.04
# Add Google Chrome's repo to sources.list
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee -a /etc/apt/sources.list
# Install Google's public key used for signing packages (e.g. Chrome)
# (Source: http://www.google.com/linuxrepositories/)
@prince-mishra
prince-mishra / System Design.md
Created January 8, 2020 17:45 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@prince-mishra
prince-mishra / find_executable.py
Created March 27, 2019 14:18 — forked from techtonik/find_executable.py
Python Which/Where - Find executable
# https://gist.github.com/4368898
# Public domain code by anatoly techtonik <[email protected]>
# AKA Linux `which` and Windows `where`
import os
import sys
def find_executable(executable, path=None):
"""Find if 'executable' can be run. Looks for it in 'path'
(string that lists directories separated by 'os.pathsep';
@prince-mishra
prince-mishra / django-cr.md
Created February 28, 2019 11:15
Django code review checklist

If there is a change in Model, check if a corresponding Migrations file is committed.

@prince-mishra
prince-mishra / git-cheat.sh
Last active August 13, 2020 14:05
Git cheatsheet
# Update tag to a new sha
# remove tag from remotes
git push origin :refs/tags/<tag>
# force and annotate to new sha
git tag -fa <tag>
# push new tag
git push origin master --tags
# Print one line pretty log
@prince-mishra
prince-mishra / nginx.conf
Created December 31, 2018 01:28
Add CORS headers nginx
server {
listen 80;
server_name api.test.com;
location / {
# Simple requests
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;