Skip to content

Instantly share code, notes, and snippets.

View astannard's full-sized avatar

Andy Stannard astannard

View GitHub Profile
@astannard
astannard / gist:5813627
Created June 19, 2013 11:38
Drop cap style
.dropCap:first-letter {
font-weight: 600;
font-size: 6em!important;
line-height: .8;
display: block;
float: left;
height: 0.6em;
margin: 5px 5px 5px -7px;
}
@astannard
astannard / gist:5984913
Created July 12, 2013 14:32
Ye Old Typography
body {
background-color: #f5f5dc;
border-top: solid 10px #333;
color: #4c362a;
font-size: 1.1em;
font-family: 'Alegreya', serif;
margin: 0;
padding: 0;
}
@astannard
astannard / gist:6914157
Created October 10, 2013 06:55
ios / android mobile html camera access
<input type="file" capture="camera" accept="image/*" id="cameraInput">
@astannard
astannard / gist:7022405
Last active December 25, 2015 18:39
T-SQL Cursor
DECLARE @Id int
DECLARE TableCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT Id
FROM dbo.TABLENAME
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @Id
WHILE @@FETCH_STATUS=0
@astannard
astannard / gist:7319388
Created November 5, 2013 13:59
Select XML node data from a column of type XML
SELECT TOP 1 [xmlColumnName].value('(//NodeName)[1]','varchar(max)') AS NameOfData
FROM [TableWithXMLColumn]
WHERE
Id = @id
@astannard
astannard / gist:7332814
Created November 6, 2013 08:37
Stop javascript treating a number as text
// This does not work and gives the wrong figure due to concatination
var shiftPrem = $('#Contract_Reward_ShiftPremium').val();
var basePay = $('#Contract_Reward_BasePay').val();
var total = basePay + (basePay * (shiftPrem/100));
//This works by forcing javascript to treat the variables as numbers
shiftPrem = $('#Contract_Reward_ShiftPremium').val();
basePay = $('#Contract_Reward_BasePay').val();
total = +basePay + +(basePay * (shiftPrem/100));
@astannard
astannard / gist:7526517
Created November 18, 2013 11:47
HTML5 email field
<input type="text" title="email" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" />
@astannard
astannard / gist:8706894
Created January 30, 2014 11:44
Gets the browser name and version
navigator.sayswho = (function () {
var ua = navigator.userAgent, tem,
M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*([\d\.]+)/i) || [];
if (/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+(\.\d+)?)/g.exec(ua) || [];
return 'IE ' + (tem[1] || '');
}
M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((tem = ua.match(/version\/([\.\d]+)/i)) != null) M[2] = tem[1];
return M.join(' ');
@astannard
astannard / razor
Created April 15, 2014 13:57
DropDownListFor
@Html.DropDownListFor(x=>x.ListName,
Model.ListName.Select(i => new SelectListItem
{
Value = i.Id.ToString(),
Text = i.Title
}),
new { @class = "input-full" })
@astannard
astannard / gist:9ccf5dd3611b0ad048c6
Last active August 29, 2015 14:01
SQL genarated ID's
@@IDENTITY - returns the last identity value generated for any table in the current session, across all scopes. You need to be careful here, since it's across scopes. You could get a value from a trigger, instead of your current statement.
SCOPE_IDENTITY - returns the last identity value generated for any table in the current session and the current scope. Generally what you want to use.
IDENT_CURRENT - returns the last identity value generated for a specific table in any session and any scope. This lets you specify which table you want the value from, in case the two above aren't quite what you need (very rare). Also, as @Guy Starbuck mentioned, "You could use this if you want to get the current IDENTITY value for a table that you have not inserted a record into."
The OUTPUT clause of the INSERT statement will let you access every row that was inserted via that statement. Since it's scoped to the specific statement, it's more straightforward than the other functions above. However, it's a litt