Skip to content

Instantly share code, notes, and snippets.

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

大芡猫 akfish

🎯
刻舟求剑
View GitHub Profile
@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 / 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: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 / !PEROOF.md
Last active April 3, 2017 17:23
Peroof Storage Format
@akfish
akfish / react-usage.jsx
Last active November 22, 2016 19:39
hypercube.css
import React from 'react'
import Hypercube from 'react-hypercube'
// Use normal `style` attributes
class My3DComponent extends React.Component {
render() {
return (
<div style={{
width: '800px',
height: '800px',
@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 / shader-def-no-keywords.js
Last active March 14, 2016 09:56
GLSL in JavaScript with Babel
// flow type alias
// see http://flowtype.org/docs/type-aliases.html
type MVP = {
m: vec4,
v: vec4,
p: vec4
}
@uniform
const UFoo _.extends(UMVP, {
@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 / 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 / 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
}