Skip to content

Instantly share code, notes, and snippets.

View pala's full-sized avatar
🏠
Working from home

Tao Zhang pala

🏠
Working from home
View GitHub Profile
@pala
pala / emptyImage.swift
Created May 24, 2015 05:40
UIImage extension
// https://twitter.com/dwineman/status/601853359839006721
// Default arguments are expressions, not constants, evaluated only when necessary.
extension UIImage {
static func emptyImage(size: CGSize, scale: CGFloat = UIScreen.mainScreen().scale) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
@pala
pala / Singleton.swift
Last active August 29, 2015 14:02
Singleton in Swift
public class var sharedConfiguration: AppConfiguration {
struct Singleton {
static let sharedAppConfiguration = AppConfiguration()
}
return Singleton.sharedAppConfiguration
}
// Checkout Lister: A Productivity App Built in Swift by Apple
@pala
pala / TZReceptionist.h
Created February 10, 2014 19:23
Receptionist Pattern
#import <Foundation/Foundation.h>
typedef void (^RCTaskBlock)(NSString *keyPath, id object, NSDictionary *change);
@interface TZReceptionist : NSObject
+ (id)receptionistForKeyPath:(NSString *)path
object:(id)obj
queue:(NSOperationQueue *)queue
task:(RCTaskBlock)task;
@end
@pala
pala / newpost.rb
Last active December 19, 2015 22:18
to generate a new Jekyll post
#!/usr/bin/env ruby
unless ARGV[0]
puts 'Usage: newpost "the post title"'
exit(-1)
end
date_prefix = Time.now.strftime("%Y-%m-%d")
postname = ARGV[0].strip.downcase.gsub(/ /, '-')
post = "./_posts/#{date_prefix}-#{postname}.md"
@pala
pala / textmate-shortcuts.md
Created July 18, 2013 03:00
TextMate 2 shortcuts
  1. ⌥ + ⌘ + ] Align Assignments
@pala
pala / zshShortcuts.md
Created July 8, 2013 19:53
zsh shortcuts
  • ⌃ + a Move to the beginning of the line.

  • ⌃ + e Move to the end of the line.

  • ⌃ + u Clear the entire line.

  • ⌃ + w Delete the word in front of the cursor.

  • ⌃ + r Search history.

@pala
pala / HM1-prime.js
Last active December 19, 2015 00:28
Coursera: Startup Engineering
#!/usr/bin/env node
var checkprime = function(smallerPrimes, number) {
isprime = 1;
for (var i = 0; i < smallerPrimes.length; i++) {
if (number % smallerPrimes[i] == 0) {
isprime = 0;
break;
}
}
@pala
pala / printFreeMemory.m
Created July 30, 2012 23:15
print free memory on iOS device
#import <mach/mach.h>
#import <mach/mach_host.h>
void print_free_memory ()
{
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
@pala
pala / hack.sh
Created March 31, 2012 17:08 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@pala
pala / RunScript
Created February 3, 2012 20:00
Show TODO's And FIXME's As Warnings In Xcode 4
KEYWORDS="TODO:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"
//via http://deallocatedobjects.com/posts/show-todos-and-fixmes-as-warnings-in-xcode-4