Skip to content

Instantly share code, notes, and snippets.

View chuyihuang's full-sized avatar

Bamboo Huang chuyihuang

View GitHub Profile
@chuyihuang
chuyihuang / lang_mapping.rb
Created July 13, 2017 14:45
在model/concern中加入enum與對應語言的方法
# In model:
# include LangMapping
#
# lang_map({
# status: [[:enabled, 1, "啟動"], [:disabled, 2, "取消"], [:unauthenticated, 0, "註冊中"]],
# user_type: [[:standard, 0, "標準"], [:vip, 1, "高級"], [:vvip, 2, "最高級"], [:admin, 3, "管理員"]]
# })
# 會產生 class methods: all_xxxxs, instance methods: show_xxxx 2個方法
# 例如 user.show_status 會出現"啟動"、"取消"或"註冊中"
@chuyihuang
chuyihuang / taiwanZone.js
Created July 1, 2017 13:12
台灣縣市郵遞區號
{ '基隆市': ​​​​​
​​​​​ [ '仁愛區200',​​​​​
​​​​​ '信義區201',​​​​​
​​​​​ '中正區202',​​​​​
​​​​​ '中山區203',​​​​​
​​​​​ '安樂區204',​​​​​
​​​​​ '暖暖區205',​​​​​
​​​​​ '七堵區206' ],​​​​​
​​​​​ '臺北市': ​​​​​
​​​​​ [ '中正區100',​​​​​
@chuyihuang
chuyihuang / picture_uploader.rb
Created January 12, 2017 14:42
carrierwave uploader example
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
@chuyihuang
chuyihuang / gist:a7fd63e74a0fbd5d0161d9f98fc0232d
Created October 4, 2016 10:24
使用IOS 10 / XCODE 8 遇到 libsystem_kernel.dylib`__abort_with_payload 的問題
存取照片或相機時可能會遇到,通常是權限的問題,所以在info.plist中增加額外的key來處理
1. 增加 Privacy - Camera Usage Description, value的部分寫個為何要使用的理由
2. 增加 Privacy - Photo Library Usage Description, value的部分寫個為何要使用的理由
@chuyihuang
chuyihuang / gist:9678ef573dd4a8688b6e56a5667b76a3
Created September 30, 2016 04:15
徹底移除atom的指令清單 completely remove atom from your MAC
rm -rf ~/.atom
rm -rf /usr/local/bin/atom
rm -rf /usr/local/bin/apm
rm -rf /Applications/Atom.app
rm -rf ~/Library/Preferences/com.github.atom.plist
rm -rf ~/Library/Application Support/com.github.atom.ShipIt
rm -rf ~/Library/Application Support/Atom
rm -rf ~/Library/Saved Application State/com.github.atom.savedState
rm -rf ~/Library/Caches/com.github.atom
rm -rf ~/Library/Caches/Atom
@chuyihuang
chuyihuang / gist:07bb9072ea75cdf36148af7463a48f6b
Created September 26, 2016 07:27
mac安裝mongodb後自動啟動 | mongodb auto start after installation
1. 用brew install mongoldb
2. 安裝完畢後用ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents 連結
3. 加入自動launch清單 launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
4. 如果都無法啟動的話,可能要檢查log資料夾的權限: /usr/local/var/log/mongodb 改成使用者的
chown -R username mongodb
5. 以及chgrp:
chgrp -R groupname mongodb
@chuyihuang
chuyihuang / order.xls
Created August 30, 2016 10:05
order.xls example
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<Cell><Data ss:Type="String">建立時間</Data></Cell>
@chuyihuang
chuyihuang / main.js
Created August 26, 2016 09:13
invalid_auth when connecting to eventbrite
// https://www.eventbriteapi.com/v3/users/me/?token=SESXYS4X3FJ5LHZRWGKQ
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet
} from 'react-native';
const API_KEY = 'Bearer SESXYS4X3FJ5LHZRWGKQ';
@chuyihuang
chuyihuang / react-native-network-request-fail.md
Last active August 23, 2016 09:19
處理react native network request fail的問題

參考: http://10minbasics.com/react-native-network-request-failed-fix/

First of all, when you try to use the network in your app, you should enable it in XCode.

  1. Click on your project in the Project Navigator
  2. Open the Info tab (打開info.plist檔案)
  3. Right click on App Transport Security Settings and select Add Row
  4. For created row set the key “Allow Arbitrary Loads“, type to boolean and value to YES.
@chuyihuang
chuyihuang / .js
Last active April 9, 2016 03:23
webpack babel example
module.exports = {
entry: "./app.js",
output: {
filename: "./bundle.js"
},
module: {
loaders: [
{
test: /jsx?$/,
exclude: /node_modules/,