Skip to content

Instantly share code, notes, and snippets.

@jeffypooo
jeffypooo / seriously.swift
Last active January 29, 2024 17:34
How to determine PresentationDetent type in SwiftUI (pre-iOS 16.4).
extension PresentationDetent {
/// Converts a `PresentationDetent` to an `ExpandableSheetDetent`
/// NOTE: Detents created using `.custom(_)` will fail to convert.
var expandableSheetDetent: ExpandableSheetDetent {
if self == .medium { return .medium }
if self == .large { return .large }
if let height = heightValue { return .height(height) }
if let fraction = fractionValue { return .fraction(fraction) }
let unknownType = type(of: self)
@mxcl
mxcl / detweet.swift
Last active August 16, 2024 15:38
Delete all tweets and favorites older than two months ago. Instructions in comment.
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@Edudjr
Edudjr / Luhn.swift
Last active February 15, 2024 20:33 — forked from cwagdev/Luhn.swift
Luhn Algorithm in Swift 4.1
func luhnCheck(_ number: String) -> Bool {
var sum = 0
let digitStrings = number.reversed().map { String($0) }
for tuple in digitStrings.enumerated() {
if let digit = Int(tuple.element) {
let odd = tuple.offset % 2 == 1
switch (odd, digit) {
case (true, 9):
@candostdagdeviren
candostdagdeviren / .swiftlint.yml
Last active September 15, 2024 19:51
Sample SwiftLint file to apply best practices
disabled_rules: # rule identifiers to exclude from running
- variable_name
- nesting
- function_parameter_count
opt_in_rules: # some rules are only opt-in
- control_statement
- empty_count
- trailing_newline
- colon
- comma
@zacwest
zacwest / ios-font-sizes.swift
Last active November 8, 2024 02:45
iOS default font sizes - also available on https://www.iosfontsizes.com
let styles: [UIFont.TextStyle] = [
// iOS 17
.extraLargeTitle, .extraLargeTitle2,
// iOS 11
.largeTitle,
// iOS 9
.title1, .title2, .title3, .callout,
// iOS 7
.headline, .subheadline, .body, .footnote, .caption1, .caption2,
]
@orta
orta / _SQL.sql
Last active November 8, 2016 12:12
Top 300 Pods by Application Integrations
SELECT pods.name, stats_metrics.download_total, stats_metrics.download_week, stats_metrics.app_total, stats_metrics.app_week FROM stats_metrics JOIN pods ON stats_metrics.pod_id = pods.id ORDER BY app_total DESC LIMIT 300;
@hlung
hlung / How to connect PS3 controller to a Mac or PC.md
Last active July 22, 2024 21:41
How to connect PS3 controller to a Mac or PC

How to connect PS3 controller to a Mac or PC

This is how you connect PS3 controller to Mac OSX, PC, etc. when previously connected to a PS3. You will need a Mini USB cable. Overcome your laziness, get up of your chair, and go get one!

A big misconception is that keep holding PS button will reset the controller's pairing. It DOES NOT! From my testings, the controller keeps paring with the last machine it was CONNECTED VIA A USB CABLE.

Here are the steps:

@jexchan
jexchan / multiple_ssh_setting.md
Created April 10, 2012 15:00
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"