Skip to content

Instantly share code, notes, and snippets.

View nderkach's full-sized avatar
✏️

Nikolay Derkach nderkach

✏️
View GitHub Profile
@nderkach
nderkach / find_missing_packages
Created September 19, 2014 17:36
Find missing python packages
#!/usr/bin/env python
import os
import importlib
for fn in os.listdir():
if fn.endswith(".py"):
with open(fn, 'r') as f:
for line in f:
if "import" in line:
#!/usr/bin/env python
import unittest
class Stack(list):
def push(self, item):
self.append(item)
def isEmpty(self):
return not self
def peek(self):
#!/usr/bin/python
import unittest
class Node(object):
def __init__(self, data, children=None):
self.children = []
self.right = None
self.data = data
#!/usr/bin/python
import itertools
from collections import defaultdict
from timeit import Timer
class Feature(object):
def __init__(self, name):
self.name = name
@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
- (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 / 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)
@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 / 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