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 / 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 / advanced-typescript-api-response.ts
Created December 29, 2022 05:52
Advanced level typescript implementation of API response handling
<!-- common payload: stats associated with data -->
type StatsRange = {
max: number, min: number
}
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value'
type PartialStats<
T extends Partial<{
[key in StatsKeys]: any;
@shreyakupadhyay
shreyakupadhyay / intermediate-typescript-api-response.ts
Created December 28, 2022 21:14
Intermediate level typescript implementation of API response handling
<!-- common payload: stats associated with data -->
type StatsRange = {
max: number, min: number
}
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value'
interface PartialStats<Type extends string|number|symbol, RangeType> {
stats?: Partial<Record<Type, RangeType>>
}
@shreyakupadhyay
shreyakupadhyay / beginner-typescript-api-response.ts
Last active December 28, 2022 09:13
Beginner level typescript implementation of API response handling
<!-- common payload: stats associated with data -->
type StatsRange = {
max: number, min: number
}
type StatsKeys = 'count' | 'aum' | 'priceusd' | 'value'
type PartialStats = {
stats?: {
[key in StatsKeys]?: StatsRange
@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 / 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 / version64.js
Last active April 5, 2021 13:27
Medium blog 0.64 version
// before inline default
import { BeforeFunction } from 'before-module';
const BeforeComponent = (props) => {
const view = BeforeFunction();
return <View>{view}</View>;
};
// after inline default
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,
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);
};
@shreyakupadhyay
shreyakupadhyay / ImageLazyLoad.js
Last active February 22, 2021 09:32
Lazy loading 5 images stacked on a single scrollview in React-Native
// lazy loading for three images
const ImageLazyLoad = React.forwardRef((props, ref) => {
const marker1 = React.useRef(null);
const marker2 = React.useRef(null);
const marker3 = React.useRef(null);
const [markerVisible, setmarkerVisible] = useState(0);
// marker Visible set with value -> 1,2,3
React.useImperativeHandle(ref, () => ({
onScroll: () => {