Skip to content

Instantly share code, notes, and snippets.

@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 / app-session.ts
Last active December 8, 2022 03:00
Custom session storage for a Shopify app in SQL using Prisma
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 March 7, 2019 20:03
Experiments with DynamoDB and Connection HTTP headers
import json
import os
import time
import uuid
import boto3
def set_connection_header(request, operation_name, **kwargs):
# request.headers['Connection'] = 'keep-alive'
@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.
"""
@milancermak
milancermak / classMethodIntrospection.swift
Created December 21, 2015 16:04
A way how to introspect methods in Swift at runtime
var methodCount: UInt32 = 0
let methods = class_copyMethodList(anInstance.dynamicType, &methodCount) // replace anInstace
for i in 0..<Int(methodCount) {
NSLog("method: \(NSStringFromSelector(method_getName(methods[i])))")
}
@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);