Skip to content

Instantly share code, notes, and snippets.

@compustar
compustar / gist:f835b6a183800194a137
Created March 19, 2015 16:29
Search domain account name (sAMAccountName) with first name and last name from AD
public static string GetSAMAccountName(string firstName, string lastName, string domain) {
string result = string.Empty;
string connectionPrefix = "LDAP://" + domain;
using (DirectoryEntry entry = new DirectoryEntry(connectionPrefix))
using (DirectorySearcher searcher = new DirectorySearcher(entry)) {
searcher.Filter = string.Format("(&(objectClass=user)(&(sn={1})(givenName={0})))", firstName, lastName);
SearchResult searchResult = searcher.FindOne();
if (searchResult == null) {
@compustar
compustar / MessageTemplate.cs
Last active August 29, 2015 14:23
Enhanced version of java.text.MessageFormat and String.Format() using named parameters instead of index numbers. e.g.: Java - "{now,date,yyyy-MM-dd HH:mm:ss.SSS}: Hello {name}!", C# - "{now:yyyy-MM-dd HH:mm:ss.fff}: Hello {name}!"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Text {
public class MessageTemplate {
private static Dictionary<string, MessageTemplate> cache = new Dictionary<string, MessageTemplate>();
private string format;
@compustar
compustar / NGramAnalyzer.cs
Last active August 29, 2015 14:24
CJK NGram Analyzer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
namespace ngram {
public class NGramAnalyzer {
private bool cjkOnly;
/*
* JavaScript Obfucator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* JavaScript Obfucator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
using System;
using System.Linq;
public class Program {
public static void Main() {
for (int i = 10; i < 100; i++) {
if (CountDigits(i, 111 - i) == 4) {
for (int j = 10; j < 100; j++) {
if (CountDigits(j, i + j, i, 111 - i) == 8 && i + j > 9 && i + j < 100) {
Console.WriteLine(string.Format("{2} - {3} = {0} + {1} = 111", i, 111 - i, j, i + j));
using System;
using System.Linq;
using System.Text;
public class Program {
public static void Main(string[] args) {
var @base = 16;
var pLength = 4;
var n = (pLength - 1) * 4;
var max = Max(pLength - 1, @base);
@compustar
compustar / ping.js
Last active August 3, 2016 04:10
Script to ping a web page to keep AppPool alive
var http = WScript.CreateObject('Msxml2.XMLHTTP.6.0');
// Retrieve the url parameter
var url = WScript.Arguments.Item(0)
// Make the request
http.open("GET", url, false);
http.send();
@compustar
compustar / ChainStream.cs
Last active August 15, 2016 03:10
Streaming Classes
#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2012 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
@compustar
compustar / hugin_stitch.bat
Last active June 16, 2021 12:49
Batch files for Hugin stitching for Mi Sphere or Madv360 with template (https://github.com/pxlartificer/XiaomiMijiaMi-HuginTemplate).
REM Usage: hugin_stitch.bat template-XiaomiMijiaMiJPG.pto IMG_20171231_172305.jpg
@echo off
SET PATH=%PATH%;C:\Program Files\Hugin\bin
FOR %%i IN ("%2") DO (
SET Name=%%~ni
)
pto_gen %2 %2 --output=%Name%_stitched.pto
@compustar
compustar / embeddings.config
Last active December 11, 2018 07:00
A set of Chinese word embeddings
{
"embeddings": [
{
"tensorName": "三國演義",
"tensorShape": [
3957,
100
],
"tensorPath": "https://gist.githubusercontent.com/compustar/793dce1ea65e26ee38ee97b73e3208b5/raw/f9a32bf3b004145cb011cdb4ce528f12e4370b19/three_kingdoms.tsv",
"metadataPath": "https://gist.githubusercontent.com/compustar/793dce1ea65e26ee38ee97b73e3208b5/raw/f9a32bf3b004145cb011cdb4ce528f12e4370b19/three_kingdoms_meta.tsv"