Skip to content

Instantly share code, notes, and snippets.

View lmatt-bit's full-sized avatar
🎱

lmatt lmatt-bit

🎱
View GitHub Profile
@lmatt-bit
lmatt-bit / gist:10526070
Created April 12, 2014 09:09
Get or set value for a field with reflection
class RTest
{
public static int staticInt;
public int instantInt;
}
Type type = typeof(RTest);
var field = type.GetField("staticInt");
field.SetValue(null, 10);
Console.WirteLine(field.GetValue(null));//why use null here? because this is a static field
@lmatt-bit
lmatt-bit / gist:6f46b20f0d0cf2cd843a
Created June 4, 2014 05:52
httpclient post with ntlm auth
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
using(var client = new HttpClient(handler)) {
var content = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("query", "test"),
new KeyValuePair<string, string>("position", "top")
});
var result = client.PostAsync("http://url/", content).Result;
Console.WriteLine(result.Content.ReadAsStringAsync().Result);
@lmatt-bit
lmatt-bit / gist:1902d501d4f7018cfd60
Created June 4, 2014 05:54
Node.js use request library to post/get
var request = require('request');
request.post(
'http://url/',
{form:
{
"query" : "test",
"position" : "top"
}
},
@lmatt-bit
lmatt-bit / gist:703b41afa35d47862af0
Created August 13, 2014 07:34
Use CSharpCodeProvider to build code at runtime
using (var codeProvider = new CSharpCodeProvider())
{
var parameters = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = true };
parameters.ReferencedAssemblies.Add("some.dll");
var results = codeProvider.CompileAssemblyFromFile(parameters, fileList);
if (results.Errors.Count > 0)
{
var errorString = new StringBuilder();
for (int i = 0; i < results.Errors.Count; i++)
{
@lmatt-bit
lmatt-bit / gist:2ce8e1419ebcbd5d6ab9
Last active August 29, 2015 14:05
Generic method & Extension method
namespace ExtensionExample {
public static class ExtensionExampleClass {
public static T[] GetCustomAttributes<T>(this Type type, bool inherit) where T : Attribute {
var attributes = type.GetCustomAttributes(typeof(T), inherit);
return attributes as T[];
}
}
}
@lmatt-bit
lmatt-bit / gist:9d969885241b72937865
Created October 23, 2014 08:05
Load file by using html5
<input type="file" id="inputFile" />
<textarea id="output"></textarea>
<script>
function readFile(evt) {
var fs = evt.target.files;
if(fs.length > 0) {
var reader = new FileReader();
reader.onload = function(e) {
@lmatt-bit
lmatt-bit / .vimrc
Last active January 19, 2017 12:46
vimrc
set t_Co=256
syntax on
set scrolloff=3
" colorschema desert
set autoindent
filetype plugin indent on
" no swap file
set noswapfile
set clipboard+=unnamed
@lmatt-bit
lmatt-bit / gist:f14c8087724a5cdf66d5
Created November 11, 2014 06:43
create an xslt
XNamespace xsl = "http://www.w3.org/1999/XSL/Transform";
var root = new XElement(xsl + "stylesheet", new XAttribute("version", "1.0"), new XAttribute(XNamespace.Xmlns + "xsl", xsl));
var template = new XElement(xsl + "template", new XAttribute("match", "/"));
template.Add(items);
root.Add(template);
# -*- coding: utf-8 -*-
"""
flask.logging
~~~~~~~~~~~~~
Implements the logging support for Flask.
:copyright: (c) 2014 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
@lmatt-bit
lmatt-bit / gist:2c62be504a24f347405a
Created January 5, 2015 02:22
Send email with IronPython
# coding=utf-8
import System.Net.Mail
import httplib
import time
import datetime
import os.path
workingDir = 'E:\\IronPython-2.7.5'
logFile = os.path.join(workingDir,'check.log')
touchFile = os.path.join(workingDir,'touchFile')