Skip to content

Instantly share code, notes, and snippets.

@bumaociyuan
bumaociyuan / hehe.swift
Last active January 4, 2024 17:52
ios 听筒和扬声器切换
let session = AVAudioSession.sharedInstance()
try? session.setActive(true)
if !isSpeakerMode {
// NSLog(@"Device is close to user");
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
} catch _ {}
} else {
// NSLog(@"Device is not close to user");
@bumaociyuan
bumaociyuan / jxaClickAppSubMenuItem.applescript
Last active September 15, 2023 14:24 — forked from RobTrew/jxaClickAppSubMenuItem.applescript
Yosemite JXA Javascript Function for clicking application sub-menu items
// Click an OS X app sub-menu item
// 2nd argument is an array of arbitrary length (exact menu item labels, giving full path)
// e.g. menuItemClick("InqScribe", ['View', 'Aspect Ratio', 'Use Media Ratio'])
// Note that the menu path (spelling & sequence) must be exactly as in the app
// See menuItemTestClick() below for a slower version which reports any errors
// For OS X 10.10 Yosemite JXA JavaScript for Automation
@bumaociyuan
bumaociyuan / UIImage+gif.swift
Created May 4, 2018 08:37
Get first frame of gif
extension UIImage {
// first frame of gif
class func firstFrame(gif url: URL) -> UIImage? {
guard let data = try? Data(contentsOf: url) as CFData else {
return nil
}
guard let source = CGImageSourceCreateWithData(data, nil) else {
return nil
}
guard let cgimage = CGImageSourceCreateImageAtIndex(source, 0, nil) else {
@bumaociyuan
bumaociyuan / 拼图.bat
Last active January 18, 2021 15:18
需要 https://www.imagemagick.org/script/binary-releases.php#windows 把拼图.bat 放到 C:\Users\zx\AppData\Roaming\Microsoft\Windows\SendTo\ 里面就可以用右键 发送到 拼图.bat 调用脚本
@echo off
title Concat images vertically
echo Begin
set datetimef=%date:~0,2%-%date:~3,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%
echo %datetimef%
setlocal enabledelayedexpansion
set argCount=0
@bumaociyuan
bumaociyuan / cd.applescript
Created March 7, 2016 03:02
go2shell for iterm2.9
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
set command to "clear; cd " & pathList
end tell
tell application "System Events"
-- some versions might identify as "iTerm2" instead of "iTerm"
set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2"))
end tell
@bumaociyuan
bumaociyuan / ImagePositionButton.swift
Created July 4, 2016 03:11
Custom UIButton Title Position
//
// ImagePositionButton.swift
//
//
// Created by zx on 7/4/16.
// Copyright © 2016 zx. All rights reserved.
//
import UIKit
@bumaociyuan
bumaociyuan / common.cy
Last active September 30, 2018 08:29 — forked from susnmos/common.cy
A script for cycript
(function(exports) {
// 打印按钮的action及其target
zxactionWithTargets = function actionWithTargets(button) {
var allTargets = [button allTargets].allObjects();
if (!allTargets) {
return "is not a uicontrol"
}
var allShow = [];
for (var i = 0; i < allTargets.length; i++) {
var target = allTargets[i];
@bumaociyuan
bumaociyuan / shadow.sh
Created February 18, 2016 01:58
极路由安装ss
#!/bin/sh
#
echo ''
echo '/*教程请参考:极路由Shadowsocks家庭无痛翻墙实践*/'
echo 'https://luolei.org/hiwifi-shadowsocks/'
echo 'by @foru17'
echo ''
echo ''
echo '那一天,'
echo '人类终于回想起了,'
@bumaociyuan
bumaociyuan / NSObject+hook.m
Created January 29, 2018 07:52
swizzle function
@interface NSObject (hook)
+ (void)switchClassFuction:(NSString *)originalSelectorName swizzledSelector:(NSString *)swizzledSelectorName;
+ (void)switchInstanceFuction:(NSString *)originalSelectorName sel2:(NSString *)swizzledSelectorName;
@end
@implementation NSObject (hook)
+ (void)switchClassFuction:(NSString *)originalSelectorName swizzledSelector:(NSString *)swizzledSelectorName {
Class class = object_getClass((id)self);
SEL originalSelector = NSSelectorFromString(originalSelectorName);
@bumaociyuan
bumaociyuan / Podfile
Created June 29, 2017 07:41
单独配置podfile macro
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'demo' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
end
post_install do |installer|
installer.pods_project.targets.each do |target|