Skip to content

Instantly share code, notes, and snippets.

View onevcat's full-sized avatar
🐭

Wei Wang onevcat

🐭
View GitHub Profile
import UIKit
import WebKit
// Disableing `WKWebView` user zooming by returning `nil` in `UIScrollViewDelegate`'s
// `viewForZooming` delegate method.
// On iOS 12, the delegate method only called when set the web view itself as the
// scroll view delegate.
class WebView: WKWebView {}
@onevcat
onevcat / PostBuildLog.cs
Created December 5, 2012 05:15 — forked from darktable/PostBuildLog.cs
Unity3D: Post-process script that includes a build.log file containing the build summary in the output directory. Based on a method in BuildManager.
/* **************************************************************************
Copyright 2012 Calvin Rien
(http://the.darktable.com)
Derived from a method in BuildManager, part of
VoxelBoy's Unite 2012 Advanced Editor Scripting Talk.
(http://bit.ly/EditorScripting)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
extension Notification {
struct UserInfoKey<ValueType>: Hashable {
let key: String
}
@onevcat
onevcat / COW.swift
Last active September 12, 2023 08:25
import Foundation
var a = 123
var cpa = a
class Miao {}
var c = Miao()
var cc = c
struct S {}
var s = S()
@onevcat
onevcat / VVSnowShader.shader
Created August 31, 2013 07:49
Shader of a snow effect.
Shader "Custom/VVSnowShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Bump ("Bump", 2D) = "bump" {}
_Snow ("Snow Level", Range(0,1) ) = 0
_SnowColor ("Snow Color", Color) = (1.0,1.0,1.0,1.0)
_SnowDirection ("Snow Direction", Vector) = (0,1,0)
_SnowDepth ("Snow Depth", Range(0,0.3)) = 0.1
}
SubShader {
@onevcat
onevcat / Controller.cs
Last active August 30, 2023 08:01
Final script for UniWebView "Working with Code" sample
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour {
UniWebView webView;
// Use this for initialization
void Start () {
//Solution goes in Sources
public struct Card: CustomStringConvertible {
enum Suit: String {
case spade = "♤", heart = "♡", club = "♧", diamond = "♢"
// It is not the standard Texas poker rule. All suits are considered equal.
// However, there is a test case to "brake tide by suit", in which "heart" is the largest.
var value: Int {
switch self {
@onevcat
onevcat / Default.swift
Created November 10, 2020 03:56
Sample code of using Default to decode a property to the default value
import UIKit
protocol DefaultValue {
associatedtype Value: Decodable
static var defaultValue: Value { get }
}
@propertyWrapper
struct Default<T: DefaultValue> {
var wrappedValue: T.Value
@onevcat
onevcat / xcodeproj_build.rb
Last active May 12, 2023 02:03
Example of using xcodeproj
require_relative "../config.rb"
gem 'xcodeproj', '>=0.19.4'
require 'xcodeproj'
PROJECT = 'Unity-iPhone'
TARGET = 'Unity-iPhone'
LIBRARY = 'Libraries'
### Export
def exportUnityProject
@onevcat
onevcat / MonoSingleton.cs
Created July 18, 2013 00:37
Mono singleton Class. Extend this class to make singleton component.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Mono singleton Class. Extend this class to make singleton component.
/// Example:
/// <code>
/// public class Foo : MonoSingleton<Foo>
/// </code>. To get the instance of Foo class, use <code>Foo.instance</code>