Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
@samsonjs
samsonjs / inset.swift
Created December 12, 2022 05:05 — forked from erica/inset.swift
import Cocoa
public struct UIEdgeInsets {
public var top: CGFloat // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
public var left: CGFloat
public var bottom: CGFloat
@samsonjs
samsonjs / Logging.swift
Last active December 3, 2022 02:34
Simple logging helper for OSLog in Swift
import OSLog
extension Logger {
static let subsystem = Bundle.main.bundleIdentifier!
static func `for`(category: String) -> Logger {
Logger(subsystem: subsystem, category: category)
}
}
@samsonjs
samsonjs / BetterNotification.swift
Last active November 28, 2022 06:12
Slightly better type-safe notifications for Apple platforms
import Combine
import Foundation
public protocol BetterNotification {}
private extension BetterNotification {
static var notificationName: Notification.Name {
Notification.Name(rawValue: "BetterNotification:\(Self.self)")
}
}
@samsonjs
samsonjs / SimLink.swift
Last active November 23, 2022 07:28
Paul Samuel’s code for symlinking simulator directories to make them more accessible
@samsonjs
samsonjs / zlocal
Created September 21, 2022 05:13
zlocal from macOS
eval "$(/opt/homebrew/bin/brew shellenv)"
local_paths=(
/Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin
/opt/homebrew/Cellar/[email protected]/3.10.*/Frameworks/Python.framework/Versions/3.10/bin(N)
/opt/homebrew/opt/libpq/bin
)
for dir in $local_paths; do
if [[ -d "$dir" ]]; then
path=($dir $path)
@samsonjs
samsonjs / S3.php
Created August 7, 2022 20:30 — forked from marcoarment/S3.php
A simple PHP class to perform basic operations against Amazon S3 and compatible services.
<?php
/*
A simple PHP class to perform basic operations against Amazon S3 and compatible
services. Requires modern PHP (7+, probably) with curl, dom, and iconv modules.
Copyright 2022 Marco Arment. Released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
@samsonjs
samsonjs / postgres_queries_and_commands.sql
Created March 23, 2022 00:38 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@samsonjs
samsonjs / Database.fs
Last active February 18, 2022 22:25 — forked from praeclarum/Database.fs
An immutable database with reference entities, cascading deletes, undo buffers, serialization, and reactive variables
namespace Neural
type Id = System.String
type Id<'T> =
| Id of Id
override this.ToString () = match this with Id id -> id
type IEntity =
abstract References : Id seq with get
abstract DeleteReference : Id -> IEntity option
@samsonjs
samsonjs / mailbox-mbox.py
Created December 28, 2021 21:52
Python 3.9's mailbox.mbox class patched to properly handle body lines that start with "From " in multipart messages
class mbox(_mboxMMDF):
"""A classic mbox mailbox."""
_mangle_from_ = True
# All messages must end in a newline character, and
# _post_message_hooks outputs an empty line between messages.
_append_newline = True
def __init__(self, path, factory=None, create=True):