Skip to content

Instantly share code, notes, and snippets.

@sisyphusSmiling
sisyphusSmiling / CadenceRandomConsumer.sol
Last active April 19, 2024 15:21
Prototype of Solidity contract implementing commit-reveal in an abstract contract with Flow's protocol-native randomness in EVM
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
abstract contract CadenceRandomConsumer {
struct Request {
uint64 flowHeight;
uint256 evmHeight;
@sisyphusSmiling
sisyphusSmiling / kmp_search.cdc
Created March 16, 2024 19:59
Knuth-Morris-Pratt Search Algorithm
/// Computes the longest proper prefix which is suffix (LPS) array
///
access(all) fun computeLPSArray(w: String, m: Int): [Int] {
var len: Int = 0
let lps: [Int] = [0]
var i: Int = 1
while i < m {
if w.length > i && w[i] == w[len] {
len = len + 1
@sisyphusSmiling
sisyphusSmiling / hf_twitter_sentiment_zapier_code.py
Created May 26, 2023 21:32
Analyzes tweet content sentiment using named model, providing sentiment label and score
import requests
import time
# Add the model ID and your Hugging Face Token
HF_TOKEN = "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"
# MODEL = "cardiffnlp/twitter-roberta-base-sentiment-latest"
SENTIMENT_MODEL = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
# Create the API request
API_BASE = "https://api-inference.huggingface.co/models/"
SENTIMENT_API_URL = API_BASE + SENTIMENT_MODEL
@sisyphusSmiling
sisyphusSmiling / ScopedProvider.cdc
Last active January 20, 2023 16:36
Quick resource implementation defining a wrapped Provider Capability & withdrawal Limit, the wrapping resource itself implementing the FungibleToken.Provider standard.
import FungibleToken from 0xFUNGIBLETOKEN
/// Quick resource implementation defining a wrapped Provider Capability
/// with a withdrawal limit, the wrapping resource itself implementing
/// the FungibleToken.Provider standard.
///
pub contract ScopedFungibleToken {
pub let ScopedProviderStoragePath: StoragePath
pub let ScopedProviderPrivatePath: PrivatePath