Skip to content

Instantly share code, notes, and snippets.

@haifengkao
haifengkao / removeDuplicate.py
Created October 14, 2023 22:18
remove duplicated lines in openmw.log
def remove_duplicates_ignore_timestamp(filename):
seen = set()
temp_filename = filename + '.temp'
with open(filename, 'r') as f, open(temp_filename, 'w') as temp_file:
for line in f:
# Strip the timestamp
stripped_line = line[12:]
if stripped_line not in seen:
@haifengkao
haifengkao / convertToYaml.py
Created October 14, 2023 22:03
convert morrowind plugins' dialogues and scripts to yaml
import os
import subprocess
import sys
# Directory paths
plugins_dir = "./plugins/"
dialogue_dir = "yamls/dialogue/"
script_dir = "yamls/script/"
# Ensure the output directories exist
@haifengkao
haifengkao / wrapperTest.swift
Created September 5, 2022 08:23
broken property wrapper syntax in Xcode 14 beta 5
@propertyWrapper
struct SmallNumber {
private var maximum: Int
private var number: Int
var wrappedValue: Int {
get { return number }
@haifengkao
haifengkao / TaggedWeak.swift
Created January 8, 2021 10:04
TaggedWeakWillCrashIfPutToEnum
public class TaggedWeak<T: AnyObject, Hash: Hashable>: Hashable {
public static func == (lhs: TaggedWeak<T, Hash>, rhs: TaggedWeak<T, Hash>) -> Bool {
lhs.hash == rhs.hash
}
public func hash(into hasher: inout Hasher) {
hasher.combine(hash)
}
public weak var value: T?
@haifengkao
haifengkao / TaggedWeak.swift
Created January 8, 2021 10:03
TaggedWeakCanBePutToEnum.swift
public struct TaggedWeak<T: AnyObject, Hash: Hashable>: Hashable {
public static func == (lhs: TaggedWeak<T, Hash>, rhs: TaggedWeak<T, Hash>) -> Bool {
lhs.hash == rhs.hash
}
public func hash(into hasher: inout Hasher) {
hasher.combine(hash)
}
public weak var value: T?
@haifengkao
haifengkao / TestRNNSequenceCountEvenOdd.py
Created October 21, 2020 10:09
Can RNN learn that the length of input sequence is even or odd number?
import tensorflow as tf
import random
def genSequence():
len = 101
X = []
for i in range(1, len):
X.append([[random.random()]]*i)
y = []
for i in range(1, len):
@haifengkao
haifengkao / TestRNNSequenceCount.py
Created October 21, 2020 10:04
Test if RNN can learn the length of input sequence
import tensorflow as tf
import random
def genSequence():
len = 101
X = []
for i in range(1, len):
X.append([[random.random()]]*i)
y = []
@haifengkao
haifengkao / gist:4473173790ac3d74ced7c9f09f27eefe
Last active September 21, 2020 07:38
point free exercise
import Foundation
infix operator <<<: CompositionPrecedence
precedencegroup CompositionPrecedence {
associativity: left
}
public func <<<<A, B, C>(
_ g: @escaping (B) -> C,
_ f: @escaping (A) -> B
@haifengkao
haifengkao / combineTest.swift
Last active September 1, 2020 12:01
combineLatest test
import Cocoa
import Combine
var subscriptions = Set<AnyCancellable>()
func futureIncrement(
integer: Int,
afterDelay delay: TimeInterval) -> AnyPublisher<Int, Never> {
Deferred {
@haifengkao
haifengkao / tpuError.log
Created August 15, 2020 07:25
Tensorflow TPU Error
InvalidArgumentError: 9 root error(s) found.
(0) Invalid argument: {{function_node __inference_train_function_80125}} Compilation failure: Detected unsupported operations when trying to compile graph broadcast_weights_1_assert_broadcastable_is_valid_shape_has_valid_nonscalar_shape_true_79965_const_0[] on XLA_TPU_JIT: DenseToDenseSetOperation (No registered 'DenseToDenseSetOperation' OpKernel for XLA_TPU_JIT devices compatible with node {{node broadcast_weights_1/assert_broadcastable/is_valid_shape/has_valid_nonscalar_shape/has_invalid_dims/DenseToDenseSetOperation}}){{node broadcast_weights_1/assert_broadcastable/is_valid_shape/has_valid_nonscalar_shape/has_invalid_dims/DenseToDenseSetOperation}}
[[broadcast_weights_1/assert_broadcastable/is_valid_shape/has_valid_nonscalar_shape]]
[[broadcast_weights_1/assert_broadcastable/is_valid_shape]]
TPU compilation failed
[[tpu_compile_succeeded_assert/_16364550150888184836/_30]]
[[TPUReplicate/_compile/_2384856891229734177/_29/_1132]]
(1) Invalid argument