Skip to content

Instantly share code, notes, and snippets.

View szhu's full-sized avatar

Sean Zhu szhu

  • NYC / SF
  • 12:32 (UTC -04:00)
  • X @sfzhu
View GitHub Profile
@floer32
floer32 / Uniform Type Identifiers (UTI).md
Last active August 5, 2022 18:06
I always forget where to find this, so here's a copy. It's an old-but-still-useful thing from the Apple Developer documentation archive, and it's from 2005 (whoa, right?)

What's a Uniform Type Identifier?

Each UTI provides a unique identifier for a particular file type, data type, directory or bundle type, and so on. In addition, other type identifier namespaces for a particular type can be grouped under one UTI, with utility functions available to translate from one format to another.

What's the table below?

The following tables list uniform type identifiers (UTIs) that are declared by the system as of OS X v10.4. [Which was released in 2005. That means it's NOT up to date. Apple Developer stuff has the up to date docs. Still, these can be useful for scripting, Alfred Workflows, and so on.]

Note: T

@manuelbl
manuelbl / README.md
Created August 3, 2019 09:12
ESP32 as Bluetooth Keyboard

ESP32 as Bluetooth Keyboard

With its built-in Bluetooth capabilities, the ESP32 can act as a Bluetooth keyboard. The below code is a minimal example of how to achieve it. It will generate the key strokes for a message whenever a button attached to the ESP32 is pressed.

For the example setup, a momentary button should be connected to pin 2 and to ground. Pin 2 will be configured as an input with pull-up.

In order to receive the message, add the ESP32 as a Bluetooth keyboard of your computer or mobile phone:

  1. Go to your computers/phones settings
  2. Ensure Bluetooth is turned on
@4np
4np / ambientLightSensor.swift
Created January 24, 2017 23:33
Acces Mac OS Ambient Light Sensor
func getLux() {
guard let serviceType = IOServiceMatching("AppleLMUController") else {
debugPrint("No ambient light sensor")
return
}
// get and release service
let service = IOServiceGetMatchingService(kIOMasterPortDefault, serviceType)
defer {
IOObjectRelease(service)
// FindMode - phoenix binding for an interactive window-finding mode
// * bind to a key by calling the instance's 'bind' method, which has the
// same first two args as phoenix's Phoenix.bind() call. The third argument
// is an array of other key bindings which should be temporarily disabled
// while in the FindMode mode.
// * while in Find mode:
// - hit escape to exit the mode (todo: and restore the window stack)
// - type a regex to interactively auto-raise the first window that matches
// - backspace to remove chars from the regex
// - hit tab to cycle to the next matching window for the current regex
@paulirish
paulirish / what-forces-layout.md
Last active April 14, 2024 08:07
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@obfusk
obfusk / break.py
Last active March 20, 2024 23:09
python "breakpoint" (more or less equivalent to ruby's binding.pry); for a proper debugger, use https://docs.python.org/3/library/pdb.html
import code; code.interact(local=dict(globals(), **locals()))
@bensmithett
bensmithett / AppComponent.cjsx
Last active April 20, 2020 06:59
The world's tiniest guide to getting started with React, JSX, CoffeeScript & Webpack
React = require("react")
VideoPlayerComponent = require("components/VideoPlayerComponent")
AppComponent = React.createClass
# Need to add this manually if you want it to show up in React Chrome Dev Tools
# See https://github.com/jsdf/coffee-react-transform/issues/16
displayName: "AppComponent"
render: ->
<div>
@papaben
papaben / git.sh
Created April 18, 2014 20:51
My typical answer when git asks, "Did you mean?"
##
# "I did [mean that]"
# Re-run the suggested git command
# Intended to be run as 'idid !!'
##
function idid() {
declare last=''
while [[ $# > 0 ]]; do
last="$last $1"
require 'psych'
class ScalarHandler < Psych::Handler
def parser=(parser)
@parser=parser
end
def mark
@parser.mark
@n-b
n-b / selfcompile.m
Last active April 29, 2019 03:43
A simple self-compiling objective-c file
/*/../bin/ls > /dev/null
COMPILED=${0%.*}
clang $0 -o $COMPILED -framework Foundation;
$COMPILED; rm $COMPILED; exit;
*/
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])