Skip to content

Instantly share code, notes, and snippets.

View nderkach's full-sized avatar
✏️

Nikolay Derkach nderkach

✏️
View GitHub Profile
@nderkach
nderkach / gist:f3155d0e41e53ed6beb3
Created November 30, 2015 14:17
iOS 8+ supported device strings (iPhone, iPad, iPod)
iPhone4,1
iPhone5,1
iPhone5,2
iPhone5,3
iPhone5,4
iPhone6,1
iPhone6,2
iPhone7,1
iPhone8,1
iPhone8,2
@nderkach
nderkach / test.py
Created December 10, 2016 22:24
MAC Access Authentication example
#!/usr/bin/env python
from binascii import b2a_base64
import hashlib
import hmac
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
@nderkach
nderkach / gist:b8f4fe57a7a09af7815cdeaf8d44adfe
Last active September 22, 2019 16:12
DevinantArt Private API (used by mobile app)
# get OAuth2 token
curl -H 'host:www.deviantart.com' -H 'User-Agent:DeviantArt/1.12 (iPhone; iOS 8.2; Scale/2.00)' -H 'Accept-Language:en;q=1' -H 'DA-SYNC-TOKEN:2fcf547f0e4ddcd8e8e45084b6dc0d2c' -H 'dA-minor-version:20160316' -H 'Accept:*/*' -H 'Content-Type:application/x-www-form-urlencoded' -H 'dA-session-id:b0618f6c2819e75b9d2b20b0e96c5802' -H 'Connection:keep-alive' -H 'Proxy-Connection:keep-alive' -H 'Content-Length:123' -H 'Accept-Encoding:gzip, deflate' -X POST 'https://www.deviantart.com/oauth2/token' --compressed --data-binary 'client_id=1701&client_secret=e6af3dc9712a1aad9efed05f16ceecf198aefcb5bab1531018e28034a3792e30&grant_type=client_credentials'
@nderkach
nderkach / uiimageviewmask.swift
Created June 16, 2017 17:36
iOS: set UIImage mask
let maskLayer = CALayer()
let maskImage = UIImage(named: "avatar-mask")?.cgImage
maskLayer.frame = CGRect(x: 0, y: 0, width: profileImageView.bounds.size.width, height: profileImageView.bounds.size.height)
maskLayer.contents = maskImage;
profileImageView.layer.mask = maskLayer
profileImageView.layer.masksToBounds = true
@nderkach
nderkach / reviews.txt
Last active November 26, 2017 10:15
Airbnb API reviews response
{
'reviews':[
{
'author':{
'first_name':'Maryann',
'has_profile_pic':True,
'id':40613795,
'picture_url':'https://a0.muscache.com/im/pictures/c77f54a1-c3d0-4742-93af-f2e53b8f5145.jpg?aki_policy=profile_x_medium',
'smart_name':'Maryann',
'thumbnail_url':'https://a0.muscache.com/im/pictures/c77f54a1-c3d0-4742-93af-f2e53b8f5145.jpg?aki_policy=profile_small'
@nderkach
nderkach / schema.py
Last active November 26, 2017 11:09
Graphene schema for Airbnb reviews
from graphene import ObjectType, String, Boolean, ID, Field, Int
class User(ObjectType):
first_name = String()
has_profile_pic = Boolean()
id = ID()
picture_url = String()
smart_name = String()
thumbnail_url = String()
from graphene import ObjectType, List
class Query(ObjectType):
reviews = List(Review, id=Int(required=True))
@nderkach
nderkach / json2obj.py
Created November 26, 2017 11:55
How to convert JSON data into a Python object
# stolen from https://stackoverflow.com/questions/6578986/how-to-convert-json-data-into-a-python-object/15882054#15882054
def _json_object_hook(d):
return namedtuple('X', d.keys())(*d.values())
def json2obj(data):
return json.loads(data, object_hook=_json_object_hook)
class Query(ObjectType):
reviews = List(Review, id=Int(required=True))
def resolve_reviews(self, args, context, info):
reviews = api_call(args.get("id"))["reviews"]
return json2obj(json.dumps(reviews))
@nderkach
nderkach / flask_graphql.py
Last active November 26, 2017 12:04
A simple Flask app serving GraphQL API
from flask import Flask
from schema import Query
from flask_graphql import GraphQLView
from graphene import Schema
import os
view_func = GraphQLView.as_view(
'graphql', schema=Schema(query=Query), graphiql=True)