Skip to content

Instantly share code, notes, and snippets.

View iamtomcat's full-sized avatar

Tom Clark iamtomcat

View GitHub Profile
// Authoer: The SwiftUI Lab
// Full article: https://swiftui-lab.com/scrollview-pull-to-refresh/
import SwiftUI
struct RefreshableScrollView<Content: View>: View {
@State private var previousScrollOffset: CGFloat = 0
@State private var scrollOffset: CGFloat = 0
@State private var frozen: Bool = false
@State private var rotation: Angle = .degrees(0)
@yongjun21
yongjun21 / Promise.js
Last active June 28, 2022 11:56
Implement bluebird's Promise.map & Promise.filter with native Promise
Promise.map = function (iterable, mapper, options) {
options = options || {}
let concurrency = options.concurrency || Infinity
let index = 0
const results = []
const iterator = iterable[Symbol.iterator]()
const promises = []
while (concurrency-- > 0) {
@marians
marians / main.go
Created January 27, 2017 10:25
OAuth 2.0 authentication in a Golang CLI
package main
import (
"context"
"crypto/tls"
"fmt"
"log"
"net/http"
"net/url"
"time"
@SethCalkins
SethCalkins / LittleSnitch_Block_List.md
Last active January 5, 2023 05:17
Little Snitch Script to block Ad Servers

Here is a script to take the hosts from From http://pgl.yoyo.org/adservers/ and convert them to rules for Little Snitch.

It has options to grab the entire list or grab new entries past a certain date.

Just grab the output and copy/paste into Little Snitch.

The script is written to block access to any process, any port. You can also delete those lines and it will only block Mail. Or use the options to enter any process, port or protocol you want to block.

@nathanhillyer
nathanhillyer / .gitignore
Created May 12, 2016 16:26
Swift gitignore
#####
# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
#
# This is complicated:
#
# SOMETIMES you need to put this file in version control.
# Apple designed it poorly - if you use "custom executables", they are
# saved in this file.
# 99% of projects do NOT use those, so they do NOT want to version control this file.
# ..but if you're in the 1%, comment out the line "*.pbxuser"
@zacwest
zacwest / ios-font-sizes.swift
Last active March 27, 2024 07:16
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,
]
@DarrenN
DarrenN / get-npm-package-version
Last active April 17, 2024 16:57 — forked from yvele/get-npm-package-version.sh
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
echo $PACKAGE_VERSION
@natecook1000
natecook1000 / shuffle.swift
Last active December 11, 2018 06:53
Shuffle/shuffled functions & Array extensions
// (c) 2014 Nate Cook, licensed under the MIT license
//
// Fisher-Yates shuffle as top-level functions and array extension methods
/// Shuffle the elements of `list`.
func shuffle<C: MutableCollectionType where C.Index == Int>(inout list: C) {
let c = count(list)
for i in 0..<(c - 1) {
let j = Int(arc4random_uniform(UInt32(c - i))) + i
swap(&list[i], &list[j])
@peeblesjs
peeblesjs / gist:9288f79322ed3119ece4
Last active February 11, 2016 23:31
A naive "valueForKey:" operator in Swift
operator infix --> {}
func --> (instance: Any, key: String) -> Any? {
let mirror = reflect(instance)
for index in 0 ..< mirror.count {
let (childKey, childMirror) = mirror[index]
if childKey == key {
return childMirror.value
}
}
@therealjohn
therealjohn / gist:c658d6c087847360afdc
Created July 1, 2014 23:58
UIImage FixOrientation
public static UIImage FixOrientation(this UIImage image)
{
UIImage fixedImage = image;
// No-op if the orientation is already correct
if (image.Orientation == UIImageOrientation.Up) return image;
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform = CGAffineTransform.MakeIdentity();