Skip to content

Instantly share code, notes, and snippets.

View zhaorui's full-sized avatar

Bill Zhao zhaorui

View GitHub Profile
@zhaorui
zhaorui / keypad.swift
Created November 11, 2021 13:52
A console app print all key events written by swift
import Cocoa
import Foundation
@discardableResult
func acquirePrivileges() -> Bool {
let accessEnabled = AXIsProcessTrustedWithOptions([kAXTrustedCheckOptionPrompt.takeUnretainedValue() as String: true] as CFDictionary)
if accessEnabled != true {
print("You need to enable the keylogger in the System Prefrences")
@fnky
fnky / ANSI.md
Last active July 27, 2024 21:04
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@uupaa
uupaa / spin.animation.html
Created January 14, 2016 15:45
回転アニメーション spin animation CSS
<!DOCTYPE html><html><head><title></title>
<meta name="viewport" content="width=device-width, user-scalable=no">
<meta charset="utf-8"></head><body>
<style>
@keyframes spin {
to { transform: rotate(-10turn); }
}
#product-logo.spin {
animation: spin 500ms cubic-bezier(1, 0, 0, 1) forwards;
extension CollectionType where Index: BidirectionalIndexType {
func lastIndexOf(isElement: Generator.Element -> Bool) -> Index? {
return indices.reverse().filter { return isElement(self[$0]) }.first
}
}
@andrew-d
andrew-d / main.c
Last active April 29, 2024 17:01
Example of how to get current binary's path using Apple's Code Signing Services
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <Security/Security.h>
// Compile with:
// gcc -o ourpath -framework CoreFoundation -framework Security main.c
import Cocoa
// for-in
func checkForIn(array: [Int], dict: [Int: String]) {
for num in array where dict[num] != nil {
num
}
}
checkForIn([1,2,3,4], dict: [1:"one", 2:"two"])
@midwire
midwire / reset_routing_table.sh
Last active July 25, 2024 17:31
[Reset routing table on OSX] #osx #devops #networking
#!/usr/bin/env bash
# Reset routing table on OSX
# display current routing table
echo "********** BEFORE ****************************************"
netstat -r
echo "**********************************************************"
for i in {0..4}; do
sudo route -n flush # several times
@KosmicTask
KosmicTask / BPImageView.h
Created April 7, 2014 15:31
NSImageView subclass that responds to mouse up and sends click event
@interface BPImageView : NSImageView
@property SEL clickAction;
@end