Skip to content

Instantly share code, notes, and snippets.

View hewigovens's full-sized avatar
🪄
Debugging

Tao Xu hewigovens

🪄
Debugging
View GitHub Profile
@hewigovens
hewigovens / latency.markdown
Created October 14, 2016 03:34 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@hewigovens
hewigovens / pipe_source.m
Created May 24, 2016 08:41 — forked from keithduncan/pipe_source.m
Various options for streaming from the read end of a pipe until EOF
/*
pipe_source.m
clang pipe_source.m -o pipe -framework Foundation -D [ USE_SOURCE | USE_IO | USE_FILEHANDLE [ FILEHANDLE_READABILITY | FILEHANDLE_WAIT ] ]
*/
#import <Foundation/Foundation.h>
int main(void) {
enum RunLoop {
@hewigovens
hewigovens / in.fourplex.aria2.plist
Created December 12, 2015 07:39
aria2 auto launch plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>in.fourplex.aria2</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/aria2c</string>
@hewigovens
hewigovens / main.c
Last active May 15, 2020 02:33
get executable path from libproc
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libproc.h>
int main (int argc, char* argv[])
{
int ret;
pid_t pid;
@hewigovens
hewigovens / link_derived_folder.sh
Last active May 15, 2020 02:33
symlink derived data path in Xcode build phase
@hewigovens
hewigovens / get_disk_sn.m
Last active January 2, 2016 09:09
Get internal disk serial number
NSString* getInternalDiskSN()
{
NSString* result = @"";
CFMutableDictionaryRef matching;
matching = IOServiceMatching("IOAHCIBlockStorageDevice");
io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, matching);
if (service) {
CFMutableDictionaryRef properties = NULL;
@hewigovens
hewigovens / clean_sdk_gcc.sh
Created October 17, 2013 04:34
Remove SDK/GCC/DeployTarget settings from legacy Xcode projects
#!/bin/sh
find . -name "*.pbxproj" -exec sed -i "*.bak" '/GCC_VERSION/d' {} \;
find . -name "*.pbxproj" -exec sed -i "*.bak" '/SDKROOT =/d' {} \;
find . -name "*.pbxproj" -exec sed -i "*.bak" '/MACOSX_DEPLOYMENT_TARGET =/d' {} \;
@hewigovens
hewigovens / install-sdk
Last active December 13, 2015 19:48 — forked from rpetrich/install-sdk
#!/bin/sh
SDK=`dirname $0`
SCRIPT=`basename $0`
SDKPARENT=`dirname $SDK`
DEVROOT=`xcode-select --print-path`
SDKVER=`xcodebuild -showsdks | grep iphoneos | awk '{print $2}' | tail -n 1`
SDKROOT="$DEVROOT/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$SDKVER.sdk"
SDKsROOT="$DEVROOT/Platforms/iPhoneOS.platform/Developer/SDKs"
PLATFORM=`uname -sp`
@hewigovens
hewigovens / short_url_resolve.c
Created May 9, 2012 06:08
resolve short url
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode ret;
char* resolved_url = NULL;
curl = curl_easy_init();
if(curl)