Skip to content

Instantly share code, notes, and snippets.

View ts95's full-sized avatar
🦉
🍰

Toni Sučić ts95

🦉
🍰
View GitHub Profile
@ts95
ts95 / Fibonacci Haskell
Last active December 27, 2015 02:59
Fibonacci Sequence, Haskell.
import Data.List
fib :: Int -> Int
fib 0 = 1
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
main :: IO ()
main = putStrLn $ intercalate ", " $ map show $ map fib [0..10]
@ts95
ts95 / ScreenshotDetector.swift
Last active February 14, 2022 19:49
OS X detect new screenshot event with Swift
import Foundation
typealias NewFileCallback = (fileURL: NSURL) -> Void
class ScreenshotDetector: NSObject, NSMetadataQueryDelegate {
let query = NSMetadataQuery()
var newFileCallback: NewFileCallback?
@ts95
ts95 / instagram-save.js
Last active February 2, 2021 20:54
A simple script that removes the overlays on Instagram-images so that you can save them by right-clicking on them.
// ==UserScript==
// @name InstagramSave
// @namespace https://instagram-save.tonisucic.com
// @version 1.2
// @description Enables you to save/copy images on Instagram.
// @author Toni S
// @match https://www.instagram.com/*
// @grant none
// ==/UserScript==
@ts95
ts95 / rollover_fees.py
Last active October 22, 2020 23:19
Script for calculating rollover fees (Kraken)
#!/usr/bin/env python3.6
"""Script for calculating rollover fees"""
import argparse
import requests
# One rollover for every 4 hours
ROLLOVER_RATE = 4
# 0.02% for most currency pairs
@ts95
ts95 / Model.swift
Created June 23, 2017 22:42
Model protocol for Firebase/Database
import Foundation
import FirebaseDatabase
enum ModelError: Error {
case invalidProperties
}
protocol Model {
init?(snapshot: FIRDataSnapshot)
@ts95
ts95 / Book.swift
Created June 23, 2017 22:49
An example of a book model that implements the Model protocol
import Foundation
import FirebaseDatabase
struct Book {
var id: String?
var isbn: String
var title: String
var authors: String
var year: String
var country: String
@ts95
ts95 / StoreNewBook.swift
Last active June 23, 2017 23:24
Example of storing a new book model instance in the Firebase database
let db = FIRDatabase.database()
let booksRef = db.reference(withPath: Endpoint.books.path)
var newBook = Book(
id: nil,
isbn: "95-0443-843-0",
title: "Do Androids Dream of Electric Sheep?",
authors: "Philip K. Dick",
year: "1968",
country: "United States",
@ts95
ts95 / FetchBook.swift
Created June 23, 2017 23:25
Example of fetching a book by its id and printing out the title of it
let db = FIRDatabase.database()
let bookRef = db.reference(withPath: Endpoint.book("-KnEUaDbm6-snUq_Ojzo").path)
bookRef.observeSingleEvent(of: .value, with: { snapshot in
guard let book = Book(snapshot: snapshot) else { return }
print(book.title)
})
@ts95
ts95 / Validatable.swift
Last active July 7, 2022 09:34
A Swift protocol for making a model validatable
import Foundation
protocol Rule {
associatedtype Option
var errorMessage: String { get }
init(_ option: Option, error: String)
func validate(for value: ValidatableType) -> Bool
import UIKit
protocol ReusableView: class {
static var defaultReuseIdentifier: String { get }
}
extension ReusableView where Self: UIView {
static var defaultReuseIdentifier: String {
return String(describing: self)