Skip to content

Instantly share code, notes, and snippets.

View franz101's full-sized avatar
🎯
Focusing

franz101 franz101

🎯
Focusing
View GitHub Profile
@qexat
qexat / __main__.py
Last active March 12, 2024 14:07
Python implementation of Solution 3 from Let's Get Rusty's "Improve your Rust APIs with the type state pattern" video
"""
PoC of an equivalent Python implementation of the third solution borrowed from the following video:
<https://www.youtube.com/watch?v=_ccDqRTx-JU>
Important note: Python static type checkers are independent from the interpreter, and type checking failing
does not prevent from running code. Considering that, the following code does NOT perform runtime checks for
safety. `add_password()` is still technically accessible, even through a `PasswordManager` object in a locked
state (i.e. `PasswordManager[Literal[True]]`).
The program also requires the following dependencies:
@karmacoma-eth
karmacoma-eth / AdversarialRoyalties.sol
Created February 15, 2022 02:26
What if a contract returns different data when viewed off-chain vs during a transaction?
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
contract AdversarialRoyalties {
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
function supportsInterface(bytes4 interfaceID) external pure returns (bool) {
return interfaceID == _INTERFACE_ID_ERC2981;
}
@JoranHonig
JoranHonig / AnnotatedToken.sol
Last active March 21, 2022 14:54
An annotated erc20 token
pragma solidity ^0.6.0;
///#invariant unchecked_sum(_balances) == _totalSupply;
///#if_succeeds unchecked_sum(_balances) == old(unchecked_sum(_balances)) || msg.sig == bytes4(0x00000000);
contract AnnotatedToken {
uint256 private _totalSupply;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
constructor() public {
@dabit3
dabit3 / SingleTableAppSync.md
Last active February 24, 2023 20:05
GraphQL Single Table Design with DynamoDB and AWS AppSync

GraphQL

GraphQL Schema

type Customer {
  id: ID!
  email: String!
}
@polyrand
polyrand / parse_sql_return.py
Last active September 21, 2024 10:34
Decorator to parse the results of a raw sqlalchemy query to a Pydantic model.
import inspect
from functools import partial, wraps
from typing import Union
from app import schemas
from app.db import database
from pydantic.main import ModelMetaclass
from shortuuid import uuid
# The following 2 functions parse raw results from the SQL queries
@deepaksood619
deepaksood619 / jupyterlab-deployment.yaml
Created April 28, 2020 21:26
Jupyterlab standalone deployment in Kubernetes cluster
apiVersion: apps/v1
kind: Deployment
metadata:
name: jupyterlab
namespace: jlab
labels:
name: jupyterlab
spec:
replicas: 1
selector:
@FlorisCalkoen
FlorisCalkoen / es_rnn_colab_nb_example.ipynb
Last active October 7, 2020 15:03
es_rnn_colab_nb_example.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@korakot
korakot / sheet_df.py
Last active March 29, 2024 23:33
Save dataframe to Google Sheet from Colab
# authenticate
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials as GC
gc = gspread.authorize(GC.get_application_default())
# create, and save df
from gspread_dataframe import set_with_dataframe
title = 'New Sheet'
gc.create(title) # if not exist
# https://hakibenita.com/fast-load-data-python-postgresql
from typing import Iterator, Dict, Any, Optional
from urllib.parse import urlencode
import datetime
#------------------------ Profile
import time
@parthdesai93
parthdesai93 / aws_es_connector.js
Last active April 8, 2021 06:18
http-aws-es compatible with new Elasticsearch client.
/* requires AWS creds to be updated.
* if they aren't, update using AWS.config.update() method before instatiing the client.
*
* import this module where you instantiate the client, and simply pass this module as the connection class.
*
* eg:
* const client = new Client({
* node,
* Connection: AwsConnector
* });