Skip to content

Instantly share code, notes, and snippets.

View wwj718's full-sized avatar

wwj718

View GitHub Profile
@wwj718
wwj718 / 问题.md
Created April 20, 2018 11:13
为何外部写入的和读出的不一致
import serial, json, time
from serial.tools.list_ports import comports as list_serial_ports

def find_microbit():
    """
    Finds the port to which the device is connected.
    https://github.com/mu-editor/mu/blob/803153f661097260206ed2b7cc9a1e71b564d7c3/mu/contrib/microfs.py#L44
    """
    ports = list_serial_ports()

pc上:

#!/usr/bin/env python
# encoding: utf-8

import serial, json, time
from serial.tools.list_ports import comports as list_serial_ports

def find_microbit():
# https://stackoverflow.com/questions/48676566/grant-access-to-cam-mic-using-python-for-pyqt-webengine
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
from PyQt5.QtCore import QUrl
class WebEnginePage(QWebEnginePage):
def __init__(self, *args, **kwargs):
QWebEnginePage.__init__(self, *args, **kwargs)
self.featurePermissionRequested.connect(self.onFeaturePermissionRequested)
@wwj718
wwj718 / pub_sub.py
Last active March 27, 2018 08:27
pub和sub在同个文件中
import zmq
import time
from zmq.utils.strtypes import asbytes
import threading
context = zmq.Context()
pub = context.socket(zmq.PUB)
pub.bind("tcp://*:5000")
@wwj718
wwj718 / zeromq_demo_publisher.py
Last active March 16, 2018 04:46 — forked from ramn/zeromq_demo_publisher.py
Python ZeroMQ pub/sub example
'''
测试环境:
python3.6
pyzmq==17.0.0
'''
import time
import zmq
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind('tcp://127.0.0.1:2000')
@wwj718
wwj718 / understanding-word-vectors.ipynb
Created March 3, 2018 01:55 — forked from aparrish/understanding-word-vectors.ipynb
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# main.py -- put your code here!
c = '''
import pyb
red_led = pyb.LED(1) #
red_led.on()
'''
exec(c.strip())
import asyncio
# 一个对future进行赋值的函数
async def slow_operation(future):
await asyncio.sleep(1)
# 给future赋值
future.set_result('Future is done!')
loop = asyncio.get_event_loop()
# 创建一个future
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import uasyncio
async def hello():
print('Hello world! ' )
await uasyncio.sleep(1)
print('Hello again! ' )
@wwj718
wwj718 / mpy_uasyncio.py
Created January 26, 2018 07:38
micropython uasyncio test
# See original soft_pwm.py for detailed comments.
import uasyncio
async def pwm_cycle(led, duty, cycles):
duty_off = 20 - duty
for i in range(cycles):
if duty:
print(led)
await uasyncio.sleep_ms(duty)