Skip to content

Instantly share code, notes, and snippets.

View victorchee's full-sized avatar
🎯
Focusing

Victor Chee victorchee

🎯
Focusing
View GitHub Profile
// ==UserScript==
// @name XiSai
// @namespace https://gist.github.com/victorchee/e5cec41982f3fbf611faa0e6f88459c6.js
// @version 0.1
// @description try to take over the world!
// @author VictorChee
// @match https://wangxiao.xisaiwang.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=45.185
// @grant none
// ==/UserScript==
'use strict';
const fs = require('fs');
const read = fs.readdirSync('./');
let string = '';
for (let i in read) {
const item = read[i];
const index = item.lastIndexOf('.');
string += item.substring(0, index) + '\n';
const fs = require('fs');
const path = require('path');
const fetch = require('node-fetch');
if (!fs.existsSync('images')) {
fs.mkdirSync('images');
}
async function download(url) {
const request = await fetch(url);
import UIKit
extension URLSession {
func dataTask(with url: URL, completionHandler: @escaping (Result<Data, Error>, URLResponse?) -> Void) -> URLSessionDataTask {
return dataTask(with: url) { (data, response, error) in
if let error = error {
completionHandler(.failure(error), response)
} else {
completionHandler(.success(data ?? Data()), response)
}
// Objective-C
#if TARGET_IPHONE_SIMULATOR
// Simulator
#else
// Device
#endif
// Swift
#if targetEnvironment(simulator)
// your simulator code
@victorchee
victorchee / FindHotPatch.sh
Created May 31, 2019 01:44
Find hot patch in Xcode project.
#!/bin/sh
echo "请输入需要检测的工程路径"
read path
if [ ${#path} = 0 ]
then
echo "请在.sh文件后面添加路径"
exit
fi
cd $path
echo "当前路径为`pwd`"
@victorchee
victorchee / PanDirectionGestureRecognizer.swift
Created January 7, 2019 06:17
Pan gesture recognizer with directions.
import UIKit
enum PanDirection {
case vertical
case horizontal
}
class PanDirectionGestureRecognizer: UIPanGestureRecognizer {
let direction: PanDirection
@victorchee
victorchee / Fireworks.swift
Created December 29, 2018 06:11
Fireworks effect by emitter.
let emitterLayer = CAEmitterLayer()
emitterLayer.frame = navigationView.bounds
emitterLayer.renderMode = .additive
emitterLayer.emitterMode = .outline
emitterLayer.emitterShape = .line
emitterLayer.emitterSize = CGSize(width: 50, height: 0)
emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: navigationView.bounds.height)
emitterLayer.velocity = 1
emitterLayer.seed = (arc4random() % 100) + 1
navigationView.layer.insertSublayer(emitterLayer, at: 0)
@victorchee
victorchee / Snow.swift
Created December 29, 2018 05:51
Snow effect by emitter.
let emitterLayer = CAEmitterLayer()
emitterLayer.frame = navigationView.bounds
emitterLayer.renderMode = .oldestLast
emitterLayer.emitterShape = .rectangle
emitterLayer.emitterSize = CGSize(width: navigationView.bounds.width, height: navigationView.bounds.height / 2)
emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: 0)
navigationView.layer.insertSublayer(emitterLayer, at: 0)
let emitterCell = CAEmitterCell()
emitterCell.contents = UIImage(named: "triangle1")?.cgImage
UIView.animate(withDuration: 0.25, animations: {
self.collectionView?.setContentOffset(CGPoint.zero, animated: false)
}) { (finished) in
self.collectionView.refreshControl?.beginRefreshing()
self.collectionView.refreshControl?.sendActions(for: .valueChanged)
self.collectionView.setContentOffset(CGPoint(x: 0, y: -60), animated: false)
}