Skip to content

Instantly share code, notes, and snippets.

View nderkach's full-sized avatar
✏️

Nikolay Derkach nderkach

✏️
View GitHub Profile
@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 / 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 / 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: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 / NSDateFormatter cheat sheet
Created October 7, 2015 04:40 — forked from romaonthego/NSDateFormatter cheat sheet
Date Formats for NSDateFormatter
a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
- (void)objectsDidLoad:(nullable NSError *)error {
[super objectsDidLoad:error];
__block PFGeoPoint *currentLocation = [PFUser currentUser][@"location"];
NSSortDescriptor *distanceDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"location" ascending:YES comparator:^NSComparisonResult(PFGeoPoint* obj1, PFGeoPoint* obj2) {
return [@([currentLocation distanceInMilesTo:obj1]) compare:@([currentLocation distanceInMilesTo:obj2])];
}];
[self setValue:[[self.objects sortedArrayUsingDescriptors:@[distanceDescriptor]] mutableCopy] forKey:@"_mutableObjects"];
@nderkach
nderkach / parse_nssortdescriptor
Last active October 16, 2015 10:19
Parse with NSSortDescriptor example
NSSortDescriptor *commonLikesDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"fblikes" ascending:YES comparator:^NSComparisonResult(NSArray* obj1, NSArray* obj2) {
NSMutableSet *intersection1 = [NSMutableSet setWithArray:user[@"fblikes"]];
[intersection1 intersectSet:[NSSet setWithArray:obj1]];
NSMutableSet *intersection2 = [NSMutableSet setWithArray:user[@"fblikes"]];
[intersection2 intersectSet:[NSSet setWithArray:obj2]];
return [@([intersection1 count]) compare:@([intersection2 count])];
}];
@nderkach
nderkach / octopress_github.md
Last active August 29, 2015 14:13
How to setup and configure an existing Octopress blog with github pages

Say, you have an existing octopress blog published on github pages, here is how to configure it:

git clone https://github.com/username/username.github.io.git
cd username.github.io.git
git checkout source
mkdir _deploy
cd _deploy
git init
git remote add -t master -f origin https://github.com/username/username.github.io.git
@nderkach
nderkach / ios_github_gif.md
Last active February 15, 2024 23:31
How to record iOS screen and share it on github

Record a screencast with QuickTime Player

  1. Connect an iOS defice with a cable
  2. In QuickTime Player: Option-Cmd-N (New Movie Recording) -> Select your device from the recording menu:

http://cl.ly/image/1w0y3Y0H2g2X/record.png

Install gifify

@nderkach
nderkach / read_mitmproxy_dumpfile.py
Last active March 23, 2025 19:19
Read a mitmproxy dump file and generate a curl command
#!/usr/bin/env python
#
# Simple script showing how to read a mitmproxy dump file
#
### UPD: this feature is now avaiable in mitmproxy: https://github.com/mitmproxy/mitmproxy/pull/619
from libmproxy import flow
import json, sys