Skip to content

Instantly share code, notes, and snippets.

View zydeco's full-sized avatar

Jesús A. Álvarez zydeco

View GitHub Profile
@zydeco
zydeco / thread.h
Created May 28, 2012 14:18
pthread/win32 threads
#ifdef __WIN32__
#include <windows.h>
typedef HANDLE mutex_t;
typedef HANDLE thread_t;
#define mutex_init(m) m = CreateMutex(NULL, FALSE, NULL)
#define mutex_lock(m) WaitForSingleObject(m, INFINITE)
#define mutex_unlock(m) ReleaseMutex(m)
#define mutex_destroy(m) CloseHandle(m)
@zydeco
zydeco / ExtendedAttributes.h
Created August 21, 2013 10:21
NSFileManager + extended attributes
//
// ExtendedAttributes.h
// NSFileManager+Xattr
//
// Created by Jesús A. Álvarez on 2008-12-17.
// Copyright 2008-2009 namedfork.net. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <sys/xattr.h>
@zydeco
zydeco / UIColor+String.h
Last active December 21, 2015 19:49
Init UIColor from string like #ff33cc rgb(255,51,204) or rgba(255,51,204,0.8)
#import <UIKit/UIKit.h>
@interface UIColor (String)
+ (UIColor*)colorWithString:(NSString*)str;
- (UIColor*)initWithString:(NSString*)str;
@end
@zydeco
zydeco / NSData+Hex.h
Last active August 29, 2015 13:58
Get a hex string from NSData
#import <Foundation/Foundation.h>
@interface NSData (Hex)
- (NSString*)hexString;
- (NSString*)hexStringWithCaps:(BOOL)caps;
+ (NSData*)dataWithHexString:(NSString*)hexString;
@end
@zydeco
zydeco / goestoward.swift
Last active April 27, 2016 08:36
goes toward operator
infix operator --> { associativity left precedence 80 }
func --><T:IntegerType>(inout left:T, right:T) -> Bool {
if left != right {
left = left.advancedBy(left > right ? -1 : 1)
return true
} else {
return false
}
}
@zydeco
zydeco / DisableKnockToAdmin
Created April 20, 2015 11:16
Disable Knock for admin password dialogs
#!/bin/bash
# wait until knock launches
while [ -z "`ps cax | grep Knock`" ]; do
sleep 3
done
# wait a bit more
sleep 3
# disable security agent support
lldb <<EOF
attach Knock
@zydeco
zydeco / iCloud.swift
Created July 6, 2015 12:18
iCloud UIBezierPath
let points = [
((-1, 0), (0,0), (13,25)),
((13, 22), (13, 24), (13, 23)),
((23, 12), (13, 17), (17, 12)),
((31, 16), (26, 12), (29, 14)),
((54, 0), (34, 7), (43, 0)),
((78, 24), (67, 0), (78, 11)),
((78, 27), (78, 25), (78, 26)),
((79, 27), (78, 27), (78, 27)),
((94, 42), (87, 27), (94, 33)),
@zydeco
zydeco / liconv.rb
Created October 6, 2015 14:01
line-based iconv with fallback encoding
#!/usr/bin/env ruby
# iconv line by line with fallback encoding
require 'optparse'
options = {
from: Encoding::UTF_8,
to: Encoding::UTF_8,
fallback: Encoding::ISO_8859_1
}
@zydeco
zydeco / EUMShowTouch.m
Created May 17, 2016 20:28
single file drop-in version of eumlab/EUMTouchPointView
/*
EUMShowTouchDropIn
single-file drop-in version
Copyright (c) 2014 Shawn Xiao <[email protected]>
Copyright (c) 2016 Jesús A. Álvarez <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@zydeco
zydeco / reenumerate.c
Created March 7, 2017 12:30
Simulate unplugging and plugging in of usb device
// cc reenumerate.c -framework IOKit -framework CoreFoundation -o reenumerate
#include <stdio.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/usb/IOUSBLib.h>
#include <mach/mach.h>
#define kExcAccMaxWait 5