Skip to content

Instantly share code, notes, and snippets.

@milancermak
milancermak / app-session.ts
Last active May 13, 2021
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 / gist:e0b959a5195d28133a1f
Created Dec 4, 2014
Drawing a dashed line on GoogleMaps for iOS
View gist:e0b959a5195d28133a1f
- (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 / pre-commit.sh
Created Oct 7, 2012
Python pre-commit hook
View pre-commit.sh
#!/bin/sh
# make sure requirements.txt is up to date with every commit
# by comparing the output of pip freeze
pip freeze | diff requirements.txt - > /dev/null
if [ $? != 0 ]
then
echo "Missing python module dependencies in requirements.txt. Run 'pip freeze > requirements.txt' to update."
exit 1
fi
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 / 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'
@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'
View gatekeeper.py
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 / gist:3451509
Created Aug 24, 2012
Example of validating a recurring payment from Google Play using the Web server application OAuth 2.0 flow
View gist:3451509
import datetime
import httplib2
# to see in detail what's going on, uncomment
# httplib2.debuglevel = 4
from apiclient.discovery import build
from oauth2client.client import OAuth2Credentials, OAuth2WebServerFlow
if __name__ == "__main__":
@milancermak
milancermak / classMethodIntrospection.swift
Created Dec 21, 2015
A way how to introspect methods in Swift at runtime
View classMethodIntrospection.swift
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])))")
}