Skip to content

Instantly share code, notes, and snippets.

@lqik2004
lqik2004 / gist:5140017
Last active December 14, 2015 19:58
Check China Phone Number
- (BOOL)isMobileNumber:(NSString *)mobileNum
{
/**
* 手机号码
* 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
* 联通:130,131,132,152,155,156,185,186
* 电信:133,1349,153,180,189
*/
NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
/**
@lqik2004
lqik2004 / Gemfile
Created February 21, 2013 07:57 — forked from thbar/Gemfile
source 'http://rubygems.org'
gem 'rails', '3.2.x'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "3.2.5"
gem 'coffee-rails', "3.2.2"
gem 'uglifier', '1.2.4'
@lqik2004
lqik2004 / gist:4223499
Created December 6, 2012 10:21
惯性滚动
if (recognizer.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [recognizer velocityInView:self.view];
CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y));
CGFloat slideMult = magnitude / 200;
NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult);
float slideFactor = 0.1 * slideMult; // Increase for more of a slide
CGPoint finalPoint = CGPointMake(recognizer.view.center.x + (velocity.x * slideFactor),
recognizer.view.center.y + (velocity.y * slideFactor));
@lqik2004
lqik2004 / gist:4155096
Created November 27, 2012 16:04
从真实GPS坐标获取百度地图坐标
CLLocationManager获取的坐标是由google坐标系得到的坐标,转化为百度坐标系百度有在官方API未公开实际存在的接口做转换。
/**
*坐标转换函数,从原始GPS坐标,mapbar坐标转换成百度坐标
*@param coorWgs84 待转换的原始GPS坐标,或者mapbar的坐标
*@return 返回的NSDictionry中包含“x”,“y”字段,各自对应经过base64加密之后的x,y坐标
*/
UIKIT_EXTERN NSDictionary* BMKBaiduCoorForWgs84(CLLocationCoordinate2D coorWgs84);
/**
*坐标转换函数,从google坐标,51地图坐标,mapabc坐标转换为百度坐标(51地图坐标需要显出10000)
@lqik2004
lqik2004 / gist:3780365
Created September 25, 2012 06:56
getRelativePath
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import decimal
path1='/Users/liuchao/Desktop/hah.mp3'
paht2='/Users/liuchao/Desktop/EZ/EzRead.py'
def get_Relative_Path(path1,path2):
@lqik2004
lqik2004 / gist:3616362
Created September 4, 2012 03:55
Convert Text2Mobi
#!/bin/bash
bangzhu (){
cat << EOF
用法: `basename $0` 文件名 [书名] [作者]
其中文件名是必须的,书名、作者什么的可以不添加,书名默认为文件名。作者则留空。至于出版社什么的就都浮云了。其实修改也很简单,但是我不需要所以就从简了。
EOF
}
@lqik2004
lqik2004 / gist:3606931
Created September 3, 2012 05:25
GetPixelColorAtLocation
- (UIColor *) getPixelColorAtLocation:(CGPoint)point {
UIColor* color = nil;
CGImageRef inImage = self.image.CGImage;
// Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
if (cgctx == NULL) {
return nil; /* error */
}
size_t w = CGImageGetWidth(inImage);
@lqik2004
lqik2004 / gist:3345155
Created August 14, 2012 00:34
AutoScroll
#pragma mark -KeyBoard Notifications
-(void) registerForKeyBoardNotification{
//键盘出现时发出信息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
//键盘消失时发出信息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
//called when uikeyboarddidshownotification is sent.
-(void)keyboardWasShown:(NSNotification *)noti{
@lqik2004
lqik2004 / gist:3255863
Created August 4, 2012 08:21
git pbxproj
#!/bin/sh
projectfile=`find -d . -name 'project.pbxproj'`
projectdir=`echo *.xcodeproj`
projectfile="${projectdir}/project.pbxproj"
tempfile="${projectdir}/project.pbxproj.out"
savefile="${projectdir}/project.pbxproj.mergesave"
cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
@lqik2004
lqik2004 / gist:3159157
Created July 22, 2012 10:05
Custom CoreText Fonts
NSString *fontPath = [[NSBundle mainBundle] pathForResource:_fontName ofType:@"otf"];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fontPath UTF8String]);
// 从DataProvider创建字体
CGFontRef theCGFont =CGFontCreateWithDataProvider(fontDataProvider);
CTFontRef theCTFont=CTFontCreateWithGraphicsFont(theCGFont,_fontSize,NULL,NULL);
CFRelease(theCGFont);
CFRelease(fontDataProvider);
//创建AttributeString
attrString=[[NSMutableAttributedString alloc]initWithString:self.text];
//设置字体及大小