Skip to content

Instantly share code, notes, and snippets.

@igavrysh
igavrysh / CalculatorBrain.swift
Last active July 18, 2017 16:08
Stanford CS193p Home Assignment 1
import Foundation
func lift<A, B>(_ value: (A?, B?)) -> (A, B)? {
return value.0.flatMap { lhs in
value.1.flatMap { (lhs, $0) }
}
}
func lift<A, B, C>(_ value: (A?, B?, C?)) -> (A, B, C)? {
return value.0.flatMap { lhs in
@igavrysh
igavrysh / gist:a686a5d98e1239d05dbb8ab1800989dc
Created August 28, 2017 11:37 — forked from sgergely/gist:3793166
Midnight Commander Keyboard Shortcuts for Mac OSX
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
@igavrysh
igavrysh / NSObject+SMATimer.m
Last active September 11, 2017 15:13
Adds Timer tracking funcitonality to NSObject
#import <objc/runtime.h>
#import "SMAGlobal.h"
#import "CocoaLumberjack.h"
#import "NSObject+SMATimer.h"
#import "SMAMacros.h"
#import "SMABlockMacros.h"
var markup = document.documentElement.innerHTML;
var htmlEnDeCode = (function() {
var charToEntityRegex,
entityToCharRegex,
charToEntity,
entityToChar;
function resetCharacterEntities() {
charToEntity = {};
struct SwimmingWorkout {
var distance: Double
var time: Double
var stroke: Stroke
static var breaststrokeWorkouts: [SwimmingWorkout] = []
static var freestyleWorkouts: [SwimmingWorkout] = []
static var butterflyWorkouts: [SwimmingWorkout] = []
static var backstrokeWorkouts: [SwimmingWorkout] = []
@objc
public func turnOnButtonTouched() {
self.setViewControllers([self.pages[1]], direction: .forward, animated: true, completion: nil)
}
override func viewWillAppear(_ animated: Bool) {
// 1) тебе надо пройтись по каждому контроллеру из массива страниц (контрорллеров для страниц)
_ = self.pages
// 2) тебе надо в каждом контроллере достать его главный view
// 3) тебе надо у каждого view достать его subview, и так далее - но я решил максимум
def comb(array, k):
"""
Get all combinations of k elements from array
Arguments:
array -- an array of elements, source for combinations
k -- number of elements in combination
Return:
comb -- array of stored combinations
// Created by Ievgen Gavrysh on 7/30/18.
// http://github.com/igavrysh
//
// This gist is created to show down-to-basics way of handling
// Swift optionals.
//
// No syntax sugar is used and only common and basic Swift language structures
// are applied. That includes but not limited to generics and high order functions.
// I believe that starting learning Swift Optionals from this sample if far
// more correct and easier then with features Apple included into Swift in order to
@igavrysh
igavrysh / singlePointOfFailure.py
Last active August 9, 2018 02:14
singlePointOfFailure
import networkx as nx
import matplotlib.pyplot as plt
def draw_graph(adjList, log = False):
V = len(adjList)
# extract nodes from graph
nodes = set([i for i in range(V)])
if log: print("nodes: " + str(nodes))
#Set the default java using the below command.
#The above command would list all Java JDK installed on your system, like below.
sudo update-alternatives --config java