Skip to content

Instantly share code, notes, and snippets.

@damonYuan
damonYuan / Node_01.js
Last active November 20, 2015 03:49 — forked from ricardobeat/mongoose-indexing.js
MongoDB - test compound indexes on embedded documents
var mongoose = require('mongoose')
, Schema = mongoose.Schema
mongoose.connect('mongodb://localhost/identities');
var IdentitySchema = new Schema({
type : { type: String, enum: ['twitter', 'facebook', 'google'] }
, uid : { type: String }
})
@damonYuan
damonYuan / iOS_01.txt
Last active November 20, 2015 03:48
customization of UISearchController
if there is some UIComponent above your UISearchbar, when searching the cancel button and clear button will not responding to touch event when
self.searchController.dimsBackgroundDuringPresentation = false
In order to make it work properly, you must turn
self.searchController.dimsBackgroundDuringPresentation = true
@damonYuan
damonYuan / swift_01.txt
Last active November 20, 2015 03:48
Shared UIViewController init
prevent duplicate code in swift initiators
init(withChannel channel: PHOChannelDataModel?) {
if let channel = channel {
photos = channel.channelPhotos
} else {
photos = [PHOPhotoPresenter]()
}
super.init(nibName: nil, bundle: nil)
}
@damonYuan
damonYuan / app_build.gradle
Created March 3, 2016 05:12 — forked from almozavr/app_build.gradle
Workaround to bypass library's BuildConfig.DEBUG (always true, always release build type) via custom variable
// Application
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
package com.dotp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
@damonYuan
damonYuan / node-on-ec2-port-80.md
Created March 29, 2016 04:53 — forked from kentbrew/node-on-ec2-port-80.md
How I Got Node.js Talking on EC2's Port 80

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

}).listen(80);
@damonYuan
damonYuan / Enhance.js
Created May 18, 2016 21:38 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@damonYuan
damonYuan / renderRoute.js
Last active November 29, 2018 08:16
react server side rendering without redux (server side)
// Helper function: Loop through all components in the renderProps object // and returns a new object with the desired key
let getPropsFromRoute = (renderProps, componentProps) => {
let props = {};
let lastRoute = renderProps.routes[-1];
renderProps.routes.reduceRight((prevRoute, currRoute) => {
componentProps.forEach(componentProp => {
if (!props[componentProp] && currRoute.component[componentProp]) {
props[componentProp] = currRoute.component[componentProp];
}
});
@damonYuan
damonYuan / client.js
Created August 5, 2016 15:15
react server side rendering without redux (client side)
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory, useRouterHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import { configureStore } from './app/SpreeReactStore';
import routes from './app/routes';
let state = window.__initialState__ || undefined;
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software