Skip to content

Instantly share code, notes, and snippets.

@siqin
siqin / FYSMysql.php
Created March 3, 2012 10:16
Simple PHP2MySQL Class
<?php
/*
* FYSMysql.php Created on 2012-3-3
* By Jason Lee
*
* 后面可以考虑抽象成模型,每个表对应一个Model子类,自动探测表结构,把错误检查放在Model中
*
*/
class FYSMysql {
@siqin
siqin / localizeString.py
Created March 3, 2012 10:17
Localization The Objective-C Code
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Localization The Objective-C Code
@"..." --> NSLocalizedString(@"...", nil)
Jason Lee 2012-03-01
'''
import os, sys
@siqin
siqin / gcd.m
Created March 9, 2012 03:02 — forked from simme/gcd.m
Loading images async with GCD
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSString *tweetText = [_tweet valueForKey:@"text"];
NSString *userName = [_tweet valueForKeyPath:@"user.name"];
NSString *userDescription = [_tweet valueForKeyPath:@"user.description"];
NSNumber *friends = [_tweet valueForKeyPath:@"user.friends_count"];
NSNumber *followers = [_tweet valueForKeyPath:@"user.followers_count"];
@siqin
siqin / RemoveMultipleSpaces.cs
Created April 1, 2012 14:49 — forked from Ninputer/RemoveMultipleSpaces.cs
模拟微面试之去空格
//请实现下面的函数,输入参数baseStr是一个(可以更改的)字符串,请将其中所有连续出现的多个空格都替换成一个空格,单一空格需保留。
//请直接使用baseStr的空间,如需开辟新的存储空间,不能超过o(N)(注意是小o,N是字符串的长度)。返回值是替换后的字符串的长度。
//样例代码为C#,但可以使用任何语言。如需使用任何库函数,必须同时给出库函数的实现。
class Program
{
public static int RemoveMultipleSpaces(char[] baseStr)
{
if (baseStr == null)
{
throw new ArgumentNullException("baseStr");
// Please write an sequence list implements the interface with the required
// time complexity described in the comments. The users can add the same
// element as many times as they want, but it doesn't support the null item.
// You can use any types in .NET BCL but cannot use any 3rd party libraries.
// PS: You don't need to consider the multi-threaded environment.
interface IMyList<T> : IEnumerable<T>
{
// O(1)
// Add an item at the beginning of the list.
void AddFirst(T item);
@siqin
siqin / gist:2923259
Created June 13, 2012 10:20 — forked from nyoron/gist:363423
Some sample code for a horizontal paged UIScrollView with a gap between each image, like Photos.app (which looks nicer when paging).
/*
Some sample code for a horizontal paged UIScrollView with a gap between each image (which looks nicer). Note - not using contentInset, we want each page to fill the iPhone screen and the gap only to be visible when scrolling (like Photos.app).
Taking the iPhone status bar into account - our viewport is 320x460
Our UIScrollView is therefore set in Interface Builder to 340x460 with a -10 X offset (so it's larger than the viewport but still centred)
Then we do the following...
*/
// Our image filenames
//
// NSObject+PropertyListing.h
// PropertyFun
//
// Created by Andrew Sardone on 8/27/10.
//
#import <Foundation/Foundation.h>
@siqin
siqin / gist:3081582
Created July 10, 2012 06:30
log of objective-c
#pragma mark -
#define DEFAULT_LOG_FILENAME @"log.log"
- (void)log:(NSString *)log
{
#ifdef DEBUG
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *baseDir = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *logPath = [baseDir stringByAppendingPathComponent:DEFAULT_LOG_FILENAME];
@siqin
siqin / routeOnMap.m
Created July 25, 2012 08:17
Draw route on MKMapView
#pragma mark -
- (void)drawTestLine
{
// test code : draw line between Beijing and Hangzhou
CLLocation *location0 = [[CLLocation alloc] initWithLatitude:39.954245 longitude:116.312455];
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:30.247871 longitude:120.127683];
NSArray *array = [NSArray arrayWithObjects:location0, location1, nil];
[self drawLineWithLocationArray:array];
}
@siqin
siqin / quicksort.py
Created August 8, 2012 09:41
Python QuickSort
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import random
global compareCount
def swap(arr, l, r):
temp = arr[l]
arr[l] = arr[r]