Skip to content

Instantly share code, notes, and snippets.

View duyuxuan's full-sized avatar
🎯
Focusing

杜育轩 duyuxuan

🎯
Focusing
View GitHub Profile
import requests
import shutil
import uuid
def generate_audio_filename():
return f"{uuid.uuid4()}.wav"
def download_file(url):
@gpeal
gpeal / BroadcastReceiver.kt
Last active February 21, 2023 11:07
Coroutine Broadcast Receivers
context.registerReceiverInScope(scope, WifiManager.WIFI_STATE_CHANGED_ACTION) { intent ->
val state = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED)
// Use wifi state here
}
/**
* Register a broadcast receiver in the given coroutine scope for any of the specified actions
* and call the callback when it is invoked.
*/
fun Context.registerReceiverInScope(
@tomoaki0705
tomoaki0705 / text.md
Last active May 12, 2024 07:20
「OpenCVの画像処理をGPU(CUDA)で高速化する」を読んでresizeをマルチコア対応するお話。

はじめに

OpenCVでの処理(リサイズなど)を、簡単にマルチコア化する方法をどなたかご存知でしたら教えて頂けないでしょうか? TBBを使ってスレッドを作る方法は色々見つかったのですが、単にcv::resize()をマルチコア動作で高速化させたいです。

TL;DR

  • Python バインディングが遅い
  • OpenCV の resize はずっと昔からマルチコア対応している
@takidog
takidog / main.py
Created October 19, 2019 18:21
push RTSP stream with ffmpeg by python
import cv2
import subprocess as sp
if __name__ == "__main__":
rtsp_server = 'rtsp://example.org:554/...' # push server (output server)
#pull rtsp data, or your cv cap. (input server)
cap = cv2.VideoCapture(
'rtsp://example.org:554/pull from me ')
@andystanton
andystanton / Tiny Python 3 HTTP 1.1 Server.md
Last active March 25, 2024 22:43
Tiny Python 3 HTTP/1.1 Server

What?

This is a Python 3 HTTP/1.1 server bound to 127.0.0.1 on port 8000 using only the standard library.

Why?

I wanted a simple Python 3 web server using HTTP 1.1 that can perform simple HTTP operations and depends only on Python and standard library modules. I couldn't find an example so I made one.

The example demonstrates how to accept different methods, parse the url and query strings, read data sent to the server, parse and return json, return responses with different status codes and headers, handle graceful termination, and override the default error logging.

@tomo-makes
tomo-makes / jupyter_translate.md
Last active February 20, 2024 15:53
Translating Jupyter notebook using Google Translate

Overview

  • Lots of jupyter notebooks for machine learning tutorials are available in English
  • Draft machine translations of markdown cells help self motivated learners, who are non-native English speakers, to reach more resources

Usage

generate translated notebook

$ ./jupyter_translate.py en ja source.ipynb translated.ipynb
@loganwilliams
loganwilliams / .block
Last active October 10, 2019 01:56
Basic D3 map (live mods) d3v5
license: mit
@1st1
1st1 / example.py
Last active May 16, 2024 03:09
asyncio queues example
import asyncio
import random
import time
async def worker(name, queue):
while True:
# Get a "work item" out of the queue.
sleep_for = await queue.get()
@coin8086
coin8086 / using-proxy-for-git-or-github.md
Last active April 7, 2024 07:40
Use Proxy for Git/GitHub

Use Proxy for Git/GitHub

Generally, the Git proxy configuration depends on the Git Server Protocol you use. And there're two common protocols: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on localhost:1080. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later.

SSH Protocol

When you do git clone ssh://[user@]server/project.git or git clone [user@]server:project.git, you're using the SSH protocol. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say ~/.ssh/config:

ProxyCommand nc -x localhost:1080 %h %p
# -*- coding:utf-8 -*-
#!/usr/bin/python3
import os
import shutil
import time
import pymysql
import requests
from HTMLParser import HTMLParser
from re import sub