Skip to content

Instantly share code, notes, and snippets.

🌴
On vacation

DreamPiggy dreampiggy

🌴
On vacation
Block or report user

Report or block dreampiggy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dreampiggy
dreampiggy / .wakeup
Created Aug 11, 2016 — forked from ralph089/.wakeup
Restarts Bluetooth Module on Mac OS X El Capitan. You can use the script as shortcut to restart Bluetooth on demand or you can use it with "SleepWatcher" to automatically restart Bluetooth on wakeup (See README.md). I created it, because my Logitech Bluetooth Mouse doesn't stay connected after sleep-mode, so i had to manually re-pair my mouse.
View .wakeup
#!/bin/bash
#
# Restart Bluetooth Module on Mac OS X
#
# Requires Blueutil to be installed: http://brewformulas.org/blueutil
BT="/usr/local/bin/blueutil"
log() {
echo "$@"
@dreampiggy
dreampiggy / SpinlockTestTests.swift
Created Oct 19, 2016 — forked from steipete/SpinlockTestTests.swift
Updated for Xcode 8, Swift 3; added os_unfair_lock
View SpinlockTestTests.swift
//
// SpinlockTestTests.swift
// SpinlockTestTests
//
// Created by Peter Steinberger on 04/10/2016.
// Copyright © 2016 PSPDFKit GmbH. All rights reserved.
//
import XCTest
@dreampiggy
dreampiggy / linkmap.js
Created Nov 28, 2016 — forked from bang590/linkmap.js
XCode Linkmap Parser
View linkmap.js
var readline = require('readline'),
fs = require('fs');
var LinkMap = function(filePath) {
this.files = []
this.filePath = filePath
}
LinkMap.prototype = {
start: function(cb) {
@dreampiggy
dreampiggy / StringSwitchMacro.h
Created Apr 13, 2017
Objective-C NSString Switch Case Macro
View StringSwitchMacro.h
#ifndef TTD_SWITCH_STRING
#define TTD_SWITCH_STRING
#define TTD_CASE(str) if ([__s__ isEqualToString:(str)])
#define TTD_SWITCH(s) for (NSString *__s__ = (s); ; )
#define TTD_DEFAULT
#endif
@dreampiggy
dreampiggy / GCDMacro.h
Created Apr 13, 2017
GCD main queue Macro
View GCDMacro.h
#ifndef dispatch_main_sync_safe
#define dispatch_main_sync_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}
#endif
#ifndef dispatch_main_async_safe
View PSPDFFastEnumeration.h
//
// PSPDFFastEnumeration.h
// PSPDFFoundation
//
// PSPDFKit is the leading cross-platform solution for integrating PDFs into your apps: https://pspdfkit.com.
// Try it today using our free PDF Viewer app: https://pdfviewer.io/
//
// This file is MIT licensed.
@protocol PSPDFFastEnumeration <NSFastEnumeration>
View iOS-Hit-Testing.m
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (!self.isUserInteractionEnabled || self.isHidden || self.alpha <= 0.01) {
return nil;
}
if ([self pointInside:point withEvent:event]) {
for (UIView *subview in [self.subviews reverseObjectEnumerator]) {
CGPoint convertedPoint = [subview convertPoint:point fromView:self];
UIView *hitTestView = [subview hitTest:convertedPoint withEvent:event];
if (hitTestView) {
return hitTestView;
@dreampiggy
dreampiggy / QuickSort.m
Created Jun 17, 2016
QuickSort-Objective-C
View QuickSort.m
void quicksortInPlace(NSMutableArray *array, NSInteger first, NSInteger last, NSComparator comparator) {
if (first >= last) return;
id pivot = array[(first + last) / 2];
NSInteger left = first;
NSInteger right = last;
while (left <= right) {
while (comparator(array[left], pivot) == NSOrderedAscending)
left++;
while (comparator(array[right], pivot) == NSOrderedDescending)
right--;
@dreampiggy
dreampiggy / cli-nsrunloop.m
Created Mar 29, 2019 — forked from syzdek/cli-nsrunloop.m
Creating an NSRunLoop for a command line utility.
View cli-nsrunloop.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
NSRunLoop * runLoop;
CLIMain * main; // replace with desired class
@autoreleasepool
{
// create run loop
View decode-dyn-uti.swift
extension String
{
/// Creates a string by decoding a sequence of UTF-8 code units.
init?<S: Sequence>(utf8 input: S) where S.Iterator.Element == UTF8.CodeUnit {
var chars: [Character] = []
var decoder = UTF8()
var iter = input.makeIterator()
loop: while true {
switch decoder.decode(&iter) {
case .scalarValue(let scalar): chars.append(Character(scalar))
You can’t perform that action at this time.