Skip to content

Instantly share code, notes, and snippets.

$feedUrl = "http://channel9.msdn.com/Events/TechEd/Europe/2014/RSS/mp4high"
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$rss = (new-object net.webclient)
$a = ([xml]$rss.downloadstring($feedUrl))
$a.rss.channel.item | foreach{
$url = New-Object System.Uri($_.enclosure.url)
$file = $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-") + "-" + $_.creator + ".mp4"
if (!(test-path $file))
{
$file
@paully21
paully21 / SearchForum
Created August 21, 2014 10:47
Search Discourse Topics Via API and C#
private List<DiscoursSearchResult> SearchForum(string term)
{
List<DiscoursSearchResult> results = new List<DiscoursSearchResult>();
if (string.IsNullOrEmpty(term))
return results;
string url = ConfigurationManager.AppSettings["DiscourseUrl"] + "/search.json?include_blurbs=true&type_filter=topic&api_key=" + ConfigurationManager.AppSettings["DiscourseAPIKey"] + "&api_username=" + ConfigurationManager.AppSettings["DiscourseUrl"] + "&term=" + term;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = WebRequestMethods.Http.Get;
req.Accept = "application/json";
@paully21
paully21 / AddToDiscourseGroup.cs
Last active August 29, 2015 14:01
Add a user to a Discourse group using RestSharp
private bool setGroupAccess(string username, string groupName)
{
string url = "/groups/{group_name}.json?api_key={api_key}&api_username={api_username}";
var client = new RestClient(ConfigurationManager.AppSettings["DiscourseUrl"]);
var request = new RestRequest(url, Method.GET);
request.AddUrlSegment("group_name", groupName);
request.AddUrlSegment("api_key", ConfigurationManager.AppSettings["DiscourseAPIKey"]);
request.AddUrlSegment("api_username", ConfigurationManager.AppSettings["DiscourseAPIUsername"]);
request.RootElement = "basic_group";
IRestResponse<DiscourseGroup> groupInfoResponse = client.Execute<DiscourseGroup>(request);
@paully21
paully21 / downloadBuild2014Videos.ps1
Last active August 29, 2015 13:58
Download All Build 2014 Videos Via PowerShell
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$rss = (new-object net.webclient)
$a = ([xml]$rss.downloadstring("http://channel9.msdn.com/Events/Build/2014/RSS/mp4high"))
$a.rss.channel.item | foreach{
$url = New-Object System.Uri($_.enclosure.url)
$file = $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-") + "-" + $_.creator + ".mp4"
if (!(test-path $file))
{
$file
$wc = (New-Object System.Net.WebClient)
@paully21
paully21 / aspnetmvc_discourse_sso.cs
Created February 26, 2014 16:25
ASP.NET MVC Discourse SSO Example
public ActionResult DiscourseLogin()
{
if (string.IsNullOrEmpty(Request.QueryString["sso"]) || string.IsNullOrEmpty(Request.QueryString["sig"]))
return Content("Invalid");
string ssoSecret = "YOUR SSO SECRET"; //must match sso_secret in discourse settings
string sso = Request.QueryString["sso"];
string sig = Request.QueryString["sig"];
@paully21
paully21 / gist:7056277
Last active December 25, 2015 23:19 — forked from jferguson/gist:1681480
public static void BulkInsert<T>(string connection, string tableName, IList<T> list, string[] propsToSkip)
{
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock))
{
bulkCopy.BatchSize = list.Count;
bulkCopy.DestinationTableName = tableName;
var table = new DataTable();
var props = TypeDescriptor.GetProperties(typeof(T))
//Dirty hack to make sure we only have system data types