Skip to content

Instantly share code, notes, and snippets.

View shubhamwagh's full-sized avatar

Shubham Wagh shubhamwagh

View GitHub Profile
shubhamwagh /
Last active December 1, 2023 22:16
State Design Pattern Tutorial
  • State Design Pattern allows an object to change its behavior when its internal state changes.
  • It is a behavioral type design pattern.
  • It has State Interface which represents all behaviors (methods) the context will exhibit.
  • The Concrete States in the state design pattern are the implementations of the State Interface that define behaviors specific to each state.
  • It has Context Class that holds a reference to the current state and expose methods to clients.
  • Useful to manage states in the applications and swtich between them.
  • Easy to maintian since each state is a different class and state-specific behavior is encapsulated in its respective class.
  • New states can be easily added by writing an extra class for the new state.
  • E.g. States in a document, states in a game, or different modes in a GUI.
shubhamwagh /
Last active December 7, 2021 11:33
SSH Display forward
  • Make sure you have xauth installed. (See: xauth info or xauth list)
  • On the server your /etc/ssh/sshd_config file should have these lines:
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
  • Make sure on client side you have X server installed.
  • On the client side your ~/.ssh/config file should have these lines if not create new config file and add:
shubhamwagh /
Last active May 6, 2021 12:32

BitcoinMining explaination


  • Assume this is the hash of the lastest block (shortened to 30 characters): 00000000000001adf44c7d69767585
  • Following are the hashes of a few valid transactions waiting for inclusion (shortened).
  • And this the hash of one special transaction that you just crafted, which gives 10BTC (the current reward) to yourself:
shubhamwagh /
Created November 13, 2020 12:34
ROS PointClou2 to numpy conversion (this will avoid bit flip)
colours = np.array([
bytearray([rgb_field.offset + 2::msg.point_step]),
bytearray([rgb_field.offset + 1::msg.point_step]),
bytearray([rgb_field.offset + 0::msg.point_step])
shubhamwagh /
Created October 6, 2020 11:10 — forked from cablehead/
Iterate a 2d matrix using a spiral pattern
import unittest
import copy
from itertools import cycle
def row(matrix, n):
# returns row n of a 2d matrix
return matrix.pop(n)
shubhamwagh /
Created September 4, 2020 11:55
AWS gets size of the contents in your S3 bucket
#!/usr/bin/env bash
## If no bucket name is passed, prompt user to enter one from their account.
## Else, assign $1 to bucket_name.
get_bucket_name () {
if [[ $# -eq 0 ]]; then
echo "$buckets"
shubhamwagh /
Created September 17, 2019 17:46
AWS s3 bucket delete and upload
import boto3
session = boto3.Session(
s3 = session.resource('s3')
bucket = s3.Bucket('bucket-name')
s3.meta.client.upload_file(Filename='filename-with-path', Bucket='', Key='only-filename-in-the-bucket')
shubhamwagh /
Created September 11, 2019 15:34
Smooth contours in Opencv
shubhamwagh /
Last active December 1, 2023 22:23