Python 提供了两个基本的 socket 模块:
Socket
它提供了标准的BSD Socket API。SocketServer
它提供了服务器重心,可以简化网络服务器的开发。
下面讲解下 Socket模块功能。
#!/usr/bin/env python | |
# A simple demonstration of using cairo to shape windows. | |
# Natan 'whatah' Zohar | |
import gtk | |
import math | |
class ShapedGUI: | |
def __init__(self): | |
self.window = gtk.Window() | |
self.window.show() # We show here so the window gets a border on it by the WM |
import turtle | |
import math | |
def lerp(a, b, t): | |
"""Linear interpolation function. returns a when t==0, returns b when t==1 | |
and linearly interpolates for values inbetween""" | |
return (a * (1 - t)) + (b * t) | |
next_xid = 1 | |
active_xids = set() | |
records = [] | |
def new_transaction(): | |
global next_xid | |
next_xid += 1 | |
active_xids.add(next_xid) | |
return Transaction(next_xid) |
# -*- coding: utf8 -*- | |
from __future__ import print_function | |
class LockManager: | |
def __init__(self): | |
self.locks = [] | |
def add(self, transaction, record_id): | |
if not self.exists(transaction, record_id): |
On a recent project, I ran into an issue with Python Selenium webdriver. There's no easy way to open a new tab, grab whatever you need and return to original window opener.
Here's a couple people who ran into the same complication:
So, after many minutes (read about an hour) of searching, I decided to do find a quick solution to this problem.
// Mirror Network Migration Tool | |
// Written by M. Coburn (@coburn64 on Twitter/SoftwareGuy on Github) | |
// This file is part of Mirror Networking by Coburn64, Lymdun, vis2k and Paul (goldbug). | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
using UnityEditor; | |
using UnityEngine; |
var socket = null; | |
function bootstrap() { | |
// 適当な図形を描画 | |
var c = document.getElementById('mycanvas'); | |
var ctx = c.getContext('2d'); | |
ctx.globalalpha = 0.3; | |
for(var i=0; i<1000; i++) { | |
ctx.beginPath(); |
Minimal example: transcode from MP3 to WMA:
ffmpeg -i input.mp3 output.wma
You can get the list of supported formats with:
ffmpeg -formats
Convert WAV to MP3, mix down to mono (use 1 audio channel), set bit rate to 64 kbps and sample rate to 22050 Hz:
Some code allocates memory when running in the editor and not on the device. This is due to Unity doing some extra error handling so possible error messages can be output in the console. Much of this code is stripped during build. It's therefore important to profile on device, and do it regularly.
Optimizations often makes code more rigid and harder to reason. Don't do it until you really need to.
When profiling, wrap methods or portions of a method in Profiler.BeginSample(string name) and Profiler.EndSample() to make them easier to find in the profiler.
public class SomeClass {