Skip to content

Instantly share code, notes, and snippets.

View Lessica's full-sized avatar

i_82 Lessica

View GitHub Profile
@Lessica
Lessica / expects_json.py
Created July 12, 2021 18:20
Validate JSON request data
def expects_json(obj: dict, schema: tuple):
# or use library `flask-expects-json`
_type = type(obj)
if _type != dict:
raise werkzeug.exceptions.BadRequest(f"wrong type of root object, except dict, got {str(_type.__name__)}")
_keys = schema
for _key in _keys:
assert len(_key) >= 2
if _key[0] not in obj:
if len(_key) >= 3 and _key[2] is False:
@Lessica
Lessica / ssn_mappings.json
Created July 10, 2021 05:39
Prefix List for Social Security Numbers USA
{
"AK": {
"ssn_parts": [
"574"
],
"ssn_prefixes": [
"574"
],
"ssn_sql_parts": [
"LIKE '574%'"
@Lessica
Lessica / XcodeRegexReplacementCollection.md
Last active May 22, 2021 07:36
Regular expressions to find inconsistencies in .strings

Find All Inconsistencies

(title|ibShadowedToolTip|headerToolTip|placeholderString|label|paletteLabel) = (")(.+?)\2((.|\n)+?)\2\3\2;\n
(")(.*?)\1 = \1\2\1;

Fill Base Localization

@Lessica
Lessica / TemplateOutlineView.swift
Created April 29, 2021 12:51
An attempt to re-draw 'focus ring' of NSTableView and NSOutlineView.
//
// TemplateOutlineView.swift
// JSTColorPicker
//
// Created by Rachel on 4/16/21.
// Copyright © 2021 JST. All rights reserved.
//
import Cocoa
@Lessica
Lessica / CheckboxHeaderCell.swift
Last active November 23, 2024 06:07
A Checkbox Cell in NSTableView Column Header
//
// CheckboxHeaderCell.swift
//
// Created by Rachel on 2021/4/26.
// Original: https://stackoverflow.com/questions/11961869/checkbox-in-nstableview-column-header
//
import Cocoa
class CheckboxCell: NSButtonCell {
@Lessica
Lessica / MyStackView.swift
Created April 17, 2021 16:30
Make toggleSidebar(_:) available again while firstResponder locates inside nested NSSplitView
import Cocoa
class MyStackView: NSStackView {
override func responds(to aSelector: Selector!) -> Bool {
if aSelector == #selector(NSSplitViewController.toggleSidebar(_:)) {
return false
}
return super.responds(to: aSelector)
}
@Lessica
Lessica / MutexLock.swift
Created April 17, 2021 13:42
MutexLock: pthread_mutex_t wrapper in Swift
import Foundation
final class MutexLock {
private var mutex: pthread_mutex_t = {
var mutex = pthread_mutex_t()
pthread_mutex_init(&mutex, nil)
return mutex
}()
func tryLock() -> Bool {
@Lessica
Lessica / ReadWriteLock.swift
Last active April 17, 2021 13:42
ReadWriteLock: pthread_rwlock_t wrapper in Swift
import Foundation
final class ReadWriteLock {
private var rwlock: pthread_rwlock_t = {
var rwlock = pthread_rwlock_t()
pthread_rwlock_init(&rwlock, nil)
return rwlock
}()
func writeLock() {
@Lessica
Lessica / EventGenerator.swift
Created April 26, 2020 15:05 — forked from zwaldowski/EventGenerator.swift
UIKit Touch Synthesis (Hacks! Hacks hacks! Hacks!)
import UIKit
import ObjectiveC.runtime
// MARK: - IOKit
@objc private protocol IOHIDEvent: NSObjectProtocol {}
private struct IOHIDDigitizerEventMask: OptionSet {
let rawValue: UInt32
init(rawValue: UInt32) { self.rawValue = rawValue }
@Lessica
Lessica / keybase.md
Last active November 25, 2022 06:33

Keybase proof

I hereby claim:

  • I am lessica on github.
  • I am i_82 (https://keybase.io/i_82) on keybase.
  • I have a public key ASCy06m3w8FXUbMqOsPF9bMWnqKvgwv8OBhSQ2twF_YmvAo

To claim this, I am signing this object: