Skip to content

Instantly share code, notes, and snippets.

View shreyakupadhyay's full-sized avatar
🎯
Focusing

Shreyak Upadhyay shreyakupadhyay

🎯
Focusing
View GitHub Profile
@shreyakupadhyay
shreyakupadhyay / insert_dict_mysql.py
Last active May 29, 2017 09:12
Insert any dictionary data into mysql
import MySQLdb
conn = MySQLdb.connect(host= "localhost",
user="root", #give your mysql database username
passwd="db password", #give mysql database password
db="db name") #give mysql database name
x = conn.cursor()
'''
insert into mysql columns
@shreyakupadhyay
shreyakupadhyay / connect_mininet_hosts_Internet.txt
Last active August 26, 2021 16:41
Connecting mininet host with Internet.
<-- Commands below connects the mininet hosts to internet and also with other mininet hosts.-->
$ sudo mn --topo=single,2 (topology of consisting 1 switch and 2 hosts)
$ sudo ifconfig s1 up
$ sudo ovs-vsctl add-port s1 enp0s3(or your NAT interface of virtual machine)
$ ifconfig enp0s3 0
$ dhclient s1 (To get the IP address for s1. Till here VM will get the internet connectivity through OVS.)
mininet> xterm h1
h1> ifconfig h1-eth0 0
@shreyakupadhyay
shreyakupadhyay / simpleNetworkTopo.py
Created September 4, 2017 10:00
Simple network topology using mininet
'''
A custom topology consisting 6 hosts and 3 switches. Where main switch is connected to other two switches.
And 3-3 hosts connected to these 2 switches. Your system should have mininet installed.
'''
from mininet.topo import Topo
class MyTopo( Topo ):
def __init__( self ):
Topo.__init__(self)
@shreyakupadhyay
shreyakupadhyay / checkARP.txt
Last active May 16, 2022 12:05
Check ARP requests in a network using mininet and tcpdump
$ sudo mn --topo single,3 --controller=remote,ip=<controller ip>,port=6633
(To make a topology with 1 switch, 1 remote controller and 3 hosts)
mininet> xterm h1 h2 h3
h2> tcpdump -XX -n -i h2-eth0 (run tcpdump to capture packets)
h3> tcpdump -XX -n -i h3-eth0
h1> ping -c1 10.0.0.2
(Do not do pingall before these. Otherwise you won't see the same ARP request on h2 and h3)
mininet> exit
@shreyakupadhyay
shreyakupadhyay / firewallAsService.md
Last active December 30, 2023 14:26
Bulding firewall as a service using OVS and mininet. This description is based on a topology consisting of 3 switches and 6 hosts. Where 3 hosts are connected to one switch and other 3 three are connected to another switch. While the third switch connects the two switches.

firewall.py

#!/usr/bin/python

from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import Intf
from mininet.log import setLogLevel, info
from mininet.node import Controller, OVSKernelSwitch, RemoteController
@shreyakupadhyay
shreyakupadhyay / ViewController.swift
Last active February 28, 2019 10:32
Implement an ImageView Programmatically in Swift with Synchronous fetching
import UIKit
class ViewController: UIViewController {
var imageView: UIImageView!
let urlImageView = "https://scontent.fblr1-4.fna.fbcdn.net/v/t1.0-9/41680104_2150992674919611_3587931360280444928_n.jpg?_nc_cat=110&_nc_ht=scontent.fblr1-4.fna&oh=0ade5c5fe8c8b5f476fa8336b25fc72f&oe=5CE5D475"
override func viewDidLoad() {
super.viewDidLoad()
addImagesToView()
@shreyakupadhyay
shreyakupadhyay / Jenkinsfile
Created March 12, 2019 07:10
Run multiple containers using Jenkins with declarative pipeline syntax
pipeline {
agent none
stages {
stage('unit-testing') {
agent {
docker { image 'node:8.15.1-jessie' }
}
steps {
sh 'node -v'
}
export const CustomText = styled.Text`
font-size: ${props => props.fontSize}px;
color: ${props => props.fontColor};
letter-spacing: ${props => props.letterSpacing};
font-style: ${props => props.fontStyle};
font-weight: ${props => props.fontWeight};
font-family: ${props => props.fontFamily};
line-height: ${props => props.lineHeight};
`;
CustomText.defaultProps = {
const widthPercentageToDP = widthPercent => {
const screenWidth = Dimensions.get('window').width;
const elemWidth = parseFloat(widthPercent);
return PixelRatio.roundToNearestPixel(screenWidth * elemWidth / 100);
};
const heightPercentageToDP = heightPercent => {
const screenHeight = Dimensions.get('window').height;
const elemHeight = parseFloat(heightPercent);
return PixelRatio.roundToNearestPixel(screenHeight * elemHeight / 100);
};
import axios from 'axios';
import { USER_NAME, PASSWORD, REST_END_POINT } from './ApiConstants';
function baseAxios(options) {
const defaultHeaders = {
'Content-Type': 'application/json',
'Accept-Language': options.language ? options.language : 'en',
'lang': options.lang ? options.lang : 'en',
username: USER_NAME,
password: PASSWORD,