Skip to content

Instantly share code, notes, and snippets.

View ArthurYidi's full-sized avatar

Arthur Yidi ArthurYidi

  • San Francisco, California
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Webpack Bundle Analyzer</title>
<!-- viewer.js -->
<script>
@ArthurYidi
ArthurYidi / detectFontChange.js
Created July 23, 2018 16:15
Detect Dynamic Font Size Changed
document.addEventListener('visibilitychange', function() {
if (document.visibilityState === 'visible') {
document.querySelector(':root').style.font = '-apple-system-body';
let fontSize = getComputedStyle(document.body).getPropertyValue('font-size');
console.log(fontSize);
}
});
@ArthurYidi
ArthurYidi / fonts.js
Created July 23, 2018 16:04
Body Font Size to Dynamic Type
const bodyFontToDynamicTypeSize = {
"14px": "xSmall",
"15px": "Small",
"16px": "Medium",
"17px": "Large",
"19px": "xLarge",
"21px": "xxLarge",
"23px": "xxxLarge",
"28px": "AX1",
"33px": "AX2",
@ArthurYidi
ArthurYidi / fonts.js
Created July 23, 2018 16:02
Body Font Sizes for Dynamic Type
const bodyFontToDynamicTypeSize = {
"14px": "xSmall",
"15px": "Small",
"16px": "Medium",
"17px": "Large",
"19px": "xLarge",
"21px": "xxLarge",
"23px": "xxxLarge",
"28px": "AX1",
"33px": "AX2",
#!/usr/bin/env python3
from subprocess import check_output, CalledProcessError
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("port", help="Port Number")
parser.add_argument("-n", "--dry-run", action="store_false", help="run without killing processes")
args = parser.parse_args()
# lsof
#! /usr/bin/env python
# Copyright (C) 2015 Arthur Yidi
# License: BSD Simplified
import sys
import struct
import socket
import time
from threading import Thread
from math import sin, cos
from array import array
@ArthurYidi
ArthurYidi / device properties.swift
Created April 9, 2016 02:03
Get HID Device Properties
let keys = [kIOHIDTransportKey, kIOHIDVendorIDKey, kIOHIDVendorIDSourceKey, kIOHIDProductIDKey, kIOHIDVersionNumberKey, kIOHIDManufacturerKey, kIOHIDProductKey, kIOHIDSerialNumberKey, kIOHIDCountryCodeKey, kIOHIDStandardTypeKey, kIOHIDLocationIDKey, kIOHIDDeviceUsageKey, kIOHIDDeviceUsagePageKey, kIOHIDDeviceUsagePairsKey, kIOHIDPrimaryUsageKey, kIOHIDPrimaryUsagePageKey, kIOHIDMaxInputReportSizeKey, kIOHIDMaxOutputReportSizeKey, kIOHIDMaxFeatureReportSizeKey, kIOHIDReportIntervalKey, kIOHIDSampleIntervalKey, kIOHIDBatchIntervalKey, kIOHIDRequestTimeoutKey, kIOHIDReportDescriptorKey, kIOHIDResetKey, kIOHIDKeyboardLanguageKey, kIOHIDAltHandlerIdKey, kIOHIDBuiltInKey, kIOHIDDisplayIntegratedKey, kIOHIDProductIDMaskKey, kIOHIDProductIDArrayKey, kIOHIDPowerOnDelayNSKey, kIOHIDCategoryKey, kIOHIDMaxResponseLatencyKey, kIOHIDUniqueIDKey, kIOHIDPhysicalDeviceUniqueIDKey]
for key in keys {
if let prop = IOHIDDeviceGetProperty(device, key) {
print("\t" + key + ": \(prop)")
}
}
@ArthurYidi
ArthurYidi / cgevents.swift
Created April 7, 2016 18:15
debug cgevents
switch type {
case .Null:
// system defined events
guard let nsEvent = NSEvent(CGEvent: event) else
{ print("failed nsvent"); break }
print("Null event \(binary(type.rawValue))");
print(nsEvent)
break
case .KeyDown: print("KeyDown event \(binary(type.rawValue))"); break
case .KeyUp: print("KeyUp event \(binary(type.rawValue))"); break
@ArthurYidi
ArthurYidi / translatekeycodes.swift
Created April 6, 2016 02:57
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,
@ArthurYidi
ArthurYidi / device.swift
Created April 6, 2016 01:20
Bluetooth Report HID
print("Device Connected \(device.addressString)")
let services = device.services?[1] as? IOBluetoothSDPServiceRecord
let report = services?.getAttributeDataElement(518)?.getArrayValue()
let reportDict = report?[0] as? IOBluetoothSDPDataElement
let reportDescriptorElement = reportDict?.getArrayValue()[1] as? IOBluetoothSDPDataElement
if let reportDescriptor = reportDescriptorElement?.getDataValue() {
var data = [UInt8](count: reportDescriptor.length, repeatedValue: 0)
reportDescriptor.getBytes(&data, length: reportDescriptor.length)
print(hex(data))