Skip to content

Instantly share code, notes, and snippets.

View afreeland's full-sized avatar

Aaron Freeland afreeland

View GitHub Profile
@afreeland
afreeland / gist:8849587
Created February 6, 2014 18:16
RegEx: General regular expression helpers
// Regex \[(.*?)\]
// Result [BinLocation] [nvarchar]
[BinLocation] [nvarchar](20) NOT NULL,
// RegEx \[([^\[]+)$
// \[ matches [
// [^\/[]+] Matches last occurence of [
// $ matches end of line
// Result [nvarchar](20) NOT NULL,
@afreeland
afreeland / gist:9390169
Created March 6, 2014 13:53
SQL: Common table expression to update a segmented query
with cte
as(
select ID, AccountID, ItemTypeID, SourceChannelID, ntile(3) over(order by id) as tile_nr from [Item].[Item] where AccountID = 730
)
update [item].[item]
set SourceChannelID = cte.tile_nr
from [item].[item] ii
inner join cte on ii.ID = cte.ID
where ii.AccountID = 730
@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 / 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 / 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) {