Skip to content

Instantly share code, notes, and snippets.

View nderkach's full-sized avatar
✏️

Nikolay Derkach nderkach

✏️
View GitHub Profile
@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 April 18, 2023 21:36
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
@nderkach
nderkach / recognizer.py
Last active January 29, 2020 12:46
Facebook photo upload and photo tagging
#!/usr/bin/env python
import requests
import re
import urllib.parse
import sys, os
import json
from requests_toolbelt import MultipartEncoder
BASE_URL = 'https://mbasic.facebook.com'
@nderkach
nderkach / sorted_bit_array_num_ones.swift
Last active September 28, 2019 17:18
Given a sorted bit array (values of either 0 or 1), determine the number of 1’s in the array.
//Given a sorted bit array (values of either 0 or 1), determine the number of 1’s in the array.
//
//Perform this in O(log(N)) time complexity.
//
//Input: [0,0,0,1,1,1,1,1,1,1,1]
//
//Output: 8
func numOnes(_ arr: [Int]) -> Int {
@nderkach
nderkach / bit_array_sort.swift
Created September 28, 2019 16:35
Sort a Bit Array
# Sort a Bit Array
func bitSort(_ arr: inout [Int]) {
var zerosCount = arr.filter { $0 == 0 }.count
var idx = 0
while idx < arr.count {
arr[idx] = zerosCount > 0 ? 0 : 1
zerosCount -= 1
idx += 1
@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'
UIWindow *window = [[UIWindow alloc] initWithFrame:rootWindow.bounds];
window.hidden = NO;
window.windowLevel = UIWindowLevel_Background;
window.opaque = YES;
window.backgroundColor = UIColor.ows_materialBlueColor;
ScreenLockViewController *viewController = [ScreenLockViewController new];
viewController.delegate = self;
window.rootViewController = viewController;
### Keybase proof
I hereby claim:
* I am nderkach on github.
* I am nderkach (https://keybase.io/nderkach) on keybase.
* I have a public key ASDzaBmzYWD5ZUcgOm4QY55kAjO3rA8NLqic3-KvhsHBzgo
To claim this, I am signing this object:
# def consecutive(arr):
# arr = sorted(arr)
# max_so_far_start = 0
# max_so_far_end = 1
# max_range = (0, 1)
# cur_i = 1
# while cur_i <= len(arr):
# if cur_i != len(arr) and arr[cur_i] == arr[cur_i-1]+1:
Sales Path
The car manufacturer Honda holds their distribution system in the form of a tree (not necessarily binary). The root is the company itself, and every node in the tree represents a car distributor that receives cars from the parent node and ships them to its children nodes. The leaf nodes are car dealerships that sell cars direct to consumers. In addition, every node holds an integer that is the cost of shipping a car to it.
Take for example the tree below:
https://www.pramp.com/img/content/img_01.png
A path from Honda’s factory to a car dealership, which is a path from the root to a leaf in the tree, is called a Sales Path. The cost of a Sales Path is the sum of the costs for every node in the path. For example, in the tree above one Sales Path is 0→3→0→10, and its cost is 13 (0+3+0+10).