Skip to content

Instantly share code, notes, and snippets.

@abc126
abc126 / io_realtime.py
Last active May 15, 2021 15:12
get stdout and stderr realtime
#https://stackoverflow.com/a/57084403
import io
import time
import subprocess
import sys
filename = 'test.log'
with io.open(filename, 'wb') as writer, io.open(filename, 'rb', 1) as reader:
process = subprocess.Popen(command, stdout=writer)
@abc126
abc126 / real.py
Created May 1, 2021 16:29 — forked from alfredodeza/real.py
Real time subprocess stdout/stderr
import logging
import threading
import os
import subprocess
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
class LogPipe(threading.Thread):
@abc126
abc126 / CallerMemberNameAttribute
Created January 10, 2020 18:13
CallerMemberNameAttribute
namespace System.Runtime.CompilerServices {
sealed class CallerMemberNameAttribute : Attribute { }
}
@abc126
abc126 / SimpleLogger.cs
Created December 6, 2019 09:30
SimpleLogger
using System;
using System.IO;
using System.Text;
using System.Threading;
namespace Clearcove.Logging
{
public sealed class Logger
{
#region Log File Writing
@abc126
abc126 / SimpleHttpServer.cs
Created November 29, 2019 02:57 — forked from augustoproiete/SimpleHttpServer.cs
C# Based HttpListener Static File Web Server
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Westwind.Utilities;
namespace Westwind.WebConnection
@abc126
abc126 / split string
Created October 31, 2019 03:24
split string c++
void split(const string& s, vector<string>& tokens, const string& delimiters = " ")
{
string::size_type lastPos = s.find_first_not_of(delimiters, 0);
string::size_type pos = s.find_first_of(delimiters, lastPos);
while (string::npos != pos || string::npos != lastPos) {
tokens.push_back(s.substr(lastPos, pos - lastPos));//use emplace_back after C++11
lastPos = s.find_first_not_of(delimiters, pos);
pos = s.find_first_of(delimiters, lastPos);
}
}
worksheet.TrimLastEmptyRows();
public static void TrimLastEmptyRows(this ExcelWorksheet worksheet)
{
while (worksheet.IsLastRowEmpty())
worksheet.DeleteRow(worksheet.Dimension.End.Row);
}
public static bool IsLastRowEmpty(this ExcelWorksheet worksheet)
{
public static void SendACommandToAutoCAD(string command)
{
MgdAcDocument doc = MgdApplication.DocumentManager.MdiActiveDocument;
if(doc == null)
{
MessageBox.Show("当前无活动文档,请新建或切换至活动文档后再执行命令", "无法获取活动文档", MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
// 根据是否有命令运行决定esc的数量
string esc = "";
public class RadioGroupBox : GroupBox
{
public event EventHandler SelectedChanged = delegate { };
int _selected;
public int Selected
{
get
{
return _selected;
@abc126
abc126 / IsInDesignMode.cs
Created December 7, 2018 15:38
IsInDesignMode
public static bool IsInDesignMode()
{
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
return true;
if (Process.GetCurrentProcess().ProcessName == "devenv") return true;
return false;
}