Skip to content

Instantly share code, notes, and snippets.

@wilspi
wilspi / mongo_dump_collections.sh
Last active January 24, 2018 09:54
Dumps given collections from source mongo db to destination mongo db
# Dumps given collections from source mongo db to destination mongo db
# Source DB Creds
source_host=""
source_port=""
source_user=""
source_password=""
source_db=""
# Destination DB Creds
@wilspi
wilspi / gen_cert.sh
Created January 22, 2018 12:17
Generate self signed certificates
# Provide output directory path as argument
OUTPATH=$1
# Generate CA key:
openssl genrsa -des3 -out $OUTPATH/ca.key 4096
# Generate CA certificate:
openssl req -new -x509 -days 365 -key $OUTPATH/ca.key -out $OUTPATH/ca.crt
@wilspi
wilspi / gen_grpc_code.sh
Created January 22, 2018 12:43
Generates client and server GRPC python code for all protos, given protos' directory. Read more here: https://grpc.io/docs/tutorials/basic/python.html#generating-client-and-server-code
#!/bin/bash
# Proto files directory
PROTOS_PATH="src/protos/"
# Directory in which auto generated code will be saved
AUTOGEN_GRPC_PATH="src/autogen_grp/"
# Generate python grpc code for each proto
# Requires grpcio-tools: pip install grpcio-tools
for file in "$PROTOS_PATH"*
@wilspi
wilspi / setup_react_native.md
Last active February 9, 2020 08:52
Setup for `React Native`

TODO

@wilspi
wilspi / Img2Text.py
Created March 17, 2018 04:47
Image to Text
from PIL import Image
from pytesseract import image_to_string
print image_to_string(Image.open('test.png'))
#print image_to_string(Image.open('test-english.jpg'), lang='eng')
@wilspi
wilspi / ScrapeBookmyshow.py
Created March 17, 2018 05:14
Screen Scraper based API for BookMyShow
#!/usr/bin/python
# Screen scraper based API for BookMyShow.
# Test Code for Bengaluru
import re
import urllib2
class BookMyShowClient(object):
NOW_SHOWING_REGEX = '{"event":"productClick","ecommerce":{"currencyCode":"INR","click":{"actionField":{"list":"Filter Impression:category\\\/now showing"},"products":\[{"name":"(.*?)","id":"(.*?)","category":"(.*?)","variant":"(.*?)","position":(.*?),"dimension13":"(.*?)"}\]}}}'
@wilspi
wilspi / GetQuotes.py
Created March 17, 2018 05:16
Get Quotes from BrainyQuote.com
#!/usr/bin/python
from selenium import webdriver
from bs4 import BeautifulSoup
def getPage(url):
# open with chromedriver
browser = webdriver.Chrome()
browser.get(url)
@wilspi
wilspi / udp_server.py
Created February 12, 2019 14:08
Mock Statsd server
# -*- coding: utf-8 -*-
# Script to run UDP Server on 127.0.0.1:8126
# This mocks statsd server for testing
import socket
UDP_IP_ADDRESS = "127.0.0.1"
UDP_PORT_NO = 8126
@wilspi
wilspi / main.rs
Last active May 10, 2019 15:07
Rust - abnormal behaviour - dangling reference
#[derive(Debug)]
pub enum Superheroes {
Superman(Superman),
Batman(Batman)
}
#[derive(Debug)]
pub struct Superman {
id: i32,
name: String,
@wilspi
wilspi / setup_nix.sh
Last active July 15, 2020 15:10
Setup (nix)[https://nixos.org/nix/] on Arch Linux
#!/bin/sh
# Install nix via yay (AUR helper)
yay -S archlinux-nix
# Read: https://nixos.org/nix/manual/#ssec-multi-user
# Add nix builder groups
sudo groupadd -r nixbld
for n in $(seq 1 10); do sudo useradd -c "Nix build user $n" \