Skip to content

Instantly share code, notes, and snippets.

@milancermak
milancermak / pow10.cairo
Created July 29, 2022 21:04
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 July 26, 2022 14:29
shared external funcs in 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
name: Cairo static analysis
on:
push:
branches:
- master
pull_request:
jobs:
test:
@milancermak
milancermak / README.md
Last active February 24, 2022 21:00
keccak256 of uint256 in Cairo

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 October 28, 2021 10:40
Calculate minimal rent exemption balance for a Solana account
"""
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 / gist:e0b959a5195d28133a1f
Created December 4, 2014 11:58
Drawing a dashed line on GoogleMaps for iOS
- (void)drawDashedLineOnMapBetweenOrigin:(CLLocation *)originLocation destination:(CLLocation *)destinationLocation {
[self.mapView clear];
CGFloat distance = [originLocation distanceFromLocation:destinationLocation];
if (distance < kMinimalDistance) return;
// works for segmentLength 22 at zoom level 16; to have different length,
// calculate the new lengthFactor as 1/(24^2 * newLength)
CGFloat lengthFactor = 2.7093020352450285e-09;
CGFloat zoomFactor = pow(2, self.mapView.camera.zoom + 8);
@milancermak
milancermak / buildspec_container.yml
Created February 15, 2019 20:03
CodePipeline + Fargate
---
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 January 30, 2019 13:34
Set custom request timeout for AWSLambdaInovker
// 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 June 14, 2018 15:38
Streaming upload of a file directly to S3 in AWS Lambda
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'
@milancermak
milancermak / gatekeeper.py
Created April 13, 2018 10:09
Gatekeeper loop
class NotReadyError(Exception):
"""
Custom exception signaling to the Step Function
that it cannot move to the next state. Instead,
the Retry block is triggered, pausing the process.
You can pass details about the progress as a
string when initializing it. It will be shown
in the SF console.
"""