Skip to content

Instantly share code, notes, and snippets.

View wojteklu's full-sized avatar
👋

Wojtek Lukaszuk wojteklu

👋
View GitHub Profile
// Run any SwiftUI view as a Mac app.
import Cocoa
import SwiftUI
NSApplication.shared.run {
VStack {
Text("Hello, World")
.padding()
.background(Capsule().fill(Color.blue))
@wojteklu
wojteklu / SaliencyDetector.h
Created March 15, 2018 21:07
Generating a saliency map with the spectral residual approach
//
// Copyright © 2018 wojteklu. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface SaliencyDetector: NSObject
-(CGRect)findMostProminentPartOfImage:(UIImage *)image;
-(UIImage *)selectMostProminentPartOfImage:(UIImage *)image;
public class Throttler {
private let queue: DispatchQueue = DispatchQueue.global(qos: .background)
private var job: DispatchWorkItem = DispatchWorkItem(block: {})
private var previousRun: Date = Date.distantPast
private var maxInterval: TimeInterval
public init(maxInterval: TimeInterval) {
self.maxInterval = maxInterval
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "2"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
@wojteklu
wojteklu / backtracking.swift
Created April 11, 2017 20:25
Solving sudoku using backtracking
class Board: CustomStringConvertible {
var values: [Int]
let kSize = 9 // number of rows and columns
init(_ string: String) {
values = string.characters.map { Int(String($0)) ?? 0 }
}
var empty: Int? {
return values.index(of: 0)
@wojteklu
wojteklu / board.swift
Created April 11, 2017 20:23
Solving sudoku using constraint propagation
class Board {
fileprivate let kSize = 9 // number of rows and columns
fileprivate var squares: [Square]
fileprivate var units: [[[Int]]] = []
fileprivate var peers: [[Int]] = []
init(_ string: String) {
squares = [Square](repeating: Square(0b111111111), count: kSize * kSize)
for index in 0..<(kSize * kSize) {
@wojteklu
wojteklu / bayes.go
Created February 28, 2017 20:58
Multinomial naive Bayes classifier
package bayes
// Classifier implements the Naive Bayes Classifier.
type Classifier struct {
classPerWordCount map[string]int
classPerDocument map[string]int
wordClassCount map[string]map[string]int
documentsCount int
}
@wojteklu
wojteklu / clean_code.md
Last active November 15, 2024 07:19
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@wojteklu
wojteklu / terminal_notification.md
Last active July 7, 2024 14:20
Show macOS notification when long running command finishes and your terminal is not in focus.

Add the following to your ~/.zshrc:

function notifyme {
  LAST_EXIT_CODE=$?
  CMD=$(fc -ln -1)
  osascript -e 'on run argv
  tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
 if frontApp is not "Terminal" then
@wojteklu
wojteklu / gitenv.md
Last active July 7, 2024 14:20
Perfect git environment on OS X

Perfect git environment on OS X

Global alias

Add the following to your ~/.bashrc:

alias g='git'

Branch auto-completion