Skip to content

Instantly share code, notes, and snippets.

View vsaraph's full-sized avatar
🌴
On vacation

Vikram Saraph vsaraph

🌴
On vacation
View GitHub Profile
@vsaraph
vsaraph / simple_pubsub.py
Created April 25, 2021 20:33
really really simple pub/sub in python
class Publisher:
def __init__(self):
self.subscribers = []
def publish(self, message):
print("publishing message: {msg}".format(msg=message))
for subscriber in self.subscribers:
subscriber.onReceive(message)
def addSubscriber(self, subscriber):
@vsaraph
vsaraph / z3_s3_failure.py
Created April 5, 2021 21:45
Failed attempt at getting Z3 to spit out the symmetric group of degree 3
from z3 import *
# create sort
group = DeclareSort('G')
# create function symbols
iden = Function('e', group)
mult = Function('m', group, group, group)
inv = Function('i', group, group)
@vsaraph
vsaraph / decorator_test.py
Last active April 5, 2021 21:46
Python decorator that executes a function n times
def run_n_times(n):
def identity(func):
def wrapped(*args, **kwargs):
for i in range(n):
response = func(*args, **kwargs)
return response
return wrapped
return identity
@run_n_times(10)
@vsaraph
vsaraph / get_bearer_token.py
Created June 30, 2019 01:38
Generate new Twitter OAuth bearer token and use the token to fetch latest tweet from a given account
import requests
import base64
# encode consumer API key and secret key
key = input("key: ")
secret = input("secret: ")
encoded = base64.b64encode((key + ":" + secret).encode()).decode()
# construct payload
endpoint = "https://api.twitter.com/oauth2/token"
@vsaraph
vsaraph / stack.sol
Created February 28, 2019 19:36
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=false&gist=
pragma solidity ^0.5.1;
contract Stack {
int256[] stack;
function push(int256 data) public {
stack.push(data);
}
function pop() public returns (int256 data) {