Skip to content

Instantly share code, notes, and snippets.

@chenbojian
chenbojian / force-xhr-status-with-proxy.js
Created December 23, 2024 12:56 — forked from davidsharp/force-xhr-status-with-proxy.js
Proxying a XMLHttpRequest to force the status received
XMLHttpRequest = new Proxy(XMLHttpRequest, {
construct:function(t,a){
const req = new t();
return new Proxy(req, {
get:function(o,p){
if(p=='status')return 9001
return typeof o[p] == 'function'?o[p].bind(o):o[p]
},
set: function(target, prop, value) {
Reflect.set(target, prop, value) // or target[prop] = value
@chenbojian
chenbojian / http-proxy-connect.js
Last active December 26, 2023 02:57
simple nodejs http proxy implementation
# https://imququ.com/post/web-proxy.html
var http = require('http');
var net = require('net');
var url = require('url');
function connect(cReq, cSock) {
var u = url.parse('http://' + cReq.url);
var pSock = net.connect(u.port, u.hostname, function() {
cSock.write('HTTP/1.1 200 Connection Established\r\n\r\n');
// See https://aka.ms/new-console-template for more information
using System.Text;
using System.Text.RegularExpressions;
var lines = File.ReadAllLines("error.txt");
var regex = new Regex(@"(C:\\workspace.+.cs)\((.+),(.+)\): Error CodeAnalyzer0001", RegexOptions.Compiled);
Console.WriteLine("start");
var fileRowsDict = new Dictionary<string, List<int>>();
void Update(DataRow newRow, string connStr, string tableName)
{
using MySqlDataAdapter da = new MySqlDataAdapter(
$"select * from {tableName}",
connStr
);
da.UpdateCommand = new MySqlCommandBuilder(da).GetUpdateCommand();
DataSet ds = new DataSet();
@chenbojian
chenbojian / MFC-CRecordset-example.cpp
Last active September 4, 2022 02:30
MFC CRecordset
void func() {
CDatabase db;
CRecordset rs(&db);
db.OpenEx("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\dbo.mdb;");
db.ExecuteSQL("select * from Sporter");
rs.Open(CRecordset::dynaset, "select * from [Sporter]", CRecordset::none);
BOOL a = rs.CanAppend();
function Convert-Gbk-To-Utf8($source, $dest) {
$gbk = [System.Text.Encoding]::GetEncoding("gb2312")
$utf8 = [System.Text.Encoding]::UTF8
$text = [System.IO.File]::ReadAllText($source, $gbk)
[System.IO.File]::WriteAllText($dest, $text, $utf8)
}
$roleAssignments = Get-AzRoleAssignment
$roles = Get-AzRoleDefinition
# https://docs.microsoft.com/en-us/azure/role-based-access-control/resource-provider-operations
$storageActionRegexList = @('^\*$', '^\*/.+$', '^Microsoft\.Storage/.+$')
$storageDataActionRegexList = @('^\*$', '^\*/.+$', '^Microsoft\.Storage/.+$')
$storageManagementAccessRoles = @()
$storageDataAccessRoles = @()
# ref: https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/logfile/
# ref: https://forums.iis.net/t/1205491.aspx?Add+IIS+8+5+Custom+Logging+Fields+with+Powershell
function Set-WebSiteIISLogFormat {
param (
$Site
)
$logExtFileFlags = 'Date,Time,ClientIP,UserName,ServerIP,Method,UriStem,UriQuery,HttpStatus,Win32Status,TimeTaken,ServerPort,UserAgent,Referer,Host,HttpSubStatus'
Set-ItemProperty -Path "IIS:\Sites\$Site" -Name logfile.logExtFileFlags -Value $logExtFileFlags
--https://dba.stackexchange.com/questions/20355/generate-create-script-for-all-indexes
DECLARE @SchemaName VARCHAR(256)DECLARE @TableName VARCHAR(256)
DECLARE @IndexName VARCHAR(256)
DECLARE @TSQLDropIndex VARCHAR(MAX)
DECLARE CursorIndexes CURSOR FOR
SELECT schema_name(t.schema_id), t.name, i.name
FROM sys.indexes i
INNER JOIN sys.tables t ON t.object_id= i.object_id
WHERE i.type>0 and t.is_ms_shipped=0 and t.name<>'sysdiagrams'