Skip to content

Instantly share code, notes, and snippets.

View 1c7's full-sized avatar

ZhengCheng 1c7

View GitHub Profile
@1c7
1c7 / Vue, v-for, display special element in certain position.pug
Last active September 4, 2018 03:23
Vue, v-for, display special element in certain position
// This is written in Pug syntax. not HTML. but same thing. Pug would compile to HTML
template(v-for='(l, index) in list')
topic-card(:topic='t', :key='t.id')
template(v-if='index == 2')
// [IMPORTANT: display your specifial element here]
@1c7
1c7 / extract base64 <img> to image file
Last active August 31, 2018 11:06
Fix accidentally store base64 img into database
http://1c7.me/2018-8-31-fix-base64-img-in-database-to-url/
@1c7
1c7 / ant-design-pro-route-example.js
Last active August 28, 2018 13:19
Ant-Design-Pro 路由跳转例子(2018-8-26)
import { routerRedux } from 'dva/router';
export default class Analysis extends Component {
// ==============
toUserList = () => {
const { dispatch } = this.props;
dispatch(routerRedux.push('/list/user-list'));
};
// ==============
render(){
@1c7
1c7 / img-src-to-image-file.py
Last active August 27, 2018 10:59
HTML <img src="data:image/jpeg;base64"> to Image file using Python 3
# Python 3
import base64
# Fill in this
base64_string = 'data:image/jpeg;base64, ...etc..'
array = url.split('data:image/jpeg;base64,')
base64_naked = array[1]
imgdata = base64.b64decode(base64_naked)
with open('haha.jpg', 'wb') as f:
@1c7
1c7 / upload.js
Created August 11, 2018 02:51
七牛图片上传 Promise 写法-2018-8-11
// 负责上传文件
import API_common from '@/api/common'
// 上传文件到七牛
// 这个函数用到了另外2个函数:get_upload_token, qiniu_upload
function upload(user_id, file, progress_callback){
return new Promise(function (resolve, reject) {
get_upload_token().then(token=>{
resolve(token);
@1c7
1c7 / Download Youtube Video
Created July 8, 2018 07:57
youtube-dl Download Youtube Video
## What you need
1. youtube-dl
2. aria2
3. Proxy(if you live in Country like China)
## Run this in command line
export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;
youtube-dl --external-downloader aria2c --external-downloader-args "-x 16 -k 1M" https://www.youtube.com/watch?v=rAeN7TdGq4o
@1c7
1c7 / Vue.js String truncate filter.js
Created July 6, 2018 09:21
truncate string filter for Vue.js
Vue.filter('fm-truncate', function (value, length) {
if (!value) return ''
value = value.toString()
if(value.length > length){
return value.substring(0, length) + "..."
}else{
return value
}
})
@1c7
1c7 / proxy
Last active July 8, 2018 07:58
Command line proxy
```bash
set http_proxy=http://127.0.0.1:1080;export https_proxy=http://127.0.0.1:1080;
```
@1c7
1c7 / react-native-0.51-save-image-from-app-to-local.js
Last active January 17, 2018 14:26
(React Native 0.51) save image file from App to Local(no network request)
import RNFetchBlob from 'react-native-fetch-blob';
import RNFS from'react-native-fs';
let dirs = RNFetchBlob.fs.dirs
const file_path = dirs.DCIMDir + '/' + 'wechat.jpg';
RNFS.copyFileAssets('wechat.jpg', file_path)
.then(() => {
RNFetchBlob.fs.scanFile([{ path: file_path }])
})
.catch((error) => console.log(error));
@1c7
1c7 / btc-eth-dca-buy.php
Created December 28, 2017 10:01 — forked from levelsio/btc-eth-dca-buy.php
This script runs daily and "Dollar Cost Average"-buys $40 BTC and $10 ETH per day
<?
//
// [ BUY BTC & ETH DAILY ON BITSTAMP ]
// by @levelsio
//
// 2017-08-23
//
// 1) buy $40/day BTC
// 2) buy $10/day ETH
//