Skip to content

Instantly share code, notes, and snippets.

View annidy's full-sized avatar
💭
I may be slow to respond.

fengxing annidy

💭
I may be slow to respond.
View GitHub Profile
@annidy
annidy / battery.py
Last active November 2, 2023 04:42 — forked from wangqr/battery.py
Python script to get battery status on Windows
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import ctypes
from ctypes import wintypes
class SYSTEM_POWER_STATUS(ctypes.Structure):
_fields_ = [
('ACLineStatus', wintypes.BYTE),
('BatteryFlag', wintypes.BYTE),
@annidy
annidy / String+Extensions.swift
Created February 3, 2023 15:13 — forked from Winchariot/String+Extensions.swift
Encode String for URL param or request body
//Both implementations thanks to https://useyourloaf.com/blog/how-to-percent-encode-a-url-string/
//Upgraded/cleaned up for Swift 4
Extension String {
func percentEncodedForRFC3986() -> String? {
let unreserved = "-._~/?"
var allowed = CharacterSet.alphanumerics
allowed.insert(charactersIn: unreserved)
return self.addingPercentEncoding(withAllowedCharacters: allowed)
}
//cc -Wextra -o build/dump-header-map dump-header-map.c
// see: https://github.com/llvm-mirror/clang/blob/release_40/include/clang/Lex/HeaderMapTypes.h
// https://github.com/llvm-mirror/clang/blob/release_40/include/clang/Lex/HeaderMap.h// https://github.com/llvm-mirror/clang/blob/release_40/lib/Lex/HeaderMap.cpp
// This is basically dump() from there.
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <err.h>
@annidy
annidy / ShowDerivedData.rb
Created October 27, 2021 07:04 — forked from caius/ShowDerivedData.rb
A script for showing the derived data folder for an Xcode workspace. Intended to be invoked from a custom behaviour
#!/usr/bin/env ruby
# This script currently only works if you have your derived data in the default location.
# Get the workspace name to search for, or exit with code 1 if no value in envariable
xcodeWorkspacePath = ENV["XcodeWorkspacePath"] || exit(1)
projectName = xcodeWorkspacePath[%r{/(\w+)\.xcodeproj}, 1]
#Get the folders in derived data that could match the workspace
derived_data = File.expand_path("~/Library/Developer/Xcode/DerivedData")
# Glob out the files matching our project
@annidy
annidy / BinaryCookieReader.py
Created July 21, 2021 07:24 — forked from sh1n0b1/BinaryCookieReader.py
BinaryCookieReader
#*******************************************************************************#
# BinaryCookieReader: Written By Satishb3 (http://www.securitylearn.net) #
# #
# For any bug fixes contact me: satishb3@securitylearn.net #
# #
# Usage: Python BinaryCookieReader.py Cookie.Binarycookies-FilePath #
# #
# Safari browser and iOS applications store the persistent cookies in a binary #
# file names Cookies.binarycookies.BinaryCookieReader is used to dump all the #
# cookies from the binary Cookies.binarycookies file. #
@annidy
annidy / a.m
Last active December 18, 2020 08:11 — forked from michaeleisel/a.m
//Copyright (c) 2018 Michael Eisel. All rights reserved.
#import "CLRCallRecorder.h"
#import <dlfcn.h>
#import <libkern/OSAtomicQueue.h>
#import <pthread.h>
typedef struct {
void *ptr;
NSInteger number;
@annidy
annidy / libdispatch-efficiency-tips.md
Created February 27, 2020 01:37 — forked from tclementdev/libdispatch-efficiency-tips.md
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

I suspect most developers are using the libdispatch inefficiently due to the way it was presented to us at the time it was introduced and for many years after that, and due to the confusing documentation and API. I realized this after reading the 'concurrency' discussion on the swift-evolution mailing-list, in particular the messages from Pierre Habouzit (who is the libdispatch maintainer at Apple) are quite enlightening (and you can also find many tweets from him on the subject).

My take-aways are:

@annidy
annidy / textHeight.m
Created May 22, 2019 13:31 — forked from brennanMKE/textHeight.m
Text Height in Objective-C for NSString and NSAttributedString
- (CGFloat)heightForAttributedString:(NSAttributedString *)text maxWidth:(CGFloat)maxWidth {
if ([text isKindOfClass:[NSString class]] && !text.length) {
// no text means no height
return 0;
}
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
CGSize size = [text boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:options context:nil].size;
@annidy
annidy / Python3 HTTP Server.py
Created December 4, 2018 07:02 — forked from Integralist/Python3 HTTP Server.py
Python3 HTTP Server.py
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 9000
class MyHandler(BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
@annidy
annidy / AVAsset+VideoOrientation.h
Created April 25, 2017 06:26 — forked from luca-bernardi/AVAsset+VideoOrientation.h
Find the video orientation of an AVAsset. (Useful if you need to send the video to a remote server)
//
// AVAsset+VideoOrientation.h
//
// Created by Luca Bernardi on 19/09/12.
// Copyright (c) 2012 Luca Bernardi. All rights reserved.
//
#import <AVFoundation/AVFoundation.h>
typedef enum {
LBVideoOrientationUp, //Device starts recording in Portrait