Skip to content

Instantly share code, notes, and snippets.

View ElliotWood's full-sized avatar

Elliot Wood ElliotWood

  • Lab3
  • Australia
  • 21:51 (UTC +10:00)
View GitHub Profile
@ElliotWood
ElliotWood / gist:5259918
Last active December 15, 2015 12:28
Upload a File with FTP with C# example
private static void Upload(string ftpServer, string userName, string password, string filename)
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.UploadFile(ftpServer + "/" + new FileInfo(filename).Name, "STOR", filename);
}
}
@ElliotWood
ElliotWood / gist:5259940
Created March 28, 2013 02:10
Async in winforms kinda sux Here is a way better way to do it
//static for extension..
//this allows us to always make sure we're using our controls on the
//thread they were created on, regardless of the thread we're calling from...
public static class ISynchronizeInvokeExtensions
{
public static void InvokeEx<T>(this T @this, Action<T> action) where T : ISynchronizeInvoke
{
if (@this.InvokeRequired)
@this.BeginInvoke(action, new object[] { @this });
else
@ElliotWood
ElliotWood / gist:5259949
Created March 28, 2013 02:11
Simple script to restart SharePoint 2010 Services
@echo off
@echo Stopping SharePoint 2010 services...
iisreset /stop /noforce
net stop "SharePoint 2010 User Code Host"
net stop "SharePoint 2010 Timer"
@ElliotWood
ElliotWood / gist:5259955
Created March 28, 2013 02:12
SharePoint Content Query Webpart - Auto CommonViewFields
public class ContentDisplayWebPart : ContentByQueryWebPart
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
string headerlink = "/Style%20Library/XSL%20Style%20Sheets/CustomXsl/______.xsl";
string itemlink = "/Style%20Library/XSL%20Style%20Sheets/CustomXsl/______.xsl";
if (this.HeaderXslLink != headerlink) { this.HeaderXslLink = headerlink; }
if (this.ItemXslLink != itemlink) { this.ItemXslLink = itemlink; }
if (this.CommonViewFields != (string)HttpContext.Current.Cache[this.Title + "_CommonViewFields"])
@ElliotWood
ElliotWood / gist:5259979
Created March 28, 2013 02:15
This is sort of a Part II of SharePoint Content Query Webpart - Auto CommonViewFields
//In SP Header template xslt have you ever noticed the attribute mode
<xsl:template name="someTemplateName" match="*[@GroupStyle='someTemplateName']" mode="header">
//well there is another option mode="footer" now by default it isnt hooked up so you need to copy CallHeaderTemplate or modify CallFooterTemplate to the following:
<xsl:template name="OuterTemplate.CallFooterTemplate">
<xsl:value-of disable-output-escaping="yes" select="$EndList" />
<xsl:apply-templates select="." mode="footer">
</xsl:apply-templates>
<xsl:value-of disable-output-escaping="yes" select="$EndListItem" />
@ElliotWood
ElliotWood / gist:5260019
Created March 28, 2013 02:23
Fast Data Sync - Technical Specification
First you define some data. This will be the data that will define how one player differs to another.
class PlayerDetails {
var TotalHP : float = 100.0;
var HP : float = 100.0;
var EXP : int = 0;
var jumpSpeed:float = 8.0;
var runSpeed:float = 5.0;
var attackSpeed: float = 1.0;
@ElliotWood
ElliotWood / gist:5260029
Created March 28, 2013 02:25
AI Game Behavior Tree's
public static class Behavior
{
//Branch
public static Action Selector(Func<bool> cond, Action ifTrue, Action ifFalse) {
return () => { if (cond()) { ifTrue(); } else { ifFalse(); } };
}
public static Action Sequencer(Action a, Action b) {
return () => { a(); b(); }
}
@ElliotWood
ElliotWood / gist:5260034
Last active December 15, 2015 12:28
Calculating Distance between two Latitude and Longitude GeoCoordinates
public static double Calculate(double sLatitude,double sLongitude, double eLatitude,
double eLongitude)
{
var sLatitudeRadians = sLatitude * (Math.PI / 180.0);
var sLongitudeRadians = sLongitude * (Math.PI / 180.0);
var eLatitudeRadians = eLatitude * (Math.PI / 180.0);
var eLongitudeRadians = eLongitude * (Math.PI / 180.0);
var dLongitude = eLongitudeRadians - sLongitudeRadians;
var dLatitude = eLatitudeRadians - sLatitudeRadians;
@ElliotWood
ElliotWood / gist:5260048
Created March 28, 2013 02:30
Here is what I did... Web App with signalR .net4.0, then your SharePoint Web App .net 2. Add this to the global.asax in your Signalr project RouteTable.Routes.MapHttpHandlerRoute("spproxy","spproxy/{*operation}", new SharePointRProxyHandler()); If you want to raise an event from SharePoint you can do a http POST to this new route URL for example…
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace System.Web.Routing
{
public class HttpHandlerRoute : IRouteHandler
{
private String _virtualPath = null;
@ElliotWood
ElliotWood / gist:5260059
Created March 28, 2013 02:31
Build a SharePoint 2013 Farm and Provision all the service apps
$configType = read-host "Do you wish to create a new farm? (Y/N)"
if ($ConfigType -eq "N") {
$DatabaseServer = read-host "Preparing to join existing farm. Please specify the name of your SQL Server";
$ConfigDB = read-host "Next, specify the name of your Farm Configuration Database";
$Passphrase = read-host "Finally, please enter your Farm passphrase" -assecurestring
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue;
}