Skip to content

Instantly share code, notes, and snippets.

View pow10.cairo
func pow10(i) -> (res):
let (p) = get_label_location(data)
return ([p + i])
data:
dw 10 ** 0
dw 10 ** 1
dw 10 ** 2
dw 10 ** 3
dw 10 ** 4
@milancermak
milancermak / contract.cairo
Last active Jul 26, 2022
shared external funcs in cairo
View contract.cairo
%lang starknet
from openzeppelin.access.ownable import Ownable
# this import brings public function from ownable_external.cairo
# into this contract; the OWNABLE is just a placeholder, because
# something has to be imported, Cairo doesn't support
# `from foo import *` nor `import foo`
from contracts.ownable_external import OWNABLE
View static_analysis.yml
name: Cairo static analysis
on:
push:
branches:
- master
pull_request:
jobs:
test:
@milancermak
milancermak / README.md
Last active Feb 24, 2022
keccak256 of uint256 in Cairo
View README.md

This gist contains the following Solidity code translated to Cairo:

uint256 x = 20
uint256 out = uint256(keccak256(abi.encode(x)))

It uses the keccak256 implementation from starknet-l2-storage-verifier lib. The function deals with all the peculiarities of the necessary conversion (endianness, splitting of Uint256 to four 64-bit words and back again). There's also two helper python function to illustrate how to pass arguments in and how to deal with the result.

@milancermak
milancermak / calc_rent_exemption.py
Last active Oct 28, 2021
Calculate minimal rent exemption balance for a Solana account
View calc_rent_exemption.py
"""
A simple cmd line script to calculate the minimal rent exemption balance
of a Solana account.
Usage:
python calc_rent_exemption.py ACCONUT_ADDRESS
"""
@milancermak
milancermak / app-session.ts
Last active Jun 7, 2022
Custom session storage for a Shopify app in SQL using Prisma
View app-session.ts
import { PrismaClient } from '@prisma/client'
import Shopify from '@shopify/shopify-api'
import { Session } from '@shopify/shopify-api/dist/auth/session';
const prisma = new PrismaClient({ log: ['info', 'warn', 'error'] })
async function storeCallback(session: Session): Promise<boolean> {
const payload: { [key: string]: any } = { ...session }
return prisma.appSession.upsert({
create: { id: session.id, payload: payload },
@milancermak
milancermak / ddbwriter_main.py
Created Mar 7, 2019
Experiments with DynamoDB and Connection HTTP headers
View ddbwriter_main.py
import json
import os
import time
import uuid
import boto3
def set_connection_header(request, operation_name, **kwargs):
# request.headers['Connection'] = 'keep-alive'
View buildspec_container.yml
---
version: 0.2
phases:
pre_build:
commands:
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- COMMIT_HASH="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)"
- IMAGE_TAG="${COMMIT_HASH:=latest}"
- printenv
@milancermak
milancermak / timeout.swift
Created Jan 30, 2019
Set custom request timeout for AWSLambdaInovker
View timeout.swift
// my swift is a little bit rusty, hope this works
let configuration = AWSServiceManager.defaultServiceManager().defaultServiceConfiguration.copy();
configuration.timeoutIntervalForRequest = 90;
AWSLambdaInvoker.register(with: configuration!, forKey: "USWest2LambdaInvoker")
let lambdaInvoker = AWSLambdaInvoker(forKey: "USWest2LambdaInvoker")
// lambdaInvoker.invokeFunction ...
@milancermak
milancermak / s3_streaming_upload.py
Created Jun 14, 2018
Streaming upload of a file directly to S3 in AWS Lambda
View s3_streaming_upload.py
from botocore.vendored import requests
import boto3
def main(event, context):
s3 = boto3.resource('s3')
bucket = s3.Bucket('mybucket')
destination = bucket.Object('path/to/destination')
url = 'https://foobar.com'