Skip to content

Instantly share code, notes, and snippets.

View ArthurYidi's full-sized avatar

Arthur Yidi ArthurYidi

  • San Francisco, California
View GitHub Profile
@ArthurYidi
ArthurYidi / index.html
Last active October 7, 2015 04:47
steam logo
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Sketch</title>
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js"></script>
@ArthurYidi
ArthurYidi / gist:a2a6fbdb59f0580016fc
Last active August 29, 2015 14:04
Processing blendMode()
size(100, 100);
// drawing surface with no background
PGraphics pg = createGraphics(100, 100);
pg.beginDraw();
pg.background(255);
pg.blendMode(DIFFERENCE);
pg.fill(255);
pg.noStroke();
pg.ellipse(40, 50, 30, 30);
@ArthurYidi
ArthurYidi / formateDate.swift
Created March 29, 2016 21:35
NSDate to String
func formatDate(date: NSDate, format: String = "yyyy-MM-dd hh:mm:ss Z") -> String {
let formatter = NSDateFormatter()
formatter.dateFormat = format
return formatter.stringFromDate(date)
}
@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))
@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 / 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 / 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)")
}
}
#! /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
#!/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
@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",