Skip to content

Instantly share code, notes, and snippets.

@safecat
safecat / NSJSONSerialization.swift
Created July 10, 2015 10:02
NSJSONSerialization
//: Playground - noun: a place where people can play
import UIKit
// NSJSONSerialization(iOS5新增) 类似的第三方库有:SBJSON、TouchJSON、YAJL、JSONKit、NextiveJson。
// 可以将JSON数据转为Foundation对象,一般是 NSDictionary 或者 NSArray,或者将Foundation对象转换为JSON数据
// NSJSONReadingOptions
// MutableContainers:转换的来的 NSArray 或 NSDictionary 是 mutable 的
// MutableLeaves:转换来的对象中,叶子节点的 NSString 是 mutable 的
@safecat
safecat / enum.swift
Created July 7, 2015 02:51
Swift 枚举类型
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
// Enum 类型的名称和成员值都应当以大写开头
enum status{
case ok
@safecat
safecat / closure.swift
Created July 7, 2015 02:01
Swift 闭包学习
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
var names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]
// 普通函数
func desc(s1 : String, s2 : String) -> Bool {
@safecat
safecat / func.swift
Last active August 29, 2015 14:24
Swift 函数学习
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
// 函数和返回值
func getUserName(id: Int) -> String {
return "xxy";
}
@safecat
safecat / gist:e7bee1345085cecd5ca3
Last active August 29, 2015 14:24
从mysqldump导出的sql文件中移除一些数据库
# 第一步,找出所有库所在的行号
cat all_databases.sql |grep -n "Current Database"
#返回
422:-- Current Database: `data_platform`
8094:-- Current Database: `mysql`
13013:-- Current Database: `test`
13045:-- Current Database: `test_insert`
13085:-- Current Database: `test_l5`
# 第二步,确认要移除的库:mysql
@safecat
safecat / gist:f450ce5ed5a51b3b6f32
Last active July 28, 2022 11:24
ApacheBench for Mac
# ATTENTION PLEASE!
# NOTE BY @riwazp7
# Note for future visitors of this gist: Mac OS has Apache Benchmark by default ab --help
curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
tar -xzf libtool-2.4.2.tar.gz
cd libtool-2.4.2
./configure && make && sudo make install
# brew install 'https://raw.github.com/simonair/homebrew-dupes/e5177ef4fc82ae5246842e5a544124722c9e975b/ab.rb'
@safecat
safecat / gist:2be1248ea09277189a3c
Last active August 29, 2015 14:19
Tengine Installation
# Update aptitude
sudo -s
apt-get update
apt-get install libpcre3-dev libssl-dev # openssl
# Download Tengine
wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz
tar zxvf tengine-2.1.0.tar.gz
cd tengine-2.1.0
Add following towards bottom
```
### IMPROVE SYSTEM MEMORY MANAGEMENT ###
# Increase size of file handles and inode cache
fs.file-max = 2097152
# Do less swapping
vm.swappiness = 10
vm.dirty_ratio = 60
@safecat
safecat / gist:c5686a9978f844a75034
Last active August 29, 2015 14:06
Install php5-redis for ubuntu 12.04
sudo -s
cd /opt
git clone https://github.com/nicolasff/phpredis.git
cd phpredis
phpize
./configure #--enable-redis-igbinary
make && make install
@safecat
safecat / gist:ecf5ea254ef4d15f97f0
Created September 2, 2014 06:00
uetime 个性化日期显示
<?php
/**
* 个性化日期显示
* @static
* @access public
* @param datetime $times 日期
* @return string 返回大致日期
* @example 示例 ueTime('')
* @author http://segmentfault.com/q/1010000000650101
*/