Skip to content

Instantly share code, notes, and snippets.

View afreeland's full-sized avatar

Aaron Freeland afreeland

View GitHub Profile
@afreeland
afreeland / gist:4484102
Last active December 10, 2015 19:48
JavaScript: Get Angle By Two Vectors On Coordinate Plan
/**
* Defines an x,y coordinate
* @param {float} x coordinate
* @param {float} y coordinate
*/
function Point (x, y) {
this.x = x;
this.y = y;
}
@afreeland
afreeland / SimpleZoomPan.js
Created January 8, 2013 15:07
JavaScript: Create rounded rectangle HTML5 Canvas
{
/**
* [roundedRect description]
* @param {Canvas Context} ctx Canvas Context
* @param {int} x X Coordinate
* @param {int} y Y Coordinate
* @param {int} width Width of rectangle
* @param {int} height Height of rectangle
* @param {radius} radius Radius of rectangle corners
@afreeland
afreeland / gist:4556156
Last active December 11, 2015 05:58
CSS: Full Page Background
html
{
background: url('../Images/Cloud.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@afreeland
afreeland / gist:4556172
Created January 17, 2013 14:12
C#: Read and Deserialize JSON File
using (StreamReader sr = new StreamReader(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Models", "JSON") + "/Menu.json"))
{
var response = sr.ReadToEnd();
taskbar = JSON.Deserialize<Menu.Taskbar>(response.ToString());
sr.Close();
sr.Dispose();
}
@afreeland
afreeland / gist:4565156
Last active December 11, 2015 07:18
CSS: Image Proportional
height: 40px;
width: auto;
display: block;
@afreeland
afreeland / GetLineNumberDuringException.cs
Last active May 30, 2023 05:22
C#: Get Line Number During Exception
try
{
throw new Exception();
}
catch (Exception ex)
{
// Get stack trace for the exception with source file information
var st = new StackTrace(ex, true);
// Get the top stack frame
var frame = st.GetFrame(0);
@afreeland
afreeland / mediator.js
Last active December 14, 2015 14:29
JavaScript: Pub/Sub Mediator Pattern
window.mediator = (function(){
var subscribe = function(channel, fn, _context){
_context = (typeof _context != 'undefined') ? _context : this;
if (!mediator.channels[channel]) mediator.channels[channel] = [];
mediator.channels[channel].push({ context: _context, callback: fn });
return _context;
},
publish = function(channel){
if (!mediator.channels[channel]) return false;
var args = Array.prototype.slice.call(arguments, 1);
@afreeland
afreeland / join.cs
Last active December 15, 2015 03:59
C#: Join array delimited by a comma
string.Join(",", myListOfStrings.ToArray())
@afreeland
afreeland / gist:5237760
Created March 25, 2013 15:04
C#: Import CSV file and get CSV headers
public JsonResult ImportCSV(HttpPostedFileBase file)
{
if (file == null)
return Json(new JSON.Result() { Status = JSON.Result.StatusEnum.Failed, DisplayMessage = "No Upload File Present" });
if (file.ContentLength == 0)
return Json(new JSON.Result() { Status = JSON.Result.StatusEnum.Failed, DisplayMessage = "File does not have Content Length" });
@afreeland
afreeland / gist:5254564
Last active December 15, 2015 11:39
JavaScript: Keywords array to Regular Expression
/**
* Takes an array of keywords and turn it into a regular expression
* that can be tested to see if a word matches any in the array
* irregardless of white space and case
* @param {Array} arrKeywords Array of Keywords
* @return {RegExp} Regular Expression
*/
function createExpression (arrKeywords) {
var innerExpression = '';
[].forEach.call(arrKeywords, function (k, index) {