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")
@zhaorui
zhaorui / RunloopCallback.mm
Created April 29, 2020 14:57
[Runloop Observer]
void DNSResolveerRunLoopObserverCallBack(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info) {
switch (activity) {
case kCFRunLoopEntry:
NSLog(@"kCFRunLoopEntry");
break;
case kCFRunLoopBeforeTimers:
NSLog(@"kCFRunloopBeforeTimers");
break;
case kCFRunLoopBeforeSources:
NSLog(@"kCFRunLoopBeforeSources");
@zhaorui
zhaorui / dumpasn1.c
Created December 2, 2019 07:28
dump ASN.1 data
/* ASN.1 data display code, copyright Peter Gutmann
<pgut001@cs.auckland.ac.nz>, based on ASN.1 dump program by David Kemp,
with contributions from various people including Matthew Hamrick, Bruno
Couillard, Hallvard Furuseth, Geoff Thorpe, David Boyce, John Hughes,
'Life is hard, and then you die', Hans-Olof Hermansson, Tor Rustad,
Kjetil Barvik, James Sweeny, Chris Ridd, David Lemley, John Tobey, James
Manger, Igor Perminov, and several other people whose names I've
misplaced.
Available from http://www.cs.auckland.ac.nz/~pgut001/dumpasn1.c. Last
NSString *dylibPath = @"/Users/billzhao/Desktop/libRulesActions.dylib";
const char *libPath = [dylibPath cStringUsingEncoding:NSUTF8StringEncoding];
void *dl = dlopen(libPath, RTLD_NOW);
const char *dlErr = dlerror();
if (dlErr) {
NSLog(@"dlerror() = %s", dlErr);
} else {
NSLog(@"dylib path is %s, dl = %p", libPath, dl);
}
#!/usr/bin/python
class Perceptron(object):
def __init__(self, input_num, activator):
'''
初始化感知器,设置输入参数的个数,以及激活函数。
激活函数的类型为double -> double
'''
self.activator = activator
# 权重向量初始化为0
#!/bin/bash
# redirect STDOUT to a file (note the single > -- this will truncate /tmp/outfile)
exec 1> /tmp/outfile
echo Now all STDOUT from each subsiquent command will
echo be redirected to /tmp/outfile
echo but not STDERR >&2
# redirect STDERR to STDOUT and append (note the double >>) both to /tmp/outfile
@zhaorui
zhaorui / server.c
Created November 26, 2017 03:12
Simple http server written in C
#include<netinet/in.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
int main() {
int create_socket, new_socket;
@zhaorui
zhaorui / config.fish
Created April 7, 2017 02:55
My fish config
# Path to Oh My Fish install.
set -q XDG_DATA_HOME
and set -gx OMF_PATH "$XDG_DATA_HOME/omf"
or set -gx OMF_PATH "$HOME/.local/share/omf"
# Load Oh My Fish configuration.
source $OMF_PATH/init.fish
set -x PATH $PATH ~/GitRepo/depot_tools
set -x PATH $PATH ~/.cargo/bin
@zhaorui
zhaorui / NSButtonExtension.swift
Created February 8, 2017 15:59
NSButton extension to set title color
extension NSButton {
var titleTextColor : NSColor {
get {
let attrTitle = self.attributedTitle
return attrTitle.attribute(NSForegroundColorAttributeName, at: 0, effectiveRange: nil) as! NSColor
}
set(newColor) {
let attrTitle = NSMutableAttributedString(attributedString: self.attributedTitle)
@zhaorui
zhaorui / CharacterSetExtension.swift
Created February 7, 2017 09:43
See characters in CharacterSet (swift)
extension CharacterSet {
var characters:[UnicodeScalar] {
var chars = [UnicodeScalar]()
for plane:UInt8 in 0...16 {
if self.hasMember(inPlane: plane) {
let p0 = UInt32(plane) << 16
let p1 = (UInt32(plane) + 1) << 16
for c:UInt32 in p0..<p1 {
if let us = UnicodeScalar(c) {
if self.contains(us) {