Skip to content

Instantly share code, notes, and snippets.

View samsonjs's full-sized avatar

Sami Samhuri samsonjs

View GitHub Profile
@samsonjs
samsonjs / Example.swift
Last active February 10, 2023 08:45
Tiny OSLog initializer that accepts types instead of strings
// Usage
import OSLog
private let log = Logger.forType(SheepFootPacker.self) // category is the package/module name
class SheepFootPacker {
func squishThings() {
log.debug("squishing")
}
@samsonjs
samsonjs / Sparkle.swift
Created December 20, 2022 16:16 — forked from UnderscoreDavidSmith/Sparkle.swift
Sparkle Effect in SwiftUI
@available(iOS 15.0, *)
struct TwinkleView:View {
private func position(in proxy: GeometryProxy, sparkle:Sparkle) -> CGPoint {
let radius = min(proxy.size.width, proxy.size.height) / 2.0
let drawnRadius = (radius - 5) * sparkle.position.x
let angle = Double.pi * 2.0 * sparkle.position.y
let x = proxy.size.width * 0.5 + drawnRadius * cos(angle)
let y = proxy.size.height * 0.5 + drawnRadius * sin(angle)
@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/python@3.10/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%'