Skip to content

Instantly share code, notes, and snippets.

View leavez's full-sized avatar
💭
I may be slow to respond.

Leave leavez

💭
I may be slow to respond.
View GitHub Profile
@0x1306a94
0x1306a94 / swift_macro_not_use_spm.md
Last active March 28, 2024 12:35
Swift Macro does not use SPM integration

Swift Macro 不使用 Swift Package Manager如何集成

  • Swift Macro分为两部分,一部分为宏的具体实现(编译器插件),一部分为Macro Lib用于导出宏定义以及所需要的附属代码,这里说的不使用SPM指的是编译器插件这部分
  • 仔细观察Xcode使用SPM集成Macro时,在编译命令中通过-load-plugin-executable参数指定了对应宏实现的插件可执行文件路径
  • 同时在swift源码中也找到了相关参数TypeCheckMacros.cpp TypeCheckMacros.cpp
  • swift源码中可得知,宏实现插件即可以是动态库(dylib)也可以是可执行文件
  • 系统内置的宏实现是通过 -plugin-path <dylib path> 加载
  • 内置的宏实现动态库在Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/Lib/swift/host/plugins
具体步骤
  • 编写宏实现代码,这一步可以通过SPM也可以直接通过Xcode创建命令行程序项目,完成宏实现代码编写
@glv
glv / bundler-exec.fish
Last active January 5, 2023 21:45
Automatically prepend "bundle exec" when appropriate (in fish shell).
# This sets up fish so that, if you type a command that should be
# run using Bundler, it first automatically prepends "bundle exec"
# to the command line buffer before executing it. Works for all
# commands found in the "bin" directory of the current bundle.
#
# To override this behavior and run such a command without Bundler,
# prefix with "command" (e.g., `command rake -T`)
#
# Pros (vs binstubs or aliases):
# * automatically adjusts to bundle changes
@blackgear
blackgear / clock.swift
Last active April 20, 2023 15:41
A simple floating clock for OS X
// The MIT License
// Copyright (c) 2018 Daniel
// 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
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// Created by Eric Firestone on 3/22/16.
// Copyright © 2016 Square, Inc. All rights reserved.
// Released under the Apache v2 License.
//
// Adapted from https://gist.github.com/blakemerryman/76312e1cbf8aec248167
import Foundation
@pyrtsa
pyrtsa / ThrowingSubscripts.swift
Created November 12, 2015 17:19
"Throwing subscripts" in Swift 2
infix operator « { associativity left }
infix operator »« { associativity left }
postfix operator » {}
struct Index {
let value: Int
}
enum Error : ErrorType {
case OutOfBounds(index: Int, count: Int)
@jperkin
jperkin / mdnschroot.sh
Last active December 27, 2019 05:56
Dynamically add/remove mDNSResponder chroot socket
#!/bin/bash
#
# This is an example script to dynamically update mDNSResponder on OSX to
# add/remove a chroot socket to enable DNS resolution inside it.
#
# If the chroot is not added, add it, otherwise delete it.
#
# You will probably want a more robust version for production.
#
@mobilemind
mobilemind / git-tag-delete-local-and-remote.sh
Last active July 2, 2024 00:02
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@hfossli
hfossli / gist:7234623
Last active April 19, 2024 10:09
KVO on a views geometry
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 300, 200)];
view.backgroundColor = [UIColor blueColor];
[self.view addSubview:view];
[view addObserver:self forKeyPath:@"frame" options:0 context:NULL];
@sauloperez
sauloperez / signal_catching.rb
Last active November 11, 2020 11:25
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@nachocab
nachocab / instructions.sh
Last active February 13, 2022 15:45
How to make git diff work perfectly with .docx files in Mac OS X (it even colors by word)
# download docx2txt by Sandeep Kumar
wget -O docx2txt.pl http://www.cs.indiana.edu/~kinzler/home/binp/docx2txt
# make a wrapper
echo '#!/bin/bash
docx2txt.pl $1 -' > docx2txt
chmod +x docx2txt
# make sure docx2txt.pl and docx2txt are your current PATH. Here's a guide
http://shapeshed.com/using_custom_shell_scripts_on_osx_or_linux/