Skip to content

Instantly share code, notes, and snippets.

View ytlvy's full-sized avatar

Yt ytlvy

View GitHub Profile
@ytlvy
ytlvy / UISegmentedControl+Flat.h
Created November 11, 2015 06:16 — forked from 123nobody/UISegmentedControl+Flat.h
Set UISegmentedControl to iOS 7 style.
//
// UISegmentedControl+Flat.h
//
// Created by 魏哲 on 14-2-28.
//
#import <UIKit/UIKit.h>
@interface UISegmentedControl (Flat)
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
[UIView setAnimationCurve:[notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue]];
[UIView setAnimationBeginsFromCurrentState:YES];
// do something
[UIView commitAnimations];
@ytlvy
ytlvy / Invoker.h
Created November 11, 2015 06:17 — forked from 123nobody/Invoker.h
#import <Foundation/Foundation.h>
@interface Invoker : NSObject
+ ( NSValue * ) invoke:( SEL ) selector onTarget:( id ) target, ...;
@end
@ytlvy
ytlvy / TimerWithGCD.md
Created November 13, 2015 10:31
Creating a timer with Grand Central Dispatch

##Creating a timer with Grand Central Dispatch

At the following is the implementation file of a sample class that shows, how to make a timer with the help of Grand Central Dispatch. The timer fires on a global queue, just change the queue to the main queue or any custom queue and the timer fires on this queue and not on the global queue anymore.

#import <Foundation/Foundation.h>

@interface SampleClass : NSObject
- (void)startTimer;
@ytlvy
ytlvy / TableViewCell.m
Created November 13, 2015 10:33
iOS 8 workaround for no inset in UITableViewCell separator
// No separator insets
self.separatorInset = UIEdgeInsetsZero;
if ([self respondsToSelector:@selector(layoutMargins)]) {
self.layoutMargins = UIEdgeInsetsZero;
}
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void
segv() // <--- never gets called
{
fprintf(stderr, "segv\n");
exit(0);
@ytlvy
ytlvy / test_access.c
Created December 17, 2015 08:26 — forked from phoeagon/test_access.c
Test whether memory can be accessed
#define _GNU_SOURCE
#include <stdio.h>
#include <udis86.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <ucontext.h>
#include <execinfo.h>
#include <setjmp.h>
@ytlvy
ytlvy / signal_handlers.cpp
Created December 17, 2015 08:28
#signal #cpp #linux
//
// Example of linux signal handlers
//
// Authored by Daniel Shih <[email protected]>
//
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@ytlvy
ytlvy / build-ffmpeg.sh
Created January 4, 2016 02:08 — forked from m1entus/build-ffmpeg.sh
Installing ffmpeg ios libraries armv7, armv7s, i386
#!/bin/bash
###########################################################################
# Choose your ffmpeg version and your currently-installed iOS SDK version:
#
VERSION="2.0.2"
SDKVERSION="7.0"
ARCHS="armv7 armv7s i386"
#
#
@ytlvy
ytlvy / aes128.m
Created January 4, 2016 02:09 — forked from m1entus/aes128.m
AES128 endryption
- (NSData *)AES128EncryptWithData:(NSData *)data {
NSUInteger dataLength = [self length];
//See the doc: For block ciphers, the output size will always be less than or
//equal to the input size plus the size of one block.
//That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);