Skip to content

Instantly share code, notes, and snippets.

View michaelbramwell's full-sized avatar

696d656b michaelbramwell

  • Perth Australia
View GitHub Profile
@michaelbramwell
michaelbramwell / httpRequestPost.cs
Last active June 13, 2018 11:47
Http Request POST
string getUrl = "http://whatevatreva.kwom";
string postData = String.Format("organization_id={0}&subscriber_firstname={1}", "313", "Treva");
HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
getRequest.Method = WebRequestMethods.Http.Post;
getRequest.ContentType = "application/x-www-form-urlencoded";
byte[] byteArray = Encoding.ASCII.GetBytes(postData);
getRequest.ContentLength = byteArray.Length;
Stream newStream = getRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
@michaelbramwell
michaelbramwell / gitPulls.bat
Created February 7, 2013 07:08
Git Pull(s) in a Windows Batch file
(E: && cd E:\inetpub\wwwroot\thissite.staging.com && git.exe pull)
(cd E:\inetpub\wwwroot\thatsite.staging.com && git.exe pull)
(cd E:\inetpub\wwwroot\anothersite.staging.com && git.exe pull)
REM: to run this from a scheduled task with output appended to a text file enter this in the task action /C E:\GCGitOps\gitPulls.bat >> E:\GCGitOps\gitPulls.output.txt 2>&1
@michaelbramwell
michaelbramwell / incrementWithReset.js
Created February 10, 2013 07:09
Nice little incremental trick learnt in the first week of udacity's htm5 games dev course
var frames = []; // fill array with stuff
var frame = 0; // a frame index
// when its time to increment frame array this will start from firs pos in array to last pos then restart from first pos
// more than likley to be called from a function within setInterval
frame = (frame + 1) % frames.length;
@michaelbramwell
michaelbramwell / enitityGroupByWithSum.cs
Created February 26, 2013 06:24
Example of a group by and sum of each column/property in entity framework. Relational tables/objects referenced so they are not lazy loaded, otherwise they will return null.
public static IEnumerable<ScoreReport> GetWeeklyLeaderBoardTotals(Guid challengeId, ChallengeType challengeType)
{
xxxFBAppEntities context = new xxxFBAppEntities();
context.Configuration.ProxyCreationEnabled = false;
var scoreData = from score in context.Scores
.Include("User")
.Include("Challenge")
where score.Active == (int)ActiveType.Active &&
score.ChallengeID == challengeId &&
@michaelbramwell
michaelbramwell / SQL2CSVFile
Last active December 16, 2015 09:09
SQL2CSVFile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;
namespace dbDump
@michaelbramwell
michaelbramwell / HTTPGetRequest.cs
Created May 8, 2013 08:18
HTTPGetRequest Example
public String GetRemoteHTTPContent(string remoteFile)
{
string responseFromServer = string.Empty;
try
{
WebRequest request = WebRequest.Create(remoteFile);
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse response = request.GetResponse();
@michaelbramwell
michaelbramwell / GetRandomImage.cs
Created May 31, 2013 03:10
Get Random Image with full path from SharePoint 2010 Picture Library View
private string GetRandomImage(string url)
{
SPList list = SPContext.Current.Web.GetList(url);
SPView view = SPContext.Current.Web.GetViewFromUrl(url);
SPListItemCollection curItems = list.GetItems(view);
Random random = new Random();
int index = random.Next(0, curItems.Count);
return curItems[index]["RequiredField"].ToString();
}
@michaelbramwell
michaelbramwell / GetSiteTemplate.ps1
Created June 10, 2013 06:07
Gets Site Template used for a specific site Source - http://stackoverflow.com/a/5311966
PS> asnp Microsoft.SharePoint.PowerShell
PS> $web = get-spweb http://server/site
PS> $web.WebTemplate
PS> $web.WebTemplateId
@michaelbramwell
michaelbramwell / async.js
Last active December 19, 2015 11:09
Simple jquery ajax wrapper
function async(params)
{
/// <summary>async - jQuery $.ajax wrapper</summary>
/// <param name="params" type="object">Params to build the XHR request</param>
var data = params.data || '';
var type = params.type || 'GET';
var cache = params.cache || true;
var contentType = params.contentType || 'application/x-www-form-urlencoded; charset=UTF-8';
var dataType = params.dataType || 'json';
var context = new window.webkitAudioContext(),
osc = context.createOscillator(),
osc2 = context.createOscillator(),
gain = context.createGain(),
w = window.innerWidth,
h = window.innerHeight;
osc.frequency = 400;
osc.connect(context.destination);