Skip to content

Instantly share code, notes, and snippets.

View MattyAyOh's full-sized avatar

Matt Ao MattyAyOh

View GitHub Profile
@MattyAyOh
MattyAyOh / logUndoStack.m
Created December 8, 2015 16:01
Log out the undo and redo stack on an NSUndoManager using objc/runtime to access private ivars
@try
{
NSUndoManager* undoManager = [self undoManager];
id undostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], "_undoStack"));
id redostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], "_redoStack"));
NSLog(@"%@",[NSString stringWithFormat:@"(%lu entries) %@", (unsigned long)[undostack count], [undostack description]]);
NSLog(@"%@",[NSString stringWithFormat:@"(%lu entries) %@", (unsigned long)[redostack count], [redostack description]]);
}
@MattyAyOh
MattyAyOh / removeEmptyUndoGroup.m
Created January 4, 2016 18:33
Remove empty undo group
id undostack = object_getIvar(undoManager, class_getInstanceVariable([NSUndoManager class], NEVER_TRANSLATE("_undoStack")));
id headAction = object_getIvar(undostack, class_getInstanceVariable([undostack class], NEVER_TRANSLATE("_head")));
id nextAction = object_getIvar(headAction, class_getInstanceVariable([headAction class], NEVER_TRANSLATE("next")));
const char *beginGroupName = NEVER_TRANSLATE("_NSUndoBeginMark");
const char *nextActionName = object_getClassName(nextAction);
if( strcmp(beginGroupName,nextActionName) == 0 )
{
[undoManager undo];
}
@MattyAyOh
MattyAyOh / reverseInteger.py
Created January 4, 2016 18:35
Reverse an integer in Python in place
inputNum = 1234
reverseNum = 0
while inputNum > 0:
reverseNum = (reverseNum*10) + (inputNum%10)
inputNum = inputNum/10
print reverseNum
@MattyAyOh
MattyAyOh / removeDuplicateNodes.py
Last active August 26, 2016 21:11
Remove nodes with duplicate values from a singly-linked list
# Write a function that takes a head node;
# then iterates through a singly-linked list starting from the head node, and remove any nodes that have duplicate values
class Node():
def __init__(self, value):
self.value = value
self.next = None
myNode1 = Node(1)
@MattyAyOh
MattyAyOh / powerOneHundred.py
Created January 4, 2016 18:37
Single Digit to the Exponent of 100
# Write a method that takes a single integer and prints that integer to the power of 100
firstNum = 3
numArray = [firstNum]
for i in range(0,99):
previousCarry = 0
lastValue = 0
lengthOfArray = len(numArray)
for j in range(0,lengthOfArray):
newProduct = firstNum * numArray[j] + previousCarry
@MattyAyOh
MattyAyOh / SymbolicBreakpoints
Created January 13, 2016 13:40
How to set symbolic breakpoints to identify when an object is registered/unregistered to NSNotificationCenter
-[NSNotificationCenter addObserver:selector:name:object:]
and
-[NSNotificationCenter addObserverForName:object:queue:usingBlock:]
With the condition:
(BOOL)[@"fractionCompleted" isEqualToString:(id)$r8]
and
(BOOL)[@"fractionCompleted" isEqualToString:(id)$rdx]
@MattyAyOh
MattyAyOh / substring.py
Last active September 30, 2016 14:19
Determine if a string is a substring of another string
#NOTE: #### denotes additions to the code between questions
#Find the length of a string
#Nerf toss question to warm them up
#Write a function that takes two strings, and find if the first string contains the second string
def findSubstring( main, sub ):
import csv
import requests
GITHUB_USER = ''
GITHUB_PASSWORD = ''
REPO = 'TechSmith/Snagit' # format is username/repo
ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/techsmith/snagit/issues?state=closed&labels=Bug'
AUTH = (GITHUB_USER, GITHUB_PASSWORD)
import csv
import requests
import re
try:
from bs4 import BeautifulSoup
except ImportError:
from BeautifulSoup import BeautifulSoup
g2URL = 'https://www.g2crowd.com/products/snagit/reviews?page='
@MattyAyOh
MattyAyOh / AutocorrectDescription
Last active April 5, 2017 20:26
Autocorrect Program Description
Write a text autocorrect app
We provide small dictionary (100 words)
Project Specifications:
Write an application that takes a string, and has a button that tells you if the word is valid or not.
We will provide a dictionary, with valid words delimited by newlines.
If the word is not valid, display a suggested word and give the user an option to change their word to the suggested word.
Add a button that adds the current inputted word into the dictionary