Skip to content

Instantly share code, notes, and snippets.

@yangyi
yangyi / gist:47008c51c37694a5e2695d9b1ff01152
Created May 7, 2017 07:32
从写卡片开始构建自己的知识系统
知识系统分为三个层次
* 书籍
* 文章
* 卡片
自己的知识分享 从片段的卡片开始,这样降低输出的门槛。
一开始,可以坚持写三张卡片: 反常识卡,人名卡,术语卡。
import com.querydsl.jpa.impl.JPAQuery;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.GraphQLList;
import graphql.schema.GraphQLObjectType;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.Value;
@yangyi
yangyi / reactor pattern.md
Created March 25, 2016 17:01
Reactor Pattern

高性能的服务器,Reactor 是一种非常见的模式。Nginx, NodeJS, eventmachine, twisted 都使用了这种模式来实现高性能的服务器。

  • 为什么 Reactor 能够实现高性能服务器?
  • 怎么实现 Reactor?
  • Reactor 到底是同步还是异步?

为什么 Reactor 能实现高性能的服务器?

TLTR

@yangyi
yangyi / build.grade
Created December 26, 2015 15:41
basic spring-boot project with lombok support build.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE")
classpath "gradle.plugin.net.franz-becker:gradle-lombok:1.5"
@yangyi
yangyi / .gitignore
Created December 26, 2015 15:36
git ignore for java spring app
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
@yangyi
yangyi / 0_reuse_code.js
Created December 16, 2015 02:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yangyi
yangyi / CoreImageAndVideoTest.swift
Last active January 31, 2016 18:55
read video and process using core image
import Foundation
import AVFoundation
import CoreImage
protocol SequenceReadable {
func readNext() -> CIImage
}
protocol YMSticky {
func stickOn(background: YMImage) -> YMImage
-(AVVideoComposition *)squareCropperVideoComposition:(AVAssetTrack *)clipVideoTrack {
AVMutableVideoComposition * videoComposition = [AVMutableVideoComposition videoComposition];
CGSize originVideoSize = clipVideoTrack.naturalSize;
CGFloat shortSideLength = MIN(originVideoSize.width, originVideoSize.height);
CGFloat longSideLength = MAX(originVideoSize.width, originVideoSize.height);
CGFloat renderSideLength = 640.0; // MIN(640.0, shortSideLength);
CGFloat scale = renderSideLength / shortSideLength;

原则

  1. 代码看上去很清楚在做什么事情. 不要写注释来说明程序在做什么, 而是要把程序逻辑写的非常清楚.

    a. 为啥isPlaying了还要play()呢?

     	public boolean movePrevious()
     	{
    

if(playIndex > 0)

/* sample code, 实现不完整. 可能要用service实现, 但是接口相同 */
// 先不用去想怎么实现, 先想我在Activity和UI会怎么用 audio player
// 1. 因为需要能够自动切换到下一首, 所以生成播放器需要一个播放列表
// 2. 在播放的时候, UI需要根据播放器的状态显示不同的UI, 所以需要监听AudioPlayer的状态
// 3. 因为需要能够播放任意一首歌曲, 需要play(int index)
public class AudioListPlayer {
// 我们在UI上只需要这四个状态, 那么就只监听这些状态