Skip to content

Instantly share code, notes, and snippets.

View vayn's full-sized avatar

Vayne Tsai vayn

View GitHub Profile
@vayn
vayn / translatekeycodes.swift
Created November 13, 2016 12:20 — forked from ArthurYidi/translatekeycodes.swift
virtual key codes to unicode characters
func keyCodeToString(keyCode: CGKeyCode) -> String {
let curKeyboard = TISCopyCurrentKeyboardInputSource().takeRetainedValue()
let ptr = TISGetInputSourceProperty(curKeyboard, kTISPropertyUnicodeKeyLayoutData)
let keyboardLayoutPtr = UnsafePointer<UCKeyboardLayout>(ptr)
var deadKeyState: UInt32 = 0
var actualStringLength = 0
var unicodeString = [UniChar](count: 255, repeatedValue: 0)
let status = UCKeyTranslate(keyboardLayoutPtr,
strCmd = "%COMSPEC% /c ping 192.0.2.1 -n 1 -w 1000 >nul"
Set shell = CreateObject("WScript.Shell")
shell.Run strCmd, 0, 1
WScript.Echo("Foreground window title: " & vbCrLf & GetForeWindowCaption())
Function GetForeWindowCaption()
Const WM_GETTEXT = &HD
Set DX = CreateObject("DynamicWrapperX")
DX.Register "user32", "GetForegroundWindow", "f=s", "r=l"
####################################################################
# Change the number of rows and columns to display in Launchpad #
# by typing the following two lines in Terminal. You can use any #
# two integers for the number of rows and columns. I'm using 15x10 #
####################################################################
defaults write com.apple.dock springboard-columns -int 15
defaults write com.apple.dock springboard-rows -int 10
####################################################################
# Reset all settings
@vayn
vayn / dp_3.py
Last active October 7, 2021 08:11
BadNeighbors - 2004 TCCC Online Round 4 - Division I, Level One
# https://community.topcoder.com/stat?c=problem_statement&pm=2402&rd=5009
#
# 状态转移方程:
#
# max{
# max{m[i-1][0], m[i-2][0] + A[i-1]},
# max{m[i-1][1], m[i-2][1] + A[i]}
# }
#
@vayn
vayn / eightqueen.php
Created November 3, 2010 07:41
八皇后 Eight Queens PHP
<?php
/*
* 八皇后问题是一个非常有趣的问题,是由德国大数学家高斯首先提出来的。
* 要求在国际象棋的棋盘上放置八个皇后,使她们不能互相攻击。
* 即任何两个皇后不能处在同一行、同一列、同一条斜线上。
*
* 问有多少种不同的摆法?并找出所有的摆法。
*
* 问题分析:
* (1) 满足上述条件的八个皇后,必然是每行一个,每列一个。
@vayn
vayn / parser.rs
Last active May 18, 2019 15:56
Parser combinator in Rust (https://git.io/xml-parser-combinator)
#![allow(dead_code)]
#[derive(Clone, Debug, PartialEq, Eq)]
struct Element {
name: String,
attributes: Vec<(String, String)>,
children: Vec<Element>,
}
/// Time For A Trait
@vayn
vayn / connectHTMLelements_SVG.png
Created May 6, 2019 15:05 — forked from alojzije/connectHTMLelements_SVG.png
Connect two elements / draw a path between two elements with SVG path (using jQuery)
connectHTMLelements_SVG.png
@vayn
vayn / cli-gojuon-exercise.py
Last active April 18, 2019 05:58
CLI Gojūon Exercise
#!/usr/bin/env python3
import random
import signal
import sys
"""帮助
输入 ? 显示正确答案
"""
TEST_COUNT = 0
@vayn
vayn / cvimrc.vim
Last active April 11, 2019 06:11
Vayn's cVim setting
let blacklists = ["https://mail.google.com/* gi gt x r f"]
map H scrollLeft
map L scrollRight
map h previousTab
map l nextTab
map r reloadTabUncached
map u lastClosedTab
map R :restore<Space>
map , goBack
@vayn
vayn / map_lctrl_plus_open_bracket_to_esc.json
Created September 4, 2018 16:18
Map Left-Control+Open-Bracket to Escape (Karabiner-Elements)
{
"title": "Map Left-Control+Open-Bracket to Escape",
"rules": [
{
"manipulators": [
{
"description": "Bracket Rule [left_control + open_bracket]",
"type": "basic",
"from": {
"key_code": "open_bracket",