Skip to content

Instantly share code, notes, and snippets.

View akfish's full-sized avatar
🎯
刻舟求剑

大芡猫 akfish

🎯
刻舟求剑
View GitHub Profile
@akfish
akfish / gist:1190519
Created September 3, 2011 03:47
C# Get active TextBox and insert text at cursor
if (this.ActiveControl.GetType() == typeof(TextBox))
{
TextBox textBox = (TextBox)this.ActiveControl;
String text = ((Label)sender).Text;
int pos = textBox.SelectionStart;
textBox.Text = textBox.Text.Insert(pos, text);
//Fix cursor position
textBox.Focus();
textBox.SelectionStart = pos;
textBox.SelectionLength = text.Length;
@akfish
akfish / gist:1238898
Created September 24, 2011 02:57
MFC: How to change default application look
//When using MFC wizard to generate a project, it will ask developer to choose an application look style.
//Say we have chosen "Office 2007 Blue" as default and want to change it into "Windows 7". Here is how to:
//1. In MainFrm.cpp, we will see:
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_OFF_2007_BLUE);
}
@akfish
akfish / gist:1280623
Created October 12, 2011 08:22
C# Hide borderless WinForm in Alt+Tab
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
//WS_EX_TOOLWINDOW = 0x80
cp.ExStyle |= 0x80;
return cp;
}
}
@akfish
akfish / gist:1280652
Created October 12, 2011 08:32
C# Attach event to HTMLElement in webBrowser
/// <summary>
/// Inject onclick handler to close button
/// </summary>
private void InjectJS()
{
HtmlDocument doc = webContent.Document;
HtmlElement closeBtnElement = doc.GetElementById(CloseButtonId);
if (closeBtnElement == null)
return;
@akfish
akfish / gist:1304125
Created October 21, 2011 15:30
A minor change on Android API Level 2.3.3
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
String sHeader = httpConnection.getHeaderFieldKey(i);
if (sHeader.equals("content-length")) {
//Unpredictable
//Under the same server setup, the API level before 2.3.3 will return true.
//But not this one
}
@akfish
akfish / Conversation.md
Last active December 27, 2015 08:29
Mock up data-driven interactive data input framework for C# console app

Mock up data-driven interactive data input framework for C# console app

The old way

Let's say that we have a class

public class Account
{
    public string HostName { get; set; }
@akfish
akfish / TypeMap.cs
Last active December 29, 2015 05:49
Reflection utility mock up
var account = new Account();
var validator = new AccountValidator();
account.Map<validator>(
)
@akfish
akfish / pre-commit.sh
Last active September 8, 2022 07:21
Run MSBuild and MSTest for C# project from git pre-commit hook
#!/bin/sh
# Helper
safeRunCommand() {
typeset cmd="$*"
typeset ret_code
echo cmd=$cmd
eval $cmd
ret_code=$?
@akfish
akfish / inject_i18n.md
Last active June 30, 2016 15:35
Use chrome extension i18n in injected script

Use Chrome Extension i18n in Injected Script

Introduction

Injected script has no access to chrome.i18n namespace. It would be a problem when injected script requires some i18n work. A solution is describled in this documentation.

Basic Idea

The i18n method proposed in this official documentation suggests that develops put all i18n string in messages.json file.

@akfish
akfish / converted.txt
Created February 5, 2014 16:24
CoffeeScript Grammar
/* converted on Thu Feb 6, 2014, 00:09 (UTC+08) by jison-to-w3c v0.33.722 which is Copyright (c) 2011-2013 by Gunther Rademacher <grd@gmx.net> */
Root ::= Body?
Body ::= Line ( TERMINATOR Line | TERMINATOR )*
Line ::= Expression
| Statement
Statement
::= Return
| Comment
| STATEMENT