Skip to content

Instantly share code, notes, and snippets.

View gsw945's full-sized avatar
🙏
buddha-like coding

玖亖伍 gsw945

🙏
buddha-like coding
View GitHub Profile
#!/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

Python Socket 编程详细介绍

Python 提供了两个基本的 socket 模块:

  • Socket 它提供了标准的BSD Socket API。
  • SocketServer 它提供了服务器重心,可以简化网络服务器的开发。

下面讲解下 Socket模块功能。

Socket 类型

@gsw945
gsw945 / logo.py
Created August 2, 2018 13:53 — forked from SuperDoxin/logo.py
Python Logo using bezier curves and the turtle module
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)
@gsw945
gsw945 / transactions.py
Created September 18, 2018 08:36 — forked from elliotchance/transactions.py
Implementing all four SQL transaction isolation levels in Python
# -*- 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):
@gsw945
gsw945 / python-selenium-open-tab.md
Created September 30, 2018 01:15 — forked from lrhache/python-selenium-open-tab.md
Python Selenium - Open new tab / focus tab / close tab

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.

@gsw945
gsw945 / MirrorMigrationTool.cs
Created July 19, 2019 06:06 — forked from SoftwareGuy/MirrorMigrationTool.cs
Converts old UNET code into modern Mirror Networking code
// 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;
@gsw945
gsw945 / client.js
Created October 16, 2019 03:30 — forked from hagino3000/client.js
WebSocket with binary data
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();
@gsw945
gsw945 / ffmpeg.md
Created December 5, 2019 05:11 — forked from protrolium/ffmpeg.md
using ffmpeg to extract audio from video files

ffmpeg

Converting Audio into Different Formats / Sample Rates

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:

@gsw945
gsw945 / optimizations.md
Created April 8, 2020 07:02 — forked from mandarinx/optimizations.md
Unity3D optimization tips

Unity3D optimization tips

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 {