Skip to content

Instantly share code, notes, and snippets.

View StefKors's full-sized avatar
📟

Stef Kors StefKors

📟
View GitHub Profile
@chriseidhof
chriseidhof / boilerplate.swift
Last active January 3, 2024 05:54
QuickMacApp
// 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))
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@sunshinejr
sunshinejr / Debounced.swift
Last active September 20, 2021 09:47
Swift Property wrapper for debouncing values
@propertyWrapper
public final class Debounced<T: Hashable>: BindingConvertible {
public let delay: Double
private var _value: T
private var timer: Timer? = nil
public var wrappedValue: T {
get {
return _value
@pseudosavant
pseudosavant / jSugar.js
Last active March 1, 2024 04:48
Utility function that adds in some jQuery-like syntactic sugar
// jQuery-like syntactic sugar. Only queries for one element. Does not loop over multiple like jQuery
function $(query) {
if (typeof query === 'undefined') throw 'No query provided to $';
var el;
if (typeof query.nodeType === 'string') {
el = query;
} else if (typeof query === 'string' && query[0] === '<') {
const container = document.createElement('div');
container.innerHTML = query;
@Gozala
Gozala / Readme.md
Last active June 8, 2023 07:31
Range hilighting code using getClientRects API

Highlight Selection Ranges

Code here takes a DOM Selection Range instance and creates a highlighting for it by using getClientRects. Approach was inspired by marks although here function attempts to find nearest positioned parent element to the commonAncestorContainer and draw all the highilighting rectangles there, this avoids issues with an overflowing content.

Issues

  • Approach ignores z-index which isn't great as some element might be overlaying the selection in which case it should not appear, but it does if we use high z-index value. If we use low z-index value then some elements (possibly ones containing selection) might end up overlaying selection itself.
  • Rendered selections are scattered all o
@JoshuaSullivan
JoshuaSullivan / ColorCubeHelper-swift2.swift
Last active April 17, 2024 10:48
Here are the Swift 2.3 and Swift 3.0 versions of the ColorCubeHelper class.
//
// ColorCubeHelper.swift
//
// Created by Joshua Sullivan on 10/01/16.
// Copyright © 2016 Joshua Sullivan. All rights reserved.
//
import UIKit
import Accelerate
@chilts
chilts / alexa.js
Created October 30, 2013 09:27
Getting the Alexa top 1 million sites directly from the server, unzipping it, parsing the csv and getting each line as an array.
var request = require('request');
var unzip = require('unzip');
var csv2 = require('csv2');
request.get('http://s3.amazonaws.com/alexa-static/top-1m.csv.zip')
.pipe(unzip.Parse())
.on('entry', function (entry) {
entry.pipe(csv2()).on('data', console.log);
})
;