Skip to content

Instantly share code, notes, and snippets.

@fduxiao
fduxiao / add.js
Created February 9, 2020 08:12
js奇葩设计
class Number {
constructor(x) {
this.x = x
}
apply(f) {
return f(this.x)
}
}
class Add {
@fduxiao
fduxiao / server.py
Created February 17, 2018 16:52 — forked from scturtle/server.py
python socks5 proxy server with asyncio (async/await)
#!/usr/bin/env python3.5
import socket
import asyncio
from struct import pack, unpack
class Client(asyncio.Protocol):
def connection_made(self, transport):
self.transport = transport
self.server_transport = None
@fduxiao
fduxiao / add_logo.py
Created December 14, 2017 09:23
movie add logo
#!/usr/bin/env python3
import moviepy.editor as mp
import os
import argparse
def process_one(video_path, logo_path, output_path):
video = mp.VideoFileClip(video_path)
logo_h = logo_w = video.h // 8
logo_margin_x = logo_margin_y = logo_h // 3
@fduxiao
fduxiao / receiver.py
Created August 7, 2017 01:49
mongo data receiver
#!/usr/bin/env python3
from flask import *
import pymongo
app = Flask(__name__)
def get_client():
@fduxiao
fduxiao / fetch_data.py
Created July 27, 2017 15:25
Yahoo Finance crawler
import pandas as pd
import requests
import time
def get_data(ticker, start_date, end_date, delta="1d"):
data_url = "https://query2.finance.yahoo.com/v8/finance/chart/" + ticker
params = dict()
params['interval'] = delta
params['period1'] = int(time.mktime(start_date.timetuple()))
@fduxiao
fduxiao / async_selecting.py
Last active July 23, 2017 02:40
async rolling in python3
#!/usr/bin/env python3
import asyncio
loop = asyncio.get_event_loop()
req = asyncio.Queue()
async def fetcher(a):
print("start fetching", a)
await asyncio.sleep(3)
print("end fetching", a)
@fduxiao
fduxiao / chain.py
Last active June 10, 2017 07:38
python used with functional programming
#!/usr/bin/env python3
class Chain:
cal = None
def __init__(self):
self.cal = lambda x: x
def chain(self, f):
@fduxiao
fduxiao / main.js
Last active May 14, 2017 13:13
wxa server authorization
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
var that = this