Skip to content

Instantly share code, notes, and snippets.

@rstackhouse
rstackhouse / ListNamesOfGroupsOfUserInCSharp
Created August 4, 2011 13:35
List names of groups of user in C#
var user = System.Security.Principal.WindowsIdentity.GetCurrent();
foreach(var group in user.Groups)
{
var x =group.Translate(typeof(System.Security.Principal.NTAccount));
Console.Out.WriteLine(x.Value);
}
@rstackhouse
rstackhouse / ListUsersInGroupInCSharp
Created August 4, 2011 13:40
List users in group in C#
using(DirectoryEntry d = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer"))
{
using(DirectoryEntry g = d.Children.Find("Administrators", "group"))
{
object members = g.Invoke("Members", null);
foreach(object member in (IEnumerable)members)
{
DirectoryEntry x = new DirectoryEntry(member);
Console.Out.WriteLine(x.Name);
}
@rstackhouse
rstackhouse / gist:1162357
Created August 22, 2011 13:22
Configure NLog Programmatically
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NLog.Common;
using NLog.Targets;
using NLog.Config;
namespace ConsoleApplication1
@rstackhouse
rstackhouse / TryingToUseLinkedInGem.rb
Created June 4, 2012 18:18
Tyring to use LinkedIn Gem
require 'rubygems'
require 'linkedin'
client = LinkedIn::Client.new('api_key', 'api_secret')
rtoken = client.request_token.token
rsecret = client.request_token.secret
puts client.request_token.authorize_url
pin = gets
@rstackhouse
rstackhouse / TryingToInstallRubyDebugOnRubyStack3-2-4.txt
Created June 20, 2012 10:51
Trying to install ruby-debug on RubyStack 3.2.3
C:\RubyStack-3.2.3-0>gem install ruby-debug
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing ruby-debug:
ERROR: Failed to build gem native extension.
C:/RubyStack-3.2.3-0/ruby/bin/ruby.exe extconf.rb
Can't handle 1.9.x yet
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
@rstackhouse
rstackhouse / gist:5877644
Created June 27, 2013 15:53
Button inside a link
<a href="cnn.com"><button type="button">CNN</button></a>
@rstackhouse
rstackhouse / scripts-config-minify.linq
Last active December 19, 2015 15:19
Turn Chirpy Minify flags on and off via LinqPad script
var scriptsDotChirpDotConfig = @"C:\Users\rstackhouse\Desktop\WellTrak AFE\trunk\CostTrak\UI\Web\Admin\Administration\Scripts\scripts.chirp.config";
var xDoc = XDocument.Load(scriptsDotChirpDotConfig);
xDoc.Descendants("FileGroup").ToList().ForEach(x => {
//Default for a FileGroup is to minify. Remove the attribute.
var attr = x.Attribute("Minify");
if (attr != null)
{
attr.Remove();
}
@rstackhouse
rstackhouse / DotNetLDapSearch
Last active December 20, 2015 00:09
.NET LDAP Search
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://some.ldap.server.com");
rootEntry.AuthenticationType = AuthenticationTypes.None; //Or whatever it need be
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
searcher.Filter = "(&(objectClass=user)(objectCategory=person)(SAMAccountName=some_user_name)";
foreach(SearchResult result in searcher.FindAll())
{
Console.WriteLine("account name: {0}", result.Properties["samaccountname"].Count > 0 ? result.Properties["samaccountname"][0] : string.Empty);
Console.WriteLine("common name: {0}", result.Properties["cn"].Count > 0 ? result.Properties["cn"][0] : string.Empty);
}
@rstackhouse
rstackhouse / OpenABrowserTabFromCSharp
Created July 23, 2013 15:12
Open a Browser Tab on Local Machine from C#.
//Open a browser window on local machine from C#
Process.Start("http://www.cnn.com");
@rstackhouse
rstackhouse / OpenHiddenFileInput.html
Last active December 20, 2015 05:59
Open a hidden file input by clicking a button.
<html>
<head>
<title>Test upload form focused by button press</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<!--Some ideas on better styling methods at http://www.quirksmode.org/dom/inputfile.html-->
<input name="file" id="file" type="file" style="display:none;">