Skip to content

Instantly share code, notes, and snippets.

View shmidt's full-sized avatar

Dima Shmidt shmidt

View GitHub Profile
@mecid
mecid / ViewModelComposition.swift
Last active September 12, 2018 19:45
Mastering MVVM
import Bond
import ReactiveKit
class UserProfileViewModel {
let refreshing = Observable<Bool>(false)
let username = Observable<String>("")
let photos = Observable<[Photos]>([])
private let userViewModel: UserViewModel
private let photosViewModel: PhotosViewModel
Сброс позволяет откатиться на определённую версию в истории изменений Git. Всего есть три вида сброса:
git reset --hard {{some-commit-hash}} — вернуться на определённый коммит в истории. Все изменения, сделанные после этого коммита пропадут.
git reset {{some-commit-hash}} — вернуться на определённый коммит в истории. Все изменения, сделанные после этого коммита, получат состояние «Not staged for commit». Чтобы вернуть их обратно, нужно использовать команды git add и git commit.
git reset --soft {{some-commit-hash}} — вернуться на определённый коммит в истории. Все изменения, сделанные после этого коммита, получат состояние «Staged for commit». Чтобы вернуть их обратно, нужно использовать команду git commit.
Поналачу эта информация может показаться бесполезной, однако, когда вы начнёте работать с разными версиями файлов, она вам очень пригодится. Например, я для себя выделил вот такие сценарии использования этих команд:
1. Install oh-my-zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
2. Clone necessary plugins.
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
3. Add plugins to ~/.zshrc as
plugins = ( [plugins...] zsh-autosuggestions zsh-history-substring-search zsh-syntax-highlighting)
@AdrianFerreyra
AdrianFerreyra / binaryStringsSum.swift
Created November 3, 2017 13:32
Sum of two binaries, represented through strings.
import Foundation
func sum(_ lhs: String,_ rhs: String, carry: Int = 0) -> String {
guard let lhsLast = lhs.last else {
if rhs.count > 0 {
return rhs
} else {
return carry == 1 ? "1" : ""
@scottrhoyt
scottrhoyt / HeapsAlgorithm.swift
Created September 20, 2017 00:57
Heap's Algorithm for permutations in Swift
// https://en.wikipedia.org/wiki/Heap%27s_algorithm
import Foundation
/**
Generates all possible permutations of `data` using Heap's Algorithm
- parameters:
- data: The data to permute
- output: A closure called with each permutation of the data
@sebcode
sebcode / openTermCommand.js
Created March 12, 2017 14:38
JXA: Programmatically open a new iTerm tab with a specified command
#!/usr/bin/osascript -l JavaScript
// Open a new iTerm tab with a specified command.
// Usage example: ./openTermCommand.js '/usr/local/bin/vim /tmp/test.txt'
function run(argv) {
const iTerm = Application('iTerm')
iTerm.includeStandardAdditions = true
iTerm.activate()
@yostane
yostane / dispatch7.swift
Last active August 14, 2018 22:25
Handling calcellation of a dispatch work item is ugly
//create the dispatch work item
var dwi2:DispatchWorkItem?
dwi2 = DispatchWorkItem {
for i in 1...5 {
print("\(dwi2?.isCancelled)")
if (dwi2?.isCancelled)!{
break
}
sleep(1)
print("DispatchWorkItem 2: \(i)")
@scottrigby
scottrigby / plistDiff
Created January 7, 2017 22:15
Shows CLI diff between two plist files
#!/bin/bash
## @file
## Shows CLI diff between two plist files.
##
## Normally, Mac plist files are binary, so diffs do not display. However,
## there are cases where seeing diffs is important. For example, when tracking
## changes via Mackup's git storage option.
##
## Note this option allows seeing plist diffs without fully installing Xcode
@floscr
floscr / open-dropped-files-in-nvim.js
Last active April 3, 2018 18:09
Open dropped files in NVIM in a new TMUX window
function run (input, parameters) {
const iTerm = Application('iTerm2')
iTerm.activate()
const windows = iTerm.windows()
var window = iTerm.currentWindow()
var tab = window.currentTab()
var session = tab.currentSession()
@mayoff
mayoff / NSBezierPath-CGPath.swift
Last active September 20, 2022 11:00 — forked from juliensagot/NSBezierPath+cgPath.swift
Convert NSBezierPath to CGPath (Swift 3.0 / Xcode 8b4 syntax)
import AppKit
public extension NSBezierPath {
public var CGPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)
switch type {