Skip to content

Instantly share code, notes, and snippets.

View mykolaharmash's full-sized avatar

Mykola Harmash mykolaharmash

View GitHub Profile
@mykolaharmash
mykolaharmash / StateToggle.swift
Created October 27, 2020 15:17
@State and visibility toggle
import SwiftUI
struct CounterView: View {
@State var count = 0
var body: some View {
Text(String(count))
Button("+ 1", action: { count = count + 1 })
}
}
import SwiftUI
class Counter: ObservableObject {
@Published var count: Int
init(_ count: Int) {
self.count = count
}
func increment() {
import SwiftUI
class Counter: ObservableObject {
@Published var count: Int
init(_ count: Int) {
self.count = count
}
func increment() {
import SwiftUI
class Counter: ObservableObject {
@Published var count: Int
init(_ count: Int) {
self.count = count
}
func increment() {
@mykolaharmash
mykolaharmash / StateReferenceTypeFixed.swift
Created October 27, 2020 11:50
@State with reference type (fixed)
import SwiftUI
class Counter {
var count: Int
init(_ count: Int) {
self.count = count
}
func increment() {
@mykolaharmash
mykolaharmash / StateReferenceTypeBroken.swift
Last active October 27, 2020 11:49
@State with reference type (broken)
import SwiftUI
class Counter {
var count: Int
init(_ count: Int) {
self.count = count
}
func increment() {
import SwiftUI
struct Counter: View {
@State var count: Int = 0
init() {
print("Counter Created")
}
var body: some View {
@mykolaharmash
mykolaharmash / init.lua
Last active August 15, 2023 08:45
Hammerspoon Vim Navigation
-- put into ~/.hammerspoon
-- map Caps Lock key to Control in macOS settings (Keyboard -> Modifier Keys...)
-- Give all the accessability permissions in Hammerspoon preferences
-- NOTE: Changing "Key repeat rate" and "Delay until repeat" in macOS settings
-- require Hammerspoon restart to pick up those changes.
-- See: https://github.com/Hammerspoon/hammerspoon/issues/3264
local function pressFn(mods, key)
if key == nil then
key = mods
export class Maybe<T> {
value: T | null
constructor(value: T | null) {
this.value = value
}
static property<P>(value: P | undefined): Maybe<P> {
if (value === undefined) {
return new Maybe<P>(null)
@mykolaharmash
mykolaharmash / monad.js
Created December 4, 2019 14:11
basic monad example
function square (x) {
return [x * x, () => console.log(x * x)]
}
function feet (x) {
return [x * 3.28084, () => console.log(x * 3.28084)]
}
function compose (fn1, fn2) {
return (x) => fn2(fn1(x))