Skip to content

Instantly share code, notes, and snippets.

View sebastienwindal's full-sized avatar

Sebastien Windal sebastienwindal

View GitHub Profile
@sebastienwindal
sebastienwindal / JNWThrottledBlock.h
Created October 6, 2015 22:28 — forked from jwilling/JNWThrottledBlock.h
Simple throttling of blocks using dispatch sources.
#import <Foundation/Foundation.h>
@interface JNWThrottledBlock : NSObject
// Runs the block after the buffer time _only_ if another call with the same identifier is not received
// within the buffer time. If a new call is received within that time period the buffer will be reset.
// The block will be run on the main queue.
//
// Identifier and block must not be nil.
+ (void)runBlock:(void (^)())block withIdentifier:(NSString *)identifier throttle:(CFTimeInterval)bufferTime;
@sebastienwindal
sebastienwindal / htmlTemplate.html
Created September 20, 2012 02:10
My modified html template for the iA writer on the mac.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>__IAWRITER_DOCUMENT_TITLE__</title>
<meta name="author" content="__IAWRITER_USER_NAME__">
<meta name="generator" content="iA Writer for Mac __IAWRITER_BUNDLE_VERSION__">
<meta name="description" content="">
<meta name="keywords" content="">
@sebastienwindal
sebastienwindal / WGenServer.h
Created October 29, 2012 15:34
.h file example
//
// WGenServer.h
// WgenTestCommon
//
// Created by Sebastian Windal on 10/24/12.
// Copyright (c) 2012 Sebastian Windal. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "WGenPeer.h"
@sebastienwindal
sebastienwindal / WGenServer.m
Created October 29, 2012 15:35
.m file example
//
// WGenServer.m
// WgenTestCommon
//
// Created by Sebastian Windal on 10/24/12.
// Copyright (c) 2012 Sebastian Windal. All rights reserved.
//
#import "WGenServer.h"
#import "GCDAsyncSocket.h"
@sebastienwindal
sebastienwindal / msg.m
Created October 29, 2012 15:51
messages
// what do you get?
// compile error?
// compile warning?
// runtime crash?
// value X displayed on console.
// 1.
NSString *str1 = @"hello";
NSLog(@"%d", [str1 length]);
@sebastienwindal
sebastienwindal / gist:4125476
Created November 21, 2012 15:34
bad practire
- (IBAction)myButtonAction:(id)sender {
UIButton *myButton = (UIButton *) sender;
if (myButton.tag == 1) {
// do X
}
else if (myButton.tag == 2) {
// do Y
}
else if (myButton.tag == 3) {
@implementation MyView2
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@implementation ViewController3
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
|I Want to:|init(s)|lazy loading|viewDidLoad|viewWillAppear|
|----------|-------|------------|-----------|--------------|
|Initialize obj-c objects (array, dictionaries, etc...)| X | | | |
|Initialize C stuff (C buffer, etc...)|X|||||
|Setup UI stuff in code that is not layout related (UILabel fonts, texts, etc...)|||X||
|Adjust layout of elements in code, reposition things around||||X|
@sebastienwindal
sebastienwindal / tableview & collectionview cell "pressed down" effect
Last active October 15, 2015 06:19
Generic starting point to give a (more or less) subtle visual cue a tableview row is being selected.
/// table view
-(void) tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.contentView.alpha = 0.7;
[UIView animateWithDuration:0.15
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut