Skip to content

Instantly share code, notes, and snippets.

@ruandao
ruandao / 录音权限检测.m
Created November 21, 2014 07:05
录音权限检测
AVAudioSession* session = [AVAudioSession sharedInstance];
if ([session respondsToSelector:@selector(requestRecordPermission:)]) {
[session performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
if (granted) {
// Microphone enabled code
NSLog(@"Microphone is enabled..");
dispatch_async(dispatch_get_main_queue(), ^{
if (!self.recordBtn.selected) {
@ruandao
ruandao / gist:919ce3bb59f9073204d9
Created April 22, 2015 08:14
swift method swizzle
public override class func initialize() {
struct Static {
static var token: dispatch_once_t = 0
}
if self !== RCChatListViewController.self {
return
}
@ruandao
ruandao / swizzle
Created April 22, 2015 08:14
swift method swizzle
public override class func initialize() {
struct Static {
static var token: dispatch_once_t = 0
}
if self !== RCChatListViewController.self {
return
}
@ruandao
ruandao / RACBridge
Created April 27, 2015 02:55
rac bridge
import Foundation
public struct RAC {
var target: NSObject
var keyPath: String
var nilValue: AnyObject?
public init(_ target: NSObject, _ keyPath: String, nilValue: AnyObject? = nil) {
@ruandao
ruandao / x.js
Last active September 15, 2015 13:25
// 迭代
function fib(n) {
function fib-iter(i,n_1, n_2, n) {
if 0 == n {
return 0
}
if 1 == n {
return 1
}
if i == n {
@ruandao
ruandao / p2p 借钱 下载.txt
Created September 22, 2015 11:01
p2p 借钱 下载
p2p下载,
你只能向你的朋友借流量,
你可以查看你向谁借了多少流量,
你借给谁多少流量,
你的朋友可能为了你向他的朋友借流量,
当你要下载时,
你会向你的朋友借流量,
你的朋友查看本地是否有这个文件,
没有的话,
他可以帮你下载一部分文件,
@ruandao
ruandao / post-receive.sh
Last active November 7, 2015 10:46 — forked from icyleaf/post-receive.sh
git autodeploy script when it matches the string "[deploy]"
#!/bin/sh
#
# git autodeploy script when it matches the string "[deploy]"
#
# @author icyleaf <icyleaf.cn@gmail.com>
# @link http://icyleaf.com
# @version 0.1
#
# Usage:
# 1. put this into the post-receive hook file itself below
"use strict";
var koa = require('koa');
var app = koa();
var bodyParser = require('koa-bodyparser');
var fs = require('fs');
app.use(bodyParser());
@ruandao
ruandao / 2.64.rkt
Last active November 29, 2015 12:08
sicp 2.64 构建平衡二叉树
;#lang planet neil/sicp
#lang racket
(require (planet soegaard/sicp:2:1/sicp))
(define wave einstein)
(define (list-tree elements)
(car (partial-tree elements (length elements))))
(define (partial-tree elts n)
(if (= n 0)
@ruandao
ruandao / 2.65.rkt
Created November 30, 2015 00:43
sicp 2.65 求O(n) 的union-set 以及 intersection-set 操作
;#lang planet neil/sicp
#lang racket
(require (planet soegaard/sicp:2:1/sicp))
(define wave einstein)
(define (union-set set1 set2)
(define (union-list l1 l2)
(cond ((null? l1) l2)
((null? l2) l1)